ormris created this revision. ormris added reviewers: dblaikie, aprantl, probinson, JDevlieghere.
This patch adds the associated template parameters to the DWARF name attribute of all template variable specializations, mirroring how they are referenced in the source code. Repository: rC Clang https://reviews.llvm.org/D44842 Files: lib/CodeGen/CGDebugInfo.cpp test/CodeGenCXX/debug-info-template.cpp Index: test/CodeGenCXX/debug-info-template.cpp =================================================================== --- test/CodeGenCXX/debug-info-template.cpp +++ test/CodeGenCXX/debug-info-template.cpp @@ -160,3 +160,14 @@ }; PaddingAtEndTemplate<&PaddedObj> PaddedTemplateObj; + +// RUN: %clang -S -emit-llvm -target x86_64-unknown_unknown -g %s -o - -std=c++14 | FileCheck %s --check-prefix=CXX14 +// CXX14: !DIGlobalVariable(name: "vartemp<int>" +// CXX14: !DIGlobalVariable(name: "arraytemp<int,1>" +template <typename T> T vartemp = T(); +template <typename T, int N> T arraytemp[N]; + +void func() { + vartemp<int> = 5; + arraytemp<int, 1>[0] = 1; +} Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -2982,8 +2982,27 @@ Name = VD->getName(); if (VD->getDeclContext() && !isa<FunctionDecl>(VD->getDeclContext()) && - !isa<ObjCMethodDecl>(VD->getDeclContext())) + !isa<ObjCMethodDecl>(VD->getDeclContext())) { LinkageName = CGM.getMangledName(VD); + // If this node refers to an instantiation of a variable template, add the + // template parameters to its name. This disambiguates it from other + // instantiations. + if (auto *VSD = dyn_cast<VarTemplateSpecializationDecl>(VD)) { + std::string NameString = Name.str(); + llvm::raw_string_ostream ParameterizedName(NameString); + ParameterizedName << "<"; + bool first = true; + for (auto Parameter : VSD->getTemplateArgs().asArray()) { + if (!first) + ParameterizedName << ","; + Parameter.print(getPrintingPolicy(), ParameterizedName); + first = false; + } + ParameterizedName << ">"; + Name = internString(ParameterizedName.str()); + } + } + if (LinkageName == Name) LinkageName = StringRef();
Index: test/CodeGenCXX/debug-info-template.cpp =================================================================== --- test/CodeGenCXX/debug-info-template.cpp +++ test/CodeGenCXX/debug-info-template.cpp @@ -160,3 +160,14 @@ }; PaddingAtEndTemplate<&PaddedObj> PaddedTemplateObj; + +// RUN: %clang -S -emit-llvm -target x86_64-unknown_unknown -g %s -o - -std=c++14 | FileCheck %s --check-prefix=CXX14 +// CXX14: !DIGlobalVariable(name: "vartemp<int>" +// CXX14: !DIGlobalVariable(name: "arraytemp<int,1>" +template <typename T> T vartemp = T(); +template <typename T, int N> T arraytemp[N]; + +void func() { + vartemp<int> = 5; + arraytemp<int, 1>[0] = 1; +} Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -2982,8 +2982,27 @@ Name = VD->getName(); if (VD->getDeclContext() && !isa<FunctionDecl>(VD->getDeclContext()) && - !isa<ObjCMethodDecl>(VD->getDeclContext())) + !isa<ObjCMethodDecl>(VD->getDeclContext())) { LinkageName = CGM.getMangledName(VD); + // If this node refers to an instantiation of a variable template, add the + // template parameters to its name. This disambiguates it from other + // instantiations. + if (auto *VSD = dyn_cast<VarTemplateSpecializationDecl>(VD)) { + std::string NameString = Name.str(); + llvm::raw_string_ostream ParameterizedName(NameString); + ParameterizedName << "<"; + bool first = true; + for (auto Parameter : VSD->getTemplateArgs().asArray()) { + if (!first) + ParameterizedName << ","; + Parameter.print(getPrintingPolicy(), ParameterizedName); + first = false; + } + ParameterizedName << ">"; + Name = internString(ParameterizedName.str()); + } + } + if (LinkageName == Name) LinkageName = StringRef();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits