diff options
author | Matthew Voss <matthew.voss@sony.com> | 2018-10-03 18:45:04 +0000 |
---|---|---|
committer | Matthew Voss <matthew.voss@sony.com> | 2018-10-03 18:45:04 +0000 |
commit | 2016536304c66618a8321bedeb9bcc8c7b3eee1e (patch) | |
tree | 2690db311b76ef0309ffa6a72395b98a2789a629 /clang/lib/CodeGen | |
parent | f8ab35a4f464753751c1df2b56b6c2f9c75d56a7 (diff) | |
download | bcm5719-llvm-2016536304c66618a8321bedeb9bcc8c7b3eee1e.tar.gz bcm5719-llvm-2016536304c66618a8321bedeb9bcc8c7b3eee1e.zip |
Add template type and value parameter metadata nodes to template variable specializations
Summary: Add an optional attribute referring to a tuple of type and value template parameter nodes to the DIGlobalVariable node. This allows us to record the parameters of template variable specializations.
Reviewers: dblaikie, aprantl, probinson, JDevlieghere, clayborg, jingham
Reviewed By: JDevlieghere
Subscribers: cfe-commits
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D52058
llvm-svn: 343707
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 56 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.h | 9 |
2 files changed, 59 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 7d6eb83f12d..c87d74657d7 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -41,6 +41,7 @@ #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Intrinsics.h" +#include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MD5.h" @@ -1776,6 +1777,29 @@ CGDebugInfo::CollectFunctionTemplateParams(const FunctionDecl *FD, return llvm::DINodeArray(); } +llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(const VarDecl *VL, + llvm::DIFile *Unit) { + if (auto *TS = dyn_cast<VarTemplateSpecializationDecl>(VL)) { + auto T = TS->getSpecializedTemplateOrPartial(); + auto TA = TS->getTemplateArgs().asArray(); + // Collect parameters for a partial specialization + if (T.is<VarTemplatePartialSpecializationDecl *>()) { + const TemplateParameterList *TList = + T.get<VarTemplatePartialSpecializationDecl *>() + ->getTemplateParameters(); + return CollectTemplateParams(TList, TA, Unit); + } + + // Collect parameters for an explicit specialization + if (T.is<VarTemplateDecl *>()) { + const TemplateParameterList *TList = T.get<VarTemplateDecl *>() + ->getTemplateParameters(); + return CollectTemplateParams(TList, TA, Unit); + } + } + return llvm::DINodeArray(); +} + llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams( const ClassTemplateSpecializationDecl *TSpecial, llvm::DIFile *Unit) { // Always get the full list of parameters, not just the ones from @@ -3070,6 +3094,7 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit, void CGDebugInfo::collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit, unsigned &LineNo, QualType &T, StringRef &Name, StringRef &LinkageName, + llvm::MDTuple *&TemplateParameters, llvm::DIScope *&VDContext) { Unit = getOrCreateFile(VD->getLocation()); LineNo = getLineNumber(VD->getLocation()); @@ -3093,6 +3118,13 @@ void CGDebugInfo::collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit, if (LinkageName == Name) LinkageName = StringRef(); + if (isa<VarTemplateSpecializationDecl>(VD)) { + llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit); + TemplateParameters = parameterNodes.get(); + } else { + TemplateParameters = nullptr; + } + // Since we emit declarations (DW_AT_members) for static members, place the // definition of those static members in the namespace they were declared in // in the source code (the lexical decl context). @@ -3173,12 +3205,14 @@ CGDebugInfo::getGlobalVariableForwardDeclaration(const VarDecl *VD) { llvm::DIFile *Unit = getOrCreateFile(Loc); llvm::DIScope *DContext = Unit; unsigned Line = getLineNumber(Loc); + llvm::MDTuple *TemplateParameters = nullptr; - collectVarDeclProps(VD, Unit, Line, T, Name, LinkageName, DContext); + collectVarDeclProps(VD, Unit, Line, T, Name, LinkageName, TemplateParameters, + DContext); auto Align = getDeclAlignIfRequired(VD, CGM.getContext()); auto *GV = DBuilder.createTempGlobalVariableFwdDecl( DContext, Name, LinkageName, Unit, Line, getOrCreateType(T, Unit), - !VD->isExternallyVisible(), nullptr, Align); + !VD->isExternallyVisible(), nullptr, TemplateParameters, Align); FwdDeclReplaceMap.emplace_back( std::piecewise_construct, std::make_tuple(cast<VarDecl>(VD->getCanonicalDecl())), @@ -4089,7 +4123,9 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, unsigned LineNo; StringRef DeclName, LinkageName; QualType T; - collectVarDeclProps(D, Unit, LineNo, T, DeclName, LinkageName, DContext); + llvm::MDTuple *TemplateParameters = nullptr; + collectVarDeclProps(D, Unit, LineNo, T, DeclName, LinkageName, + TemplateParameters, DContext); // Attempt to store one global variable for the declaration - even if we // emit a lot of fields. @@ -4115,7 +4151,8 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit), Var->hasLocalLinkage(), Expr.empty() ? nullptr : DBuilder.createExpression(Expr), - getOrCreateStaticDataMemberDeclarationOrNull(D), Align); + getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters, + Align); Var->addDebugInfo(GVE); } DeclCache[D->getCanonicalDecl()].reset(GVE); @@ -4172,10 +4209,19 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) { InitExpr = DBuilder.createConstantValueExpression( Init.getFloat().bitcastToAPInt().getZExtValue()); } + + llvm::MDTuple *TemplateParameters = nullptr; + + if (isa<VarTemplateSpecializationDecl>(VD)) + if (VarD) { + llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VarD, &*Unit); + TemplateParameters = parameterNodes.get(); + } + GV.reset(DBuilder.createGlobalVariableExpression( DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty, true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD), - Align)); + TemplateParameters, Align)); } llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) { diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 8641c2d8969..b007621c723 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -248,6 +248,11 @@ class CGDebugInfo { llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD, llvm::DIFile *Unit); + /// A helper function to collect debug info for function template + /// parameters. + llvm::DINodeArray CollectVarTemplateParams(const VarDecl *VD, + llvm::DIFile *Unit); + /// A helper function to collect debug info for template /// parameters. llvm::DINodeArray @@ -645,7 +650,9 @@ private: /// Collect various properties of a VarDecl. void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit, unsigned &LineNo, QualType &T, StringRef &Name, - StringRef &LinkageName, llvm::DIScope *&VDContext); + StringRef &LinkageName, + llvm::MDTuple *&TemplateParameters, + llvm::DIScope *&VDContext); /// Allocate a copy of \p A using the DebugInfoNames allocator /// and return a reference to it. If multiple arguments are given the strings |