]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: Fix omp_check_for_duplicate_variant [PR125377]
authorTobias Burnus <tburnus@baylibre.com>
Mon, 25 May 2026 11:13:46 +0000 (13:13 +0200)
committerTobias Burnus <tburnus@baylibre.com>
Mon, 25 May 2026 11:13:46 +0000 (13:13 +0200)
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.

gcc/omp-general.cc
gcc/testsuite/c-c++-common/gomp/begin-declare-variant-1.c [new file with mode: 0644]

index 7ab9770b98f6f8ff765019354652dfe1eca9de3e..118653c53d2a11ac99eb5b46d978ee4f88266dcb 100644 (file)
@@ -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 (file)
index 0000000..7301dee
--- /dev/null
@@ -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());
+}