From a3bccfa17c34a937d0222ec084fe9ca97d88a01f Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 17 Jul 2018 12:54:52 +0200 Subject: [PATCH] re PR middle-end/86542 (wrong-code for collapsed taskloop which needs omp_cpyfn) PR middle-end/86542 * omp-low.c (create_task_copyfn): Copy over also fields corresponding to _looptemp_ clauses, other than the first two. * testsuite/libgomp.c++/pr86542.C: New test. From-SVN: r262815 --- gcc/ChangeLog | 6 ++++ gcc/omp-low.c | 15 +++++++++- libgomp/ChangeLog | 3 ++ libgomp/testsuite/libgomp.c++/pr86542.C | 37 +++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 libgomp/testsuite/libgomp.c++/pr86542.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1c52477d70d..8ec7da04154 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-07-17 Jakub Jelinek + + PR middle-end/86542 + * omp-low.c (create_task_copyfn): Copy over also fields corresponding + to _looptemp_ clauses, other than the first two. + 2018-07-17 Martin Liska * opts.c: Do not enable OPT_falign_* for -Os. diff --git a/gcc/omp-low.c b/gcc/omp-low.c index c591231d8f1..714490d6921 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -7026,6 +7026,7 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx) splay_tree_node n; struct omp_taskcopy_context tcctx; location_t loc = gimple_location (task_stmt); + size_t looptempno = 0; child_fn = gimple_omp_task_copy_fn (task_stmt); child_cfun = DECL_STRUCT_FUNCTION (child_fn); @@ -7139,6 +7140,15 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx) t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src); append_to_statement_list (t, &list); break; + case OMP_CLAUSE__LOOPTEMP_: + /* Fields for first two _looptemp_ clauses are initialized by + GOMP_taskloop*, the rest are handled like firstprivate. */ + if (looptempno < 2) + { + looptempno++; + break; + } + /* FALLTHRU */ case OMP_CLAUSE_FIRSTPRIVATE: decl = OMP_CLAUSE_DECL (c); if (is_variable_sized (decl)) @@ -7164,7 +7174,10 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx) src = decl; dst = build_simple_mem_ref_loc (loc, arg); dst = omp_build_component_ref (dst, f); - t = lang_hooks.decls.omp_clause_copy_ctor (c, dst, src); + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE__LOOPTEMP_) + t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src); + else + t = lang_hooks.decls.omp_clause_copy_ctor (c, dst, src); append_to_statement_list (t, &list); break; case OMP_CLAUSE_PRIVATE: diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index bfcf9d7dcd3..baa675d61be 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,5 +1,8 @@ 2018-07-17 Jakub Jelinek + PR middle-end/86542 + * testsuite/libgomp.c++/pr86542.C: New test. + PR middle-end/86539 * testsuite/libgomp.c++/pr86539.C: New test. diff --git a/libgomp/testsuite/libgomp.c++/pr86542.C b/libgomp/testsuite/libgomp.c++/pr86542.C new file mode 100644 index 00000000000..5d42ea678a2 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/pr86542.C @@ -0,0 +1,37 @@ +// PR middle-end/86542 + +struct S { int s; S (); ~S (); S (const S &); }; +S s; + +S::S () +{ +} + +S::~S () +{ +} + +S::S (const S &x) +{ + s = x.s; +} + +__attribute__((noipa)) void +foo (int i, int j, int k, S s) +{ + if (i != 0 || j != 0 || k != 0 || s.s != 12) + __builtin_abort (); +} + +int +main () +{ + volatile int inc = 16, jnc = 16, knc = 16; + s.s = 12; + #pragma omp taskloop collapse (3) firstprivate (s) + for (int i = 0; i < 16; i += inc) + for (int j = 0; j < 16; j += jnc) + for (int k = 0; k < 16; k += knc) + foo (i, j, k, s); + return 0; +} -- 2.30.2