diff mbox series

[fortran] Bug 84506 - [6/7/8 Regression]INQUIRE(pos=) always sets pos=0 with -fdefault-integer-8

Message ID 166bfa30-941f-43a4-2e72-1046f4929ba8@charter.net
State New
Headers show
Series [fortran] Bug 84506 - [6/7/8 Regression]INQUIRE(pos=) always sets pos=0 with -fdefault-integer-8 | expand

Commit Message

Jerry DeLisle Feb. 23, 2018, 4:27 p.m. UTC
Hi Folks,

This bug is a result of a range check we do on kind=8 unit numbers to 
make sure they fall within the range values of a kind=4 integer. We were 
limiting this range to positive values. I think when we introduced the 
newunit feature which uses negative unit values, we missed this adjustment.

The attached patch is trivial. Regression tested on x86_86-pc-linux-gnu.

I will back port to 6 an 7 after approval here. I will use the case in 
the PR as a new test case.

OK for trunk?

Regards,

Jerry

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.

Comments

Steve Kargl Feb. 23, 2018, 5:33 p.m. UTC | #1
On Fri, Feb 23, 2018 at 08:27:18AM -0800, Jerry DeLisle wrote:
> 
> I will back port to 6 an 7 after approval here. I will use the case in 
> the PR as a new test case.
> 
> OK for trunk?
> 
> Regards,
> 
> Jerry
> 
> 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.

OK (with a testcase :-)
diff mbox series

Patch

diff --git a/gcc/fortran/trans-io.c b/gcc/fortran/trans-io.c
index 021c788ba54..36adb034475 100644
--- a/gcc/fortran/trans-io.c
+++ b/gcc/fortran/trans-io.c
@@ -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,