diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-06-08 01:11:23 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2007-06-08 01:11:23 +0200 |
commit | 969c111d3e5f436cc7611af9cb885923c2a96956 (patch) | |
tree | 0d27935d827af94e3bf785d1e6762aef189892e5 /gcc | |
parent | 1579e8d23577a56ac499e49a2559509a6bd21e49 (diff) | |
download | gcc-969c111d3e5f436cc7611af9cb885923c2a96956.zip gcc-969c111d3e5f436cc7611af9cb885923c2a96956.tar.gz gcc-969c111d3e5f436cc7611af9cb885923c2a96956.tar.bz2 |
re PR c++/32177 (g++ crashes on some valid OpenMP code)
PR c++/32177
* semantics.c (finish_omp_for): Call fold_build_cleanup_point_expr
on init, the non-decl cond operand and increment value.
* g++.dg/gomp/pr32177.C: New test.
From-SVN: r125544
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 27 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/gomp/pr32177.C | 46 |
4 files changed, 83 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bc6bdd1..509f8ad 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2007-06-08 Jakub Jelinek <jakub@redhat.com> + + PR c++/32177 + * semantics.c (finish_omp_for): Call fold_build_cleanup_point_expr + on init, the non-decl cond operand and increment value. + 2007-06-07 Simon Martin <simartin@users.sourceforge.net> PR c++/30759 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 4a9ea8c..dc4a9f7 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3806,6 +3806,8 @@ tree finish_omp_for (location_t locus, tree decl, tree init, tree cond, tree incr, tree body, tree pre_body) { + tree omp_for; + if (decl == NULL) { if (init != NULL) @@ -3883,8 +3885,31 @@ finish_omp_for (location_t locus, tree decl, tree init, tree cond, add_stmt (pre_body); pre_body = NULL; } + + init = fold_build_cleanup_point_expr (TREE_TYPE (init), init); init = build_modify_expr (decl, NOP_EXPR, init); - return c_finish_omp_for (locus, decl, init, cond, incr, body, pre_body); + if (cond && TREE_SIDE_EFFECTS (cond) && COMPARISON_CLASS_P (cond)) + { + int n = TREE_SIDE_EFFECTS (TREE_OPERAND (cond, 1)) != 0; + tree t = TREE_OPERAND (cond, n); + + TREE_OPERAND (cond, n) + = fold_build_cleanup_point_expr (TREE_TYPE (t), t); + } + omp_for = c_finish_omp_for (locus, decl, init, cond, incr, body, pre_body); + if (omp_for != NULL + && TREE_CODE (OMP_FOR_INCR (omp_for)) == MODIFY_EXPR + && TREE_SIDE_EFFECTS (TREE_OPERAND (OMP_FOR_INCR (omp_for), 1)) + && BINARY_CLASS_P (TREE_OPERAND (OMP_FOR_INCR (omp_for), 1))) + { + tree t = TREE_OPERAND (OMP_FOR_INCR (omp_for), 1); + int n = TREE_SIDE_EFFECTS (TREE_OPERAND (t, 1)) != 0; + + TREE_OPERAND (t, n) + = fold_build_cleanup_point_expr (TREE_TYPE (TREE_OPERAND (t, n)), + TREE_OPERAND (t, n)); + } + return omp_for; } void diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e315740..4c51713 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-06-08 Jakub Jelinek <jakub@redhat.com> + + PR c++/32177 + * g++.dg/gomp/pr32177.C: New test. + 2007-06-07 Manuel Lopez-Ibanez <manu@gcc.gnu.org> PR testsuite/25241 diff --git a/gcc/testsuite/g++.dg/gomp/pr32177.C b/gcc/testsuite/g++.dg/gomp/pr32177.C new file mode 100644 index 0000000..55c8483 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/pr32177.C @@ -0,0 +1,46 @@ +// PR c++/32177 +// { dg-do compile } +// { dg-options "-fopenmp" } +// +// Copyright (C) 2007 Free Software Foundation, Inc. +// Contributed by Theodore.Papadopoulo 1 Jun 2007 <Theodore.Papadopoulo@sophia.inria.fr> + +struct A +{ + A () {} + ~A () {} + int s () const { return 1; } +}; + +void +f1 () +{ + #pragma omp parallel for + for (int i = 1; i <= A ().s (); ++i) + ; +} + +void +f2 () +{ + #pragma omp parallel for + for (int i = A ().s (); i <= 20; ++i) + ; +} + +void +f3 () +{ + #pragma omp parallel for + for (int i = 1; i <= 20; i += A ().s ()) + ; +} + +void +f4 () +{ + int i; + #pragma omp parallel for + for (i = A ().s (); i <= 20; i++) + ; +} |