]> granicus.if.org Git - clang/commitdiff
[clang] Properly apply attributes on explicit instantiations of static data members
authorLouis Dionne <ldionne@apple.com>
Wed, 10 Oct 2018 15:32:29 +0000 (15:32 +0000)
committerLouis Dionne <ldionne@apple.com>
Wed, 10 Oct 2018 15:32:29 +0000 (15:32 +0000)
Summary: https://llvm.org/PR39118

Reviewers: aaron.ballman, rnk

Subscribers: dexonsmith, cfe-commits

Differential Revision: https://reviews.llvm.org/D52675

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344146 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplate.cpp
test/SemaCXX/attr-on-explicit-template-instantiation.cpp [new file with mode: 0644]

index 61e51de349e58766eb7d1bcfb7b3723f6a36e0ff..fb792b7539c98e758b54f925ce47169f78c39bae 100644 (file)
@@ -9173,10 +9173,8 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
     if (!HasNoEffect) {
       // Instantiate static data member or variable template.
       Prev->setTemplateSpecializationKind(TSK, D.getIdentifierLoc());
-      if (PrevTemplate) {
-        // Merge attributes.
-        ProcessDeclAttributeList(S, Prev, D.getDeclSpec().getAttributes());
-      }
+      // Merge attributes.
+      ProcessDeclAttributeList(S, Prev, D.getDeclSpec().getAttributes());
       if (TSK == TSK_ExplicitInstantiationDefinition)
         InstantiateVariableDefinition(D.getIdentifierLoc(), Prev);
     }
diff --git a/test/SemaCXX/attr-on-explicit-template-instantiation.cpp b/test/SemaCXX/attr-on-explicit-template-instantiation.cpp
new file mode 100644 (file)
index 0000000..d930c17
--- /dev/null
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+// PR39118
+// Make sure that attributes are properly applied to explicit template
+// instantiations.
+
+#define HIDDEN __attribute__((__visibility__("hidden")))
+#define VISIBLE __attribute__((__visibility__("default")))
+
+namespace ns HIDDEN {
+    struct A { };
+    template <typename T> struct B { static A a; };
+    template <typename T> A B<T>::a;
+
+    // CHECK: @_ZN2ns1BIiE1aE = weak_odr global
+    // CHECK-NOT: hidden
+    template VISIBLE A B<int>::a;
+}
+
+struct C { };
+template <typename T> struct D { static C c; };
+template <typename T> C D<T>::c;
+
+// CHECK-DAG: @_ZN1DIiE1cB3TAGE
+template __attribute__((abi_tag("TAG"))) C D<int>::c;