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]

[gomp] Handle MODOP_EXPR in finish_omp_for (PR c++/24502)


Hi!

If for iteration var is not declared in the loop and
processing_template_decl, C++ FE creates MODOP_EXPR with NOP_EXPR as
second argument instead of MODIFY_EXPR.
Tested with make -C gcc check RUNTESTFLAGS=gomp.exp && make check-target-libgomp

Ok for gomp?

2005-10-24  Jakub Jelinek  <jakub@redhat.com>

	PR c++/24502
	* semantics.c (finish_omp_for): Handle MODOP_EXPR in addition to
	MODIFY_EXPR.

	* testsuite/libgomp.c++/loop-7.C: New test.

--- gcc/cp/semantics.c.jj	2005-10-24 17:19:45.000000000 +0200
+++ gcc/cp/semantics.c	2005-10-24 17:32:14.000000000 +0200
@@ -3670,13 +3670,29 @@ finish_omp_for (location_t locus, tree d
 {
   if (decl == NULL)
     {
-      if (init == NULL || TREE_CODE (init) != MODIFY_EXPR)
+      if (init != NULL)
+	switch (TREE_CODE (init))
+	  {
+	  case MODIFY_EXPR:
+	    decl = TREE_OPERAND (init, 0);
+	    init = TREE_OPERAND (init, 1);
+	    break;
+	  case MODOP_EXPR:
+	    if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
+	      {
+		decl = TREE_OPERAND (init, 0);
+		init = TREE_OPERAND (init, 2);
+	      }
+	    break;
+	  default:
+	    break;
+	  }
+
+      if (decl == NULL)
 	{
 	  error ("expected iteration declaration or initialization");
 	  return NULL;
 	}
-      decl = TREE_OPERAND (init, 0);
-      init = TREE_OPERAND (init, 1);
     }
 
   if (type_dependent_expression_p (decl)
--- libgomp/testsuite/libgomp.c++/loop-7.C.jj	2005-10-24 17:52:48.000000000 +0200
+++ libgomp/testsuite/libgomp.c++/loop-7.C	2005-10-24 17:53:22.000000000 +0200
@@ -0,0 +1,22 @@
+// PR c++/24502
+// { dg-do run }
+
+extern "C" void abort ();
+
+template <typename T> T
+foo (T r)
+{
+  T i;
+#pragma omp for
+  for (i = 0; i < 10; i++)
+    r += i;
+  return r;
+}
+
+int
+main ()
+{
+  if (foo (0) != 10 * 9 / 2 || foo (2L) != 10L * 9 / 2 + 2)
+    abort ();
+  return 0;
+}

	Jakub


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