re PR c++/38650 (Trouble with volatile and #pragma omp for)

PR c++/38650
	* semantics.c (finish_omp_for): Don't add CLEANUP_POINT_EXPR
	around volatile iteration var in condition and/or increment
	expression.

	* testsuite/libgomp.c/pr38650.c: New test.
	* testsuite/libgomp.c++/pr38650.C: New test.

From-SVN: r142940
This commit is contained in:
Jakub Jelinek 2008-12-28 21:06:00 +01:00 committed by Jakub Jelinek
parent 2008239a95
commit e4ebaef35b
5 changed files with 146 additions and 13 deletions

View File

@ -1,3 +1,10 @@
2008-12-28 Jakub Jelinek <jakub@redhat.com>
PR c++/38650
* semantics.c (finish_omp_for): Don't add CLEANUP_POINT_EXPR
around volatile iteration var in condition and/or increment
expression.
2008-12-27 Jakub Jelinek <jakub@redhat.com>
PR c++/38639

View File

@ -4262,13 +4262,25 @@ finish_omp_for (location_t locus, tree declv, tree initv, tree condv,
}
else
init = build2 (MODIFY_EXPR, void_type_node, decl, init);
if (cond && TREE_SIDE_EFFECTS (cond) && COMPARISON_CLASS_P (cond))
if (cond
&& TREE_SIDE_EFFECTS (cond)
&& COMPARISON_CLASS_P (cond)
&& !processing_template_decl)
{
int n = TREE_SIDE_EFFECTS (TREE_OPERAND (cond, 1)) != 0;
tree t = TREE_OPERAND (cond, n);
tree t = TREE_OPERAND (cond, 0);
if (TREE_SIDE_EFFECTS (t)
&& t != decl
&& (TREE_CODE (t) != NOP_EXPR
|| TREE_OPERAND (t, 0) != decl))
TREE_OPERAND (cond, 0)
= fold_build_cleanup_point_expr (TREE_TYPE (t), t);
if (!processing_template_decl)
TREE_OPERAND (cond, n)
t = TREE_OPERAND (cond, 1);
if (TREE_SIDE_EFFECTS (t)
&& t != decl
&& (TREE_CODE (t) != NOP_EXPR
|| TREE_OPERAND (t, 0) != decl))
TREE_OPERAND (cond, 1)
= fold_build_cleanup_point_expr (TREE_TYPE (t), t);
}
if (decl == error_mark_node || init == error_mark_node)
@ -4292,21 +4304,31 @@ finish_omp_for (location_t locus, tree declv, tree initv, tree condv,
for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
{
tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i), 0);
incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
if (TREE_CODE (incr) != MODIFY_EXPR)
continue;
if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
&& BINARY_CLASS_P (TREE_OPERAND (incr, 1)))
&& BINARY_CLASS_P (TREE_OPERAND (incr, 1))
&& !processing_template_decl)
{
tree t = TREE_OPERAND (incr, 1);
int n = TREE_SIDE_EFFECTS (TREE_OPERAND (t, 1)) != 0;
tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
if (TREE_SIDE_EFFECTS (t)
&& t != decl
&& (TREE_CODE (t) != NOP_EXPR
|| TREE_OPERAND (t, 0) != decl))
TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
= fold_build_cleanup_point_expr (TREE_TYPE (t), t);
if (!processing_template_decl)
TREE_OPERAND (t, n)
= fold_build_cleanup_point_expr (TREE_TYPE (TREE_OPERAND (t, n)),
TREE_OPERAND (t, n));
t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
if (TREE_SIDE_EFFECTS (t)
&& t != decl
&& (TREE_CODE (t) != NOP_EXPR
|| TREE_OPERAND (t, 0) != decl))
TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
= fold_build_cleanup_point_expr (TREE_TYPE (t), t);
}
if (orig_incr)

View File

@ -1,3 +1,9 @@
2008-12-28 Jakub Jelinek <jakub@redhat.com>
PR c++/38650
* testsuite/libgomp.c/pr38650.c: New test.
* testsuite/libgomp.c++/pr38650.C: New test.
2008-12-27 Jakub Jelinek <jakub@redhat.com>
* testsuite/libgomp.c/collapse-1.c (main): Add private(k) clause.

View File

@ -0,0 +1,49 @@
// PR c++/38650
// { dg-do run }
#include <cstdlib>
int e;
int
main ()
{
volatile int i, j = 10;
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < j; i += 1)
e++;
if (e != 10)
std::abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < j; ++i)
e++;
if (e != 10)
std::abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < j; i++)
e++;
if (e != 10)
std::abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < 10; i += 1)
e++;
if (e != 10)
std::abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < 10; ++i)
e++;
if (e != 10)
std::abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < 10; i++)
e++;
if (e != 10)
std::abort ();
return 0;
}

View File

@ -0,0 +1,49 @@
/* PR c++/38650 */
/* { dg-do run } */
#include <stdlib.h>
int e;
int
main ()
{
volatile int i, j = 10;
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < j; i += 1)
e++;
if (e != 10)
abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < j; ++i)
e++;
if (e != 10)
abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < j; i++)
e++;
if (e != 10)
abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < 10; i += 1)
e++;
if (e != 10)
abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < 10; ++i)
e++;
if (e != 10)
abort ();
e = 0;
#pragma omp parallel for reduction(+:e)
for (i = 0; i < 10; i++)
e++;
if (e != 10)
abort ();
return 0;
}