Michael137 created this revision. Michael137 added reviewers: aprantl, dblaikie. Herald added a subscriber: hiraditya. Herald added a project: All. Michael137 requested review of this revision. Herald added projects: clang, LLVM. Herald added subscribers: llvm-commits, cfe-commits.
After this patch, in the following snippet: template <typename T> Foo {}; template <template <typename T> class CT = Foo> Bar {}; Bar<> b; The debug-info entry for the `CT` template parameter will have a `DW_AT_default_value (true)` attached to it. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D139989 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGenCXX/debug-info-template-parameter.cpp llvm/include/llvm/IR/DIBuilder.h llvm/lib/IR/DIBuilder.cpp
Index: llvm/lib/IR/DIBuilder.cpp =================================================================== --- llvm/lib/IR/DIBuilder.cpp +++ llvm/lib/IR/DIBuilder.cpp @@ -474,10 +474,11 @@ DITemplateValueParameter * DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name, - DIType *Ty, StringRef Val) { + DIType *Ty, StringRef Val, + bool IsDefault) { return createTemplateValueParameterHelper( VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty, - false, MDString::get(VMContext, Val)); + IsDefault, MDString::get(VMContext, Val)); } DITemplateValueParameter * Index: llvm/include/llvm/IR/DIBuilder.h =================================================================== --- llvm/include/llvm/IR/DIBuilder.h +++ llvm/include/llvm/IR/DIBuilder.h @@ -518,10 +518,10 @@ /// \param Name Value parameter name. /// \param Ty Parameter type. /// \param Val The fully qualified name of the template. - DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope, - StringRef Name, - DIType *Ty, - StringRef Val); + /// \param IsDefault Parameter is default or not. + DITemplateValueParameter * + createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty, + StringRef Val, bool IsDefault); /// Create debugging information for a template parameter pack. /// \param Scope Scope in which this type is defined. Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp =================================================================== --- clang/test/CodeGenCXX/debug-info-template-parameter.cpp +++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp @@ -22,17 +22,37 @@ // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, defaulted: true, value: i1 true) // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, defaulted: true) +// CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]] +// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[B1_TYPE:[0-9]+]] +// CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]} +// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "CT", value: !"qux") + +// CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]] +// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[B2_TYPE:[0-9]+]] +// CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]} +// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar") + template <typename T> class bar { }; +template <typename T> +class qux { +}; + template <typename T = char, int i = 3, bool b = true, int x = sizeof(T), typename d = bar<T>> class foo { }; +template <template <typename T> class CT = bar> +class baz { +}; + int main() { foo<int, 6, false, 3, double> f1; foo<> f2; + baz<qux> b1; + baz<> b2; return 0; } Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -2091,12 +2091,18 @@ TheCU, Name, TTy, defaultParameter, V)); } break; case TemplateArgument::Template: { + if (Args.TList) { + NamedDecl const *ND = Args.TList->getParam(i); + defaultParameter = TemplateUtils::isSubstitutedDefaultArgument( + CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth()); + } + std::string QualName; llvm::raw_string_ostream OS(QualName); TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName( OS, getPrintingPolicy()); TemplateParams.push_back(DBuilder.createTemplateTemplateParameter( - TheCU, Name, nullptr, OS.str())); + TheCU, Name, nullptr, OS.str(), defaultParameter)); break; } case TemplateArgument::Pack:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits