This is a revised version of the patch set I previously posted in February:
https://gcc.gnu.org/pipermail/gcc-patches/2025-February/675464.html The first two parts of the original patch set were approved and already applied for GCC 15 so I've renumbered the remaining pieces now. Tobias reviewed the remaining parts except for the C++ front end changes in May, and approved the old part 4, which I've included here again as the new part 2 for completeness. Part 6, the documentation update, is new (and falls within my purview as docs maintainer). As with the original patch set, the current one implements "begin declare variant" in terms of the existing compiler support for the regular "declare variant" directive, but instead of looking up the variant to be attached as an attribute on the base function, the front ends have to do the reverse mapping and find the base function for each variant instead. There are two big functional changes since the last version posted, plus a number of smaller cleanups (comments, diagnostic improvements, more test cases, etc) addressing Tobias's other review comments. I've removed the restriction that base functions must be declared before the "begin declare variant" block. For C it works fine to remember the variants and look up the base functions at the end of the translation unit. On the other hand, the current implementation of "declare variant" in C++ requires that variants be registered with their base functions prior to processing any calls to the base function; otherwise template functions don't get instantiated. This unfortunately requires some parser overhead either at every function declaration or at every call site (outside of a class declaration). I've chosen to do it when parsing function declarations but tried to structure the code to test early for the common case when there are no unregistered variants. I expect this feature will not be frequently used even in OpenMP code that uses this construct, so I've made less effort to optimize the actual lookup. The second functional change compared to the v1 patches is that the name mangling now works with C++ modules and "begin declare variant" in a module interface file gives the variant functions mangled names with module linkage same as other functions. Is this version OK to commit? -Sandra Sandra Loosemore (6): OpenMP: Support functions for nested "begin declare variant" OpenMP: Add flag for code elision to omp_context_selector_matches. OpenMP: C++ front end support for "begin declare variant" OpenMP: C front end support for "begin declare variant" OpenMP: C/C++ common testcases for "omp begin declare variant" OpenMP: Update docs for "begin declare variant" implementation status gcc/c-family/c-omp.cc | 8 +- gcc/c/c-decl.cc | 3 + gcc/c/c-lang.h | 8 + gcc/c/c-parser.cc | 376 ++++++++-- gcc/cp/cp-tree.h | 6 + gcc/cp/decl.cc | 15 + gcc/cp/parser.cc | 644 +++++++++++++++++- gcc/cp/parser.h | 12 + gcc/cp/semantics.cc | 7 + gcc/omp-general.cc | 229 ++++++- gcc/omp-general.h | 7 +- .../gomp/delim-declare-variant-1.c | 55 ++ .../gomp/delim-declare-variant-2.c | 66 ++ .../gomp/delim-declare-variant-3.c | 49 ++ .../gomp/delim-declare-variant-4.c | 31 + .../gomp/delim-declare-variant-5.c | 26 + .../gomp/delim-declare-variant-6.c | 71 ++ .../gomp/delim-declare-variant-7.c | 27 + .../gomp/delim-declare-variant-8.c | 54 ++ .../gomp/delim-declare-variant-9.c | 47 ++ .../g++.dg/gomp/delim-declare-variant-1.C | 39 ++ .../g++.dg/gomp/delim-declare-variant-2.C | 53 ++ .../g++.dg/gomp/delim-declare-variant-3.C | 37 + .../g++.dg/gomp/delim-declare-variant-4.C | 57 ++ .../g++.dg/gomp/delim-declare-variant-40.C | 51 ++ .../g++.dg/gomp/delim-declare-variant-41.C | 29 + .../g++.dg/gomp/delim-declare-variant-5.C | 53 ++ .../g++.dg/gomp/delim-declare-variant-50.C | 99 +++ .../g++.dg/gomp/delim-declare-variant-51.C | 181 +++++ .../g++.dg/gomp/delim-declare-variant-52.C | 24 + .../g++.dg/gomp/delim-declare-variant-6.C | 72 ++ .../g++.dg/gomp/delim-declare-variant-7.C | 57 ++ .../g++.dg/gomp/delim-declare-variant-70.C | 206 ++++++ .../g++.dg/gomp/delim-declare-variant-71.C | 157 +++++ libgomp/libgomp.texi | 5 +- libgomp/testsuite/libgomp.c++/bdv_module1.C | 23 + .../testsuite/libgomp.c++/bdv_module1_main.C | 16 + libgomp/testsuite/libgomp.c++/bdv_module2.C | 15 + .../testsuite/libgomp.c++/bdv_module2_impl.C | 28 + .../testsuite/libgomp.c++/bdv_module2_main.C | 20 + libgomp/testsuite/libgomp.c++/bdv_module3.C | 28 + .../testsuite/libgomp.c++/bdv_module3_impl.C | 33 + .../testsuite/libgomp.c++/bdv_module3_main.C | 25 + .../libgomp.c++/delim-declare-variant-1.C | 29 + .../libgomp.c++/delim-declare-variant-2.C | 37 + .../libgomp.c++/delim-declare-variant-7.C | 39 ++ .../delim-declare-variant-1.c | 45 ++ .../delim-declare-variant-2.c | 47 ++ 48 files changed, 3164 insertions(+), 82 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/delim-declare-variant-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/delim-declare-variant-2.c create mode 100644 gcc/testsuite/c-c++-common/gomp/delim-declare-variant-3.c create mode 100644 gcc/testsuite/c-c++-common/gomp/delim-declare-variant-4.c create mode 100644 gcc/testsuite/c-c++-common/gomp/delim-declare-variant-5.c create mode 100644 gcc/testsuite/c-c++-common/gomp/delim-declare-variant-6.c create mode 100644 gcc/testsuite/c-c++-common/gomp/delim-declare-variant-7.c create mode 100644 gcc/testsuite/c-c++-common/gomp/delim-declare-variant-8.c create mode 100644 gcc/testsuite/c-c++-common/gomp/delim-declare-variant-9.c create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-1.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-2.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-3.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-4.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-40.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-41.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-5.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-50.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-51.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-52.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-6.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-7.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-70.C create mode 100644 gcc/testsuite/g++.dg/gomp/delim-declare-variant-71.C create mode 100644 libgomp/testsuite/libgomp.c++/bdv_module1.C create mode 100644 libgomp/testsuite/libgomp.c++/bdv_module1_main.C create mode 100644 libgomp/testsuite/libgomp.c++/bdv_module2.C create mode 100644 libgomp/testsuite/libgomp.c++/bdv_module2_impl.C create mode 100644 libgomp/testsuite/libgomp.c++/bdv_module2_main.C create mode 100644 libgomp/testsuite/libgomp.c++/bdv_module3.C create mode 100644 libgomp/testsuite/libgomp.c++/bdv_module3_impl.C create mode 100644 libgomp/testsuite/libgomp.c++/bdv_module3_main.C create mode 100644 libgomp/testsuite/libgomp.c++/delim-declare-variant-1.C create mode 100644 libgomp/testsuite/libgomp.c++/delim-declare-variant-2.C create mode 100644 libgomp/testsuite/libgomp.c++/delim-declare-variant-7.C create mode 100644 libgomp/testsuite/libgomp.c-c++-common/delim-declare-variant-1.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/delim-declare-variant-2.c -- 2.39.5
