]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: abi_tag attribute on templates [PR109715]
authorPatrick Palka <ppalka@redhat.com>
Fri, 15 Dec 2023 15:03:26 +0000 (10:03 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 15 Dec 2023 15:03:26 +0000 (10:03 -0500)
We need to look through TEMPLATE_DECL when looking up the abi_tag
attribute (as with other function/variable declaration attributes).

PR c++/109715

gcc/cp/ChangeLog:

* mangle.cc (get_abi_tags): Strip TEMPLATE_DECL before looking
up the abi_tag attribute.

gcc/testsuite/ChangeLog:

* g++.dg/abi/abi-tag25.C: New test.
* g++.dg/abi/abi-tag25a.C: New test.

gcc/cp/mangle.cc
gcc/testsuite/g++.dg/abi/abi-tag25.C [new file with mode: 0644]
gcc/testsuite/g++.dg/abi/abi-tag25a.C [new file with mode: 0644]

index 0684f0e60380fe6231b581b8ea72d340f60d5a3b..365d470f46ee0c494d4bc4fc20379532a8fb1f5b 100644 (file)
@@ -530,6 +530,16 @@ get_abi_tags (tree t)
   if (DECL_P (t) && DECL_DECLARES_TYPE_P (t))
     t = TREE_TYPE (t);
 
+  if (TREE_CODE (t) == TEMPLATE_DECL && DECL_TEMPLATE_RESULT (t))
+    {
+      tree tags = get_abi_tags (DECL_TEMPLATE_RESULT (t));
+      /* We used to overlook abi_tag on function and variable templates.  */
+      if (tags && abi_check (19))
+       return tags;
+      else
+       return NULL_TREE;
+    }
+
   tree attrs;
   if (TYPE_P (t))
     attrs = TYPE_ATTRIBUTES (t);
diff --git a/gcc/testsuite/g++.dg/abi/abi-tag25.C b/gcc/testsuite/g++.dg/abi/abi-tag25.C
new file mode 100644 (file)
index 0000000..9847f0d
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/109715
+// { dg-do compile { target c++11 } }
+
+template<class T>
+[[gnu::abi_tag("foo")]] void fun() { }
+
+template void fun<int>();
+
+#if __cpp_variable_templates
+template<class T>
+[[gnu::abi_tag("foo")]] int var = 0;
+
+template int var<int>;
+#endif
+
+// { dg-final { scan-assembler "_Z3funB3fooIiEvv" } }
+// { dg-final { scan-assembler "_Z3varB3fooIiE" { target c++14 } } }
diff --git a/gcc/testsuite/g++.dg/abi/abi-tag25a.C b/gcc/testsuite/g++.dg/abi/abi-tag25a.C
new file mode 100644 (file)
index 0000000..9499b56
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/109715
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-fabi-version=18 -fabi-compat-version=18 -Wabi=0" }
+
+#include "abi-tag25.C"
+
+// { dg-warning "mangled name" "" { target *-*-* } 5 }
+// { dg-warning "mangled name" "" { target *-*-* } 11 }
+
+// { dg-final { scan-assembler "_Z3funIiEvv" } }
+// { dg-final { scan-assembler "_Z3varIiE" { target c++14 } } }