https://gcc.gnu.org/g:64be1fa670a04c81d48dfdaa074d8bf8f935d746

commit r17-756-g64be1fa670a04c81d48dfdaa074d8bf8f935d746
Author: Tobias Burnus <[email protected]>
Date:   Mon May 25 13:13:46 2026 +0200

    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:
---
 gcc/omp-general.cc                                       |  2 +-
 .../c-c++-common/gomp/begin-declare-variant-1.c          | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 7ab9770b98f6..118653c53d2a 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 000000000000..7301dee28c03
--- /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());
+}

Reply via email to