]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/84506 (INQUIRE(pos=) always sets pos=0 with -fdefault-integer-8)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 23 Feb 2018 19:53:04 +0000 (19:53 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 23 Feb 2018 19:53:04 +0000 (19:53 +0000)
2018-02-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

Backport from trunk
PR fortran/84506
* trans-io.c (set_parameter_value_inquire): Adjust range check of
negative unit values for kind=8 units to the kind=4 negative limit.

* gfortran.dg/inquire_19.f90: New test.

From-SVN: r257951

gcc/fortran/ChangeLog
gcc/fortran/trans-io.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/inquire_19.f90 [new file with mode: 0644]

index 8689c7d23a8c355cedb1cdc599820adf20e82c30..e5265bf55cad41db9abd7c99f029cfad2c6f30af 100644 (file)
@@ -1,3 +1,10 @@
+2018-02-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/84506
+       * trans-io.c (set_parameter_value_inquire): Adjust range check of
+       negative unit values for kind=8 units to the kind=4 negative limit.
+
 2018-02-23  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/84511
index ed3a9b19517c1c0d368b4a2439d045f991320b1d..a6764a175d7f103ac6b97a3b17ffd7a6ca6d419e 100644 (file)
@@ -611,12 +611,12 @@ set_parameter_value_inquire (stmtblock_t *block, tree var,
       /* Don't evaluate the UNIT number multiple times.  */
       se.expr = gfc_evaluate_now (se.expr, &se.pre);
 
-      /* UNIT numbers should be greater than zero.  */
+      /* UNIT numbers should be greater than the min.  */
       i = gfc_validate_kind (BT_INTEGER, 4, false);
+      val = gfc_conv_mpz_to_tree (gfc_integer_kinds[i].pedantic_min_int, 4);
       cond1 = build2_loc (input_location, LT_EXPR, boolean_type_node,
                          se.expr,
-                         fold_convert (TREE_TYPE (se.expr),
-                         integer_zero_node));
+                         fold_convert (TREE_TYPE (se.expr), val));
       /* UNIT numbers should be less than the max.  */
       val = gfc_conv_mpz_to_tree (gfc_integer_kinds[i].huge, 4);
       cond2 = build2_loc (input_location, GT_EXPR, boolean_type_node,
index 282189c69218a74b4f23ff3fa86681e919543f3b..8337c4c3b9d3528fe70bcd07396300f60e206754 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/84506
+       * gfortran.dg/inquire_19.f90: New test.
+
 2018-02-23  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/84346
diff --git a/gcc/testsuite/gfortran.dg/inquire_19.f90 b/gcc/testsuite/gfortran.dg/inquire_19.f90
new file mode 100644 (file)
index 0000000..7d01b6b
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do run }
+! PR84506  INQUIRE(pos=) always sets pos=0 with -fdefault-integer-8
+program TestInquire
+   implicit none
+   integer(8) :: iUnit
+   integer(8) :: iPos
+   open(newunit=iunit, file='output.txt', access='stream', status='replace')
+   write(iUnit) 'TEXT'
+   inquire(iUnit, pos=iPos)
+   close(iUnit, status='delete')
+   !print *, iPos
+   if (iPos.ne.5) stop 1
+end program TestInquire