diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2014-12-16 04:52:14 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2014-12-16 04:52:14 +0000 |
| commit | 9963adeaefaf0dca48b8c207a3ed7098528f338c (patch) | |
| tree | bd0cbced341e0970c7f18f4ae5ff0eba696e8aa9 /clang | |
| parent | 731089bbce16d5d40e0c89c24cbc9923623240c9 (diff) | |
| download | bcm5719-llvm-9963adeaefaf0dca48b8c207a3ed7098528f338c.tar.gz bcm5719-llvm-9963adeaefaf0dca48b8c207a3ed7098528f338c.zip | |
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.
llvm-svn: 224316
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/AST/Decl.cpp | 2 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/function-template-specialization.cpp | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 1c0c6f76672..e43c28af9b6 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1192,7 +1192,7 @@ static LinkageInfo getLVForLocalDecl(const NamedDecl *D, } else { const FunctionDecl *FD = cast<FunctionDecl>(OuterD); if (!FD->isInlined() && - FD->getTemplateSpecializationKind() == TSK_Undeclared) + !isTemplateInstantiation(FD->getTemplateSpecializationKind())) return LinkageInfo::none(); LV = getLVForDecl(FD, computation); diff --git a/clang/test/CodeGenCXX/function-template-specialization.cpp b/clang/test/CodeGenCXX/function-template-specialization.cpp index eb099df14d0..7728f3dc746 100644 --- a/clang/test/CodeGenCXX/function-template-specialization.cpp +++ b/clang/test/CodeGenCXX/function-template-specialization.cpp @@ -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 diff) { // 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; +} +} |

