This patch set is almost certainly too late to make it in GCC 15, except possibly the first two pieces (a bug fix and an internal interface cleanup). These patches are against current mainline head, but I am planning to shortly commit a near-identical version to the OG14 development branch and I hope it will be possible to get (perhaps a revised version of) this into mainline early in stage 1.
This set of patches implements the delimited form of the OpenMP declare variant construct. Julian Brown previously posted some initial work on this last year https://gcc.gnu.org/pipermail/gcc-patches/2024-January/642738.html but I have taken a different approach in the current implementation. I thought it was a clear design mistake to mix up the implicitly-named variant functions with C++ overloading, since that wasn't going to work for C. Even in C++, resolution of "declare variant" is independent of overloading; it happens much later in compilation, during gimplification or later in the compilation process, not in the front end. Instead, I've simply assigned the variant functions unique internal names. I also discarded Julian's complicated name-mangling code because it wasn't clear how to uniquely encode arbitrary expressions in dynamic selectors, or why it was even necessary to have a reproducible mangling across compilation units when there is no way to directly reference the variant functions by name even within a single compilation unit. The C++ implementation uses the existing omp_declare_variant_finalize_one function "backwards" to map the variant decl onto the corresponding base decl, instead of the opposite base->variant for regular "declare variant". In C, this is just a simple name lookup. For both languages, the variant info is stored in an attribute on the base function decl in the same way as regular "declare variant" and from there everything proceeds using the same existing mechanisms. Some aspects of the interaction between "begin declare variant" and C++ language features are not particularly clear in the OpenMP specification, but I tried to implement and test features that users would likely expect to work. Variant functions for class methods do work with the caveat that you have to define them inside the class with an unqualified name; similarly with namespaces. Variants for template functions and methods inside a template class work in simple test cases, but there's a known bug where it emits a "sorry" when it cannot resolve the base function for a template variant without instantiating the variant. (It seems to me that is a chicken-and-egg problem since you don't know how to instantiate the variant to match the base function until you actually have a base function.) Additionally, the reverse lookup in omp_declare_variant_finalize_one is affected by the same existing bugs it has for regular "declare variant" (e.g. PR118530 and PR118791) causing some bogus errors that are xfailed in the corresponding test cases. -Sandra Sandra Loosemore (7): OpenMP: Bug fixes for comparing context selectors OpenMP: Pass a 3-way flag to omp_check_context_selector instead of a bool. 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" gcc/c/c-decl.cc | 3 + gcc/c/c-lang.h | 8 + gcc/c/c-parser.cc | 353 +++++++++-- gcc/cp/cp-tree.h | 6 + gcc/cp/decl.cc | 15 + gcc/cp/parser.cc | 550 ++++++++++++++++-- gcc/cp/parser.h | 5 + gcc/cp/semantics.cc | 7 + gcc/fortran/trans-openmp.cc | 5 +- gcc/omp-general.cc | 266 ++++++++- gcc/omp-general.h | 13 +- .../gomp/delim-declare-variant-1.c | 55 ++ .../gomp/delim-declare-variant-2.c | 66 +++ .../gomp/delim-declare-variant-3.c | 50 ++ .../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 + .../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 | 31 + .../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.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 ++ 36 files changed, 2735 insertions(+), 89 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/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++/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 -- 2.34.1