re PR fortran/84506 (INQUIRE(pos=) always sets pos=0 with -fdefault-integer-8)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 23 Feb 2018 18:40:14 +0000 (18:40 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 23 Feb 2018 18:40:14 +0000 (18:40 +0000)
2018-02-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

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: r257941

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

index 528d294b4e167cdb5df3e245bc4be1ec1b6d0b70..673a1b85fbeda1a0a2417667583cc50dea7afeb1 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       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  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/83149
index 021c788ba54099edc89b21b9d1a741c59e2c0232..36adb0344756b3acac1af0c6e5210674db56a045 100644 (file)
@@ -639,12 +639,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, logical_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, logical_type_node,
index d68abc56b0630a1a9cf9bff8539c1d2bfe3348a6..0c703ccd4f263bb3172e525970ea914a17e6301c 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR fortran/84506
+       * gfortran.dg/inquire_19.f90: New test.
+
 2018-02-23  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/83149
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