r224316 - AST: Fix the linkage of static vars in fn template	specializations
    David Majnemer 
    david.majnemer at gmail.com
       
    Mon Dec 15 20:52:14 PST 2014
    
    
  
Author: majnemer
Date: Mon Dec 15 22:52:14 2014
New Revision: 224316
URL: http://llvm.org/viewvc/llvm-project?rev=224316&view=rev
Log:
AST: Fix the linkage of static vars in fn template specializations
We that static variables in function template specializations were
externally visible.  The manglers assumed that externally visible static
variables were numbered in Sema.  We would end up mangling static
variables in the same specialization with the same mangling number which
would give all of them the same name.
This fixes PR21904.
Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/test/CodeGenCXX/function-template-specialization.cpp
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=224316&r1=224315&r2=224316&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Dec 15 22:52:14 2014
@@ -1192,7 +1192,7 @@ static LinkageInfo getLVForLocalDecl(con
   } else {
     const FunctionDecl *FD = cast<FunctionDecl>(OuterD);
     if (!FD->isInlined() &&
-        FD->getTemplateSpecializationKind() == TSK_Undeclared)
+        !isTemplateInstantiation(FD->getTemplateSpecializationKind()))
       return LinkageInfo::none();
 
     LV = getLVForDecl(FD, computation);
Modified: cfe/trunk/test/CodeGenCXX/function-template-specialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/function-template-specialization.cpp?rev=224316&r1=224315&r2=224316&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/function-template-specialization.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/function-template-specialization.cpp Mon Dec 15 22:52:14 2014
@@ -1,4 +1,8 @@
 // RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - | FileCheck %s
+
+// CHECK-DAG: _ZZN7PR219047GetDataIiEERKibE1i = internal global i32 4
+// CHECK-DAG: _ZZN7PR219047GetDataIiEERKibE1i_0 = internal global i32 2
+
 template<typename T, typename U>
 T* next(T* ptr, const U& diff);
 
@@ -24,3 +28,18 @@ void test2(int *iptr, double *dptr, int
   // CHECK: _Z4nextIdiEPT_S1_RKT0_
   dptr = next(dptr, diff);
 }
+
+namespace PR21904 {
+template <typename>
+const int &GetData(bool);
+
+template <>
+const int &GetData<int>(bool b) {
+  static int i = 4;
+  if (b) {
+    static int i = 2;
+    return i;
+  }
+  return i;
+}
+}
    
    
More information about the cfe-commits
mailing list