From: Tobias Burnus Date: Mon, 25 May 2026 11:13:46 +0000 (+0200) Subject: OpenMP: Fix omp_check_for_duplicate_variant [PR125377] X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=64be1fa670a04c81d48dfdaa074d8bf8f935d746;p=thirdparty%2Fgcc.git OpenMP: Fix omp_check_for_duplicate_variant [PR125377] Follow up to r16-5508-g77b8221af8fc82; seemingly, a testcase never got added - and the internal representation changed afther the code was written. At least the previous code ICE'd for the included testcase. PR c/125377 gcc/ChangeLog: * omp-general.cc (omp_check_for_duplicate_variant): Fix used tree for 'inform' part of the error message. gcc/testsuite/ChangeLog: * c-c++-common/gomp/begin-declare-variant-1.c: New test. --- diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 7ab9770b98f..118653c53d2 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1562,7 +1562,7 @@ omp_check_for_duplicate_variant (location_t loc, tree base_decl, tree ctx) error_at (loc, "multiple definitions of variants with the same " "context selector violate the one-definition rule"); - inform (DECL_SOURCE_LOCATION (TREE_PURPOSE (attr)), + inform (DECL_SOURCE_LOCATION (TREE_PURPOSE (TREE_VALUE (attr))), "previous variant declaration here"); return false; } diff --git a/gcc/testsuite/c-c++-common/gomp/begin-declare-variant-1.c b/gcc/testsuite/c-c++-common/gomp/begin-declare-variant-1.c new file mode 100644 index 00000000000..7301dee28c0 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/begin-declare-variant-1.c @@ -0,0 +1,16 @@ +/* PR c/125377 */ + +static int omp_is_initial_device(void); +// { dg-warning "'omp_is_initial_device' used but never defined" "" { target c } .-1 } +#pragma omp begin declare variant match(device={kind(host)}) + static inline int omp_is_initial_device(void) { return 1; } // { dg-note "previous variant declaration here" } +#pragma omp end declare variant + +#pragma omp begin declare variant match(device={kind(host)}) + static inline int omp_is_initial_device(void) { return 1; } // { dg-error "multiple definitions of variants with the same context selector violate the one-definition rule" } +#pragma omp end declare variant + +int main() +{ + __builtin_printf("%d\n", omp_is_initial_device()); +}