The following valid code snippet (compiled with "-std=c++11 -fopenmp") triggers an ICE on trunk: ======================================================= template<typename T> struct A { #pragma omp declare reduction (x : T : omp_out += omp_in + [](){ return 0; }()) initializer (omp_priv = 0) }; ======================================================= bug.cc:3:108: internal compiler error: in cp_check_omp_declare_reduction, at cp/semantics.c:4944 #pragma omp declare reduction (x : T : omp_out += omp_in + [](){ return 0; }()) initializer (omp_priv = 0) ^ 0x7328eb cp_check_omp_declare_reduction(tree_node*) ../../gcc/gcc/cp/semantics.c:4944 0x6cfd7c cp_parser_late_parsing_for_member ../../gcc/gcc/cp/parser.c:23459 0x6a9edc cp_parser_class_specifier_1 ../../gcc/gcc/cp/parser.c:19406 0x6a9edc cp_parser_class_specifier ../../gcc/gcc/cp/parser.c:19437 0x6a9edc cp_parser_type_specifier ../../gcc/gcc/cp/parser.c:14302 0x6c2ba0 cp_parser_decl_specifier_seq ../../gcc/gcc/cp/parser.c:11547 0x6c8883 cp_parser_single_declaration ../../gcc/gcc/cp/parser.c:23039 0x6c8d64 cp_parser_template_declaration_after_export ../../gcc/gcc/cp/parser.c:22915 0x6d4119 cp_parser_declaration ../../gcc/gcc/cp/parser.c:10947 0x6d2c08 cp_parser_declaration_seq_opt ../../gcc/gcc/cp/parser.c:10869 0x6d44aa cp_parser_translation_unit ../../gcc/gcc/cp/parser.c:4014 0x6d44aa c_parse_file() ../../gcc/gcc/cp/parser.c:31536 0x7f3813 c_common_parse_file() ../../gcc/gcc/c-family/c-opts.c:1060 Please submit a full bug report, [etc.]
I would not call this valid, because OpenMP 4.0 doesn't support C++11, thus using C++11 constructs inside of OpenMP constructs is invalid.
Would it make sense to reject the testcase a little more gracefully? Or even accept is as an extension?
Something I didn't really pay attention to before: the ICE only happens in a template, otherwise the lambda is already accepted as an extension. There must be a way to fix the problem without explicitly handling C++11 constructs...
I would also like to see this supported, as the intel compiler is already able to support this.
(In reply to Steffen Seckler from comment #4) > I would also like to see this supported, as the intel compiler is already > able to support this. fyi: the clang compiler will support lambdas inside of #pragma omp declare reduction as of a913e872d6e7044ae77e55c45ab3ea5304eb7262, which will most likely be in the next release or in 9.0.1 see: https://bugs.llvm.org/show_bug.cgi?id=44133 https://bugs.llvm.org/show_bug.cgi?id=44134
Created attachment 47389 [details] gcc10-pr60228.patch Untested fix.
Author: jakub Date: Fri Nov 29 09:08:46 2019 New Revision: 278831 URL: https://gcc.gnu.org/viewcvs?rev=278831&root=gcc&view=rev Log: 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. Added: trunk/libgomp/testsuite/libgomp.c++/udr-20.C trunk/libgomp/testsuite/libgomp.c++/udr-21.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/cp/mangle.c trunk/gcc/cp/parser.c trunk/gcc/cp/semantics.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/gomp/openmp-simd-2.C trunk/libgomp/ChangeLog
Author: jakub Date: Fri Nov 29 09:10:44 2019 New Revision: 278832 URL: https://gcc.gnu.org/viewcvs?rev=278832&root=gcc&view=rev Log: 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. Modified: trunk/libgomp/testsuite/libgomp.c++/udr-20.C trunk/libgomp/testsuite/libgomp.c++/udr-21.C
Author: jakub Date: Fri Dec 20 17:30:38 2019 New Revision: 279662 URL: https://gcc.gnu.org/viewcvs?rev=279662&root=gcc&view=rev Log: Backported from mainline 2019-11-29 Jakub Jelinek <jakub@redhat.com> 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. Added: branches/gcc-9-branch/libgomp/testsuite/libgomp.c++/udr-20.C branches/gcc-9-branch/libgomp/testsuite/libgomp.c++/udr-21.C Modified: branches/gcc-9-branch/gcc/cp/ChangeLog branches/gcc-9-branch/gcc/cp/decl.c branches/gcc-9-branch/gcc/cp/mangle.c branches/gcc-9-branch/gcc/cp/parser.c branches/gcc-9-branch/gcc/cp/semantics.c branches/gcc-9-branch/gcc/testsuite/ChangeLog branches/gcc-9-branch/gcc/testsuite/g++.dg/gomp/openmp-simd-2.C branches/gcc-9-branch/libgomp/ChangeLog
The releases/gcc-8 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:1aafdd7c93226cb092b560462028394a82f404a2 commit r8-9990-g1aafdd7c93226cb092b560462028394a82f404a2 Author: Jakub Jelinek <jakub@redhat.com> Date: Fri Feb 14 12:56:42 2020 +0100 backport: re PR c++/60228 (ICE using lambda in #pragma omp declare reduction) Backported from mainline 2019-11-29 Jakub Jelinek <jakub@redhat.com> 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.
Fixed for 8.4+ and 9.3+.