Patchwork [committed] Fix !$omp do translation (PR fortran/46753)

login
register
mail settings
Submitter Jakub Jelinek
Date Dec. 2, 2010, 2:46 p.m.
Message ID <20101202144611.GN29412@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/73979/
State New
Headers show

Comments

Jakub Jelinek - Dec. 2, 2010, 2:46 p.m.
Hi!

During 4.4 development the creation of conditions were incorrectly changed
from build2 to fold_build2.  This is wrong, because comparisons with
the highest or lowest type's value can be folded into != test, which is not
valid OpenMP condition (the middle-end code wants to know if the condition
is </<= or >/>=).

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed (so far) on the trunk.

2010-12-02  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/46753
	* trans-openmp.c (gfc_trans_omp_do): Use build2_loc instead of
	fold_build2_loc for OMP_FOR conditions.

	* libgomp.fortran/pr46753.f90: New test.


	Jakub

Patch

--- gcc/fortran/trans-openmp.c.jj	2010-09-14 15:24:43.000000000 +0200
+++ gcc/fortran/trans-openmp.c	2010-12-02 11:17:55.000000000 +0100
@@ -1262,10 +1262,10 @@  gfc_trans_omp_do (gfc_code *code, stmtbl
       if (simple)
 	{
 	  TREE_VEC_ELT (init, i) = build2_v (MODIFY_EXPR, dovar, from);
-	  TREE_VEC_ELT (cond, i) = fold_build2_loc (input_location, simple > 0
-						    ? LE_EXPR : GE_EXPR,
-						    boolean_type_node, dovar,
-						    to);
+	  /* The condition should not be folded.  */
+	  TREE_VEC_ELT (cond, i) = build2_loc (input_location, simple > 0
+					       ? LE_EXPR : GE_EXPR,
+					       boolean_type_node, dovar, to);
 	  TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location, PLUS_EXPR,
 						    type, dovar, step);
 	  TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location,
@@ -1290,9 +1290,10 @@  gfc_trans_omp_do (gfc_code *code, stmtbl
 	  count = gfc_create_var (type, "count");
 	  TREE_VEC_ELT (init, i) = build2_v (MODIFY_EXPR, count,
 					     build_int_cst (type, 0));
-	  TREE_VEC_ELT (cond, i) = fold_build2_loc (input_location, LT_EXPR,
-						    boolean_type_node,
-						    count, tmp);
+	  /* The condition should not be folded.  */
+	  TREE_VEC_ELT (cond, i) = build2_loc (input_location, LT_EXPR,
+					       boolean_type_node,
+					       count, tmp);
 	  TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location, PLUS_EXPR,
 						    type, count,
 						    build_int_cst (type, 1));
--- libgomp/testsuite/libgomp.fortran/pr46753.f90.jj	2010-11-19 19:58:10.083000000 +0100
+++ libgomp/testsuite/libgomp.fortran/pr46753.f90	2010-12-02 11:37:48.000000000 +0100
@@ -0,0 +1,17 @@ 
+! PR fortran/46753
+! { dg-do run }
+
+  integer :: i, j
+  j = 0
+!$omp parallel do reduction(+:j)
+  do i = 2147483636, 2147483646
+    j = j + 1
+  end do
+  if (j.ne.11) call abort
+  j = 0
+!$omp parallel do reduction(+:j)
+  do i = -2147483637, -2147483647, -1
+    j = j + 1
+  end do
+  if (j.ne.11) call abort
+end