[PATCH] Fix gomp/30143, OpenMP can produce invalid gimple

Jakub Jelinek jakub@redhat.com
Thu Dec 21 12:17:00 GMT 2006


On Sat, Dec 16, 2006 at 11:40:08AM -0800, Andrew Pinski wrote:
>   OpenMP lowering can cause invalid gimple to be produced.  This was
> originally caught by my invalid gimple catcher but I was able to create
> a testcase that failed on the mainline with some complex typed variable.
> The problem here is that openmp lowering does not do the same lowering
> as the nesting pass does for one case.  This one case is transforming
> assignments from a gimple variable to a store to a component of a
> struct.
> 
> The way to fix this is to copy code from the unnesting pass and use it
> in the openmp lowering pass.
> 
> OK? Bootstrapped and tested on i686-linux-gnu with no regressions.
> 
> If someone wants a 4.2 version of this patch, I can post one as my
> testcase ICEs there also.

Like this (this was bootstrapped/regtested on redhat/gcc-4_1-branch
where the test ICEs too, but I think 4.2 is identical)?
Changes from the 4.3 patch are GIMPLE_MODIFY_STMT vs. MODIFY_STMT
and DECL_GIMPLE_REG_P vs. DECL_COMPLEX_GIMPLE_REG_P + guard condition.

2006-12-20  Andrew Pinski  <pinskia@gmail.com>

	PR middle-end/30143
	* omp-low.c (init_tmp_var): New function.
	(save_tmp_var): New function.
	(lower_omp_1): Use them for VAR_DECL.

	* gcc.dg/gomp/complex-1.c: New testcase.

--- gcc/omp-low.c	(revision 119958)
+++ gcc/omp-low.c	(working copy)
@@ -4188,6 +4188,40 @@ lower_regimplify (tree *tp, struct walk_
     tsi_link_before (&wi->tsi, pre, TSI_SAME_STMT);
 }
 
+/* Copy EXP into a temporary.  Insert the initialization statement before TSI.  */
+
+static tree
+init_tmp_var (tree exp, tree_stmt_iterator *tsi)
+{
+  tree t, stmt;
+
+  t = create_tmp_var (TREE_TYPE (exp), NULL);
+  if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE)
+    DECL_COMPLEX_GIMPLE_REG_P (t) = 1;
+  stmt = build2 (MODIFY_EXPR, TREE_TYPE (t), t, exp);
+  SET_EXPR_LOCUS (stmt, EXPR_LOCUS (tsi_stmt (*tsi)));
+  tsi_link_before (tsi, stmt, TSI_SAME_STMT);
+
+  return t;
+}
+
+/* Similarly, but copy from the temporary and insert the statement
+   after the iterator.  */
+
+static tree
+save_tmp_var (tree exp, tree_stmt_iterator *tsi)
+{
+  tree t, stmt;
+
+  t = create_tmp_var (TREE_TYPE (exp), NULL);
+  if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE)
+    DECL_COMPLEX_GIMPLE_REG_P (t) = 1;
+  stmt = build2 (MODIFY_EXPR, TREE_TYPE (t), exp, t);
+  SET_EXPR_LOCUS (stmt, EXPR_LOCUS (tsi_stmt (*tsi)));
+  tsi_link_after (tsi, stmt, TSI_SAME_STMT);
+
+  return t;
+}
 
 /* Callback for walk_stmts.  Lower the OpenMP directive pointed by TP.  */
 
@@ -4253,7 +4287,17 @@ lower_omp_1 (tree *tp, int *walk_subtree
 
     case VAR_DECL:
       if (ctx && DECL_HAS_VALUE_EXPR_P (t))
-	lower_regimplify (tp, wi);
+	{
+	  lower_regimplify (&t, wi);
+	  if (wi->val_only)
+	    {
+	      if (wi->is_lhs)
+		t = save_tmp_var (t, &wi->tsi);
+	      else
+		t = init_tmp_var (t, &wi->tsi);
+	    }
+	  *tp = t;
+	}
       break;
 
     case ADDR_EXPR:
--- gcc/testsuite/gcc.dg/gomp/complex-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/gomp/complex-1.c	(revision 0)
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -O1" } */
+/* PR middle-end/30143 */
+
+
+int f (int n)
+{
+  int i;
+  _Complex float t;
+#pragma omp parallel
+    for (i = 1; i < n - 1; ++i)
+      t+=1;
+}


	Jakub



More information about the Gcc-patches mailing list