r344146 - [clang] Properly apply attributes on explicit instantiations of static data members

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 10 08:32:29 PDT 2018


Author: ldionne
Date: Wed Oct 10 08:32:29 2018
New Revision: 344146

URL: http://llvm.org/viewvc/llvm-project?rev=344146&view=rev
Log:
[clang] Properly apply attributes on explicit instantiations of static data members

Summary: https://llvm.org/PR39118

Reviewers: aaron.ballman, rnk

Subscribers: dexonsmith, cfe-commits

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

Added:
    cfe/trunk/test/SemaCXX/attr-on-explicit-template-instantiation.cpp
Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=344146&r1=344145&r2=344146&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Oct 10 08:32:29 2018
@@ -9173,10 +9173,8 @@ DeclResult Sema::ActOnExplicitInstantiat
     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);
     }

Added: cfe/trunk/test/SemaCXX/attr-on-explicit-template-instantiation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-on-explicit-template-instantiation.cpp?rev=344146&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-on-explicit-template-instantiation.cpp (added)
+++ cfe/trunk/test/SemaCXX/attr-on-explicit-template-instantiation.cpp Wed Oct 10 08:32:29 2018
@@ -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;




More information about the cfe-commits mailing list