This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gomp] Handle MODOP_EXPR in finish_omp_for (PR c++/24502)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>, Diego Novillo <dnovillo at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 24 Oct 2005 12:03:46 -0400
- Subject: [gomp] Handle MODOP_EXPR in finish_omp_for (PR c++/24502)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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