[PATCH] D14358: DWARF's forward decl of a template should have template parameters.

Paul Robinson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 11 10:34:47 PDT 2017


probinson updated this revision to Diff 106063.
probinson added a comment.

Refresh to current TOT, and ping.  Funny what you can find in a year-old to-do list....


https://reviews.llvm.org/D14358

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGenCXX/debug-info-template-fwd-param.cpp
  test/Modules/ExtDebugInfo.cpp


Index: test/Modules/ExtDebugInfo.cpp
===================================================================
--- test/Modules/ExtDebugInfo.cpp
+++ test/Modules/ExtDebugInfo.cpp
@@ -93,9 +93,13 @@
 // CHECK-SAME:             flags: DIFlagFwdDecl,
 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE")
 
-// This type isn't, however, even with standalone non-module debug info this
-// type is a forward declaration.
-// CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<int>",
+// This type isn't, however, it is a template parameter type and so gets a
+// forward declaration.
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK-SAME:             name: "traits<int>",
+// CHECK-SAME:             scope: ![[NS]],
+// CHECK-SAME:             flags: DIFlagFwdDecl,
+// CHECK-SAME:             identifier: "_ZTSN8DebugCXX6traitsIiEE")
 
 // This one isn't.
 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
Index: test/CodeGenCXX/debug-info-template-fwd-param.cpp
===================================================================
--- test/CodeGenCXX/debug-info-template-fwd-param.cpp
+++ test/CodeGenCXX/debug-info-template-fwd-param.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
+// A forward declaration of a template should still have template parameters.
+
+template<typename T> class A {
+public:
+  A(T val);
+private:
+  T x;
+};
+
+struct B {
+  A<const int> *p;
+};
+
+B b;
+
+// CHECK:      !DICompositeType(tag: DW_TAG_class_type, name: "A<const int>"
+// CHECK-SAME:     flags: DIFlagFwdDecl
+// CHECK-SAME:     templateParams: [[PARAM_LIST:![0-9]*]]
+// CHECK:      [[PARAM_LIST]] = !{[[PARAM:![0-9]*]]}
+// CHECK:      [[PARAM]] = !DITemplateTypeParameter(name: "T",
+// CHECK-SAME:     type: [[CTYPE:![0-9]*]]
+// CHECK:      [[CTYPE]] = !DIDerivedType(tag: DW_TAG_const_type
+// CHECK-SAME:     baseType: [[BTYPE:![0-9]*]]
+// CHECK:      [[BTYPE]] = !DIBasicType(name: "int"
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -805,6 +805,10 @@
   llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
       getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align,
       llvm::DINode::FlagFwdDecl, FullName);
+  if (const ClassTemplateSpecializationDecl *TSpecial =
+          dyn_cast<ClassTemplateSpecializationDecl>(RD))
+    DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),
+                           CollectCXXTemplateParams(TSpecial, DefUnit));
   ReplaceMap.emplace_back(
       std::piecewise_construct, std::make_tuple(Ty),
       std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14358.106063.patch
Type: text/x-patch
Size: 2805 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170711/da789c21/attachment.bin>


More information about the cfe-commits mailing list