This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Sat, 2006-12-16 at 11:40 -0800, Andrew Pinski wrote:
> 
> ChangeLog:
> 
> 	* 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.

I Knew I pressed send too early.

Anyways here is the patch.

Thanks,
Andrew Pinski
Index: omp-low.c
===================================================================
--- omp-low.c	(revision 119958)
+++ omp-low.c	(working copy)
@@ -4188,6 +4188,38 @@ 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);
+  DECL_GIMPLE_REG_P (t) = 1;
+  stmt = build2 (GIMPLE_MODIFY_STMT, 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);
+  DECL_GIMPLE_REG_P (t) = 1;
+  stmt = build2 (GIMPLE_MODIFY_STMT, 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 +4285,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:
Index: testsuite/gcc.dg/gomp/complex-1.c
===================================================================
--- testsuite/gcc.dg/gomp/complex-1.c	(revision 0)
+++ 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;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]