diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-11-29 09:08:46 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2019-11-29 09:08:46 +0000 |
commit | 5b4a81b63d290433da6b7d9d4edbac66bc0714ee (patch) | |
tree | dee1724a138a934e00ff1750d1c62706cdd1971a /libgomp | |
parent | 37c30e81c69ebda7757f8a681d695c4a2c3a8774 (diff) |
PR c++/60228
* parser.c (cp_parser_omp_declare_reduction_exprs): If
processing_template_decl, wrap the combiner or initializer
into EXPR_STMT.
* decl.c (start_preparsed_function): Don't start a lambda scope
for DECL_OMP_DECLARE_REDUCTION_P functions.
(finish_function): Don't finish a lambda scope for
DECL_OMP_DECLARE_REDUCTION_P functions, nor cp_fold_function
them nor cp_genericize them.
* mangle.c (decl_mangling_context): Look through
DECL_OMP_DECLARE_REDUCTION_P functions.
* semantics.c (expand_or_defer_fn_1): For DECL_OMP_DECLARE_REDUCTION_P
functions, use tentative linkage, don't keep their bodies with
-fkeep-inline-functions and return false at the end.
* g++.dg/gomp/openmp-simd-2.C: Don't expect bodies for
DECL_OMP_DECLARE_REDUCTION_P functions.
* testsuite/libgomp.c++/udr-20.C: New test.
* testsuite/libgomp.c++/udr-21.C: New test.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@278831 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgomp')
-rw-r--r-- | libgomp/ChangeLog | 6 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c++/udr-20.C | 108 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c++/udr-21.C | 108 |
3 files changed, 222 insertions, 0 deletions
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index d8d76ba3ce8..abbd47eb517 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,9 @@ +2019-11-29 Jakub Jelinek <jakub@redhat.com> + + PR c++/60228 + * testsuite/libgomp.c++/udr-20.C: New test. + * testsuite/libgomp.c++/udr-21.C: New test. + 2019-11-27 Thomas Schwinge <thomas@codesourcery.com> * testsuite/lib/libgomp.exp diff --git a/libgomp/testsuite/libgomp.c++/udr-20.C b/libgomp/testsuite/libgomp.c++/udr-20.C new file mode 100644 index 00000000000..48d4feab7e5 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/udr-20.C @@ -0,0 +1,108 @@ +// PR c++/60228 +// { dg-additional-options "-std=c++11" } + +extern "C" void abort (); + +struct A +{ + typedef int T; + #pragma omp declare reduction (x : T : omp_out += omp_in + [](){ return 0; }()) initializer (omp_priv = [](){ return 0; }()) + static void foo (); +}; + +template <typename T> +struct B +{ + #pragma omp declare reduction (x : T : omp_out += omp_in + [](){ return T (0); }()) initializer (omp_priv = [](){ return T (0); }()) + static void foo (); +}; + +void +A::foo () +{ + int r = 0, s = 0; + #pragma omp parallel for reduction (x : r, s) + for (int i = 0; i < 64; i++) + { + r++; + s += i; + } + if (r != 64 || s != (64 * 63) / 2) + abort (); +} + +template <typename T> +void +B<T>::foo () +{ + T r = 0, s = 0; + #pragma omp parallel for reduction (x : r, s) + for (int i = 0; i < 64; i++) + { + r++; + s += i; + } + if (r != 64 || s != (64 * 63) / 2) + abort (); +} + +int +main () +{ + A::foo (); + B<long>::foo (); +} +// PR c++/60228 +// { dg-additional-options "-std=c++11" } + +extern "C" void abort (); + +struct A +{ + typedef int T; + #pragma omp declare reduction (x : T : omp_out += omp_in + [](){ return 0; }()) initializer (omp_priv = [](){ return 0; }()) + static void foo (); +}; + +template <typename T> +struct B +{ + #pragma omp declare reduction (x : T : omp_out += omp_in + [](){ return T (0); }()) initializer (omp_priv = [](){ return T (0); }()) + static void foo (); +}; + +void +A::foo () +{ + int r = 0, s = 0; + #pragma omp parallel for reduction (x : r, s) + for (int i = 0; i < 64; i++) + { + r++; + s += i; + } + if (r != 64 || s != (64 * 63) / 2) + abort (); +} + +template <typename T> +void +B<T>::foo () +{ + T r = 0, s = 0; + #pragma omp parallel for reduction (x : r, s) + for (int i = 0; i < 64; i++) + { + r++; + s += i; + } + if (r != 64 || s != (64 * 63) / 2) + abort (); +} + +int +main () +{ + A::foo (); + B<long>::foo (); +} diff --git a/libgomp/testsuite/libgomp.c++/udr-21.C b/libgomp/testsuite/libgomp.c++/udr-21.C new file mode 100644 index 00000000000..1ecaf473d1d --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/udr-21.C @@ -0,0 +1,108 @@ +// PR c++/60228 +// { dg-additional-options "-std=c++11" } + +extern "C" void abort (); + +struct A +{ + typedef int T; + #pragma omp declare reduction (y : T : [&omp_out, &omp_in]() { omp_out += omp_in; return 0; }()) initializer (omp_priv = [omp_orig]() { return omp_orig; }()) + static void foo (); +}; + +template <typename T> +struct B +{ + #pragma omp declare reduction (y : T : [&omp_out, &omp_in]() { omp_out += omp_in; return 0; }()) initializer (omp_priv = [omp_orig]() { return omp_orig; }()) + static void foo (); +}; + +void +A::foo () +{ + int r = 0, s = 0; + #pragma omp parallel for reduction (y : r, s) + for (int i = 0; i < 64; i++) + { + r++; + s += i; + } + if (r != 64 || s != (64 * 63) / 2) + abort (); +} + +template <typename T> +void +B<T>::foo () +{ + T r = 0, s = 0; + #pragma omp parallel for reduction (y : r, s) + for (int i = 0; i < 64; i++) + { + r++; + s += i; + } + if (r != 64 || s != (64 * 63) / 2) + abort (); +} + +int +main () +{ + A::foo (); + B<short>::foo (); +} +// PR c++/60228 +// { dg-additional-options "-std=c++11" } + +extern "C" void abort (); + +struct A +{ + typedef int T; + #pragma omp declare reduction (y : T : [&omp_out, &omp_in]() { omp_out += omp_in; return 0; }()) initializer (omp_priv = [omp_orig]() { return omp_orig; }()) + static void foo (); +}; + +template <typename T> +struct B +{ + #pragma omp declare reduction (y : T : [&omp_out, &omp_in]() { omp_out += omp_in; return 0; }()) initializer (omp_priv = [omp_orig]() { return omp_orig; }()) + static void foo (); +}; + +void +A::foo () +{ + int r = 0, s = 0; + #pragma omp parallel for reduction (y : r, s) + for (int i = 0; i < 64; i++) + { + r++; + s += i; + } + if (r != 64 || s != (64 * 63) / 2) + abort (); +} + +template <typename T> +void +B<T>::foo () +{ + T r = 0, s = 0; + #pragma omp parallel for reduction (y : r, s) + for (int i = 0; i < 64; i++) + { + r++; + s += i; + } + if (r != 64 || s != (64 * 63) / 2) + abort (); +} + +int +main () +{ + A::foo (); + B<short>::foo (); +} |