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

Paul Robinson via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 16:26:08 PST 2015


probinson created this revision.
probinson added reviewers: echristo, dblaikie, aprantl.
probinson added a subscriber: cfe-commits.

We were forgetting the template parameters on the forward declaration of a template class.


http://reviews.llvm.org/D14358

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

Index: test/CodeGenCXX/debug-info-template-member.cpp
===================================================================
--- test/CodeGenCXX/debug-info-template-member.cpp
+++ test/CodeGenCXX/debug-info-template-member.cpp
@@ -34,6 +34,13 @@
 // CHECK: [[VIRT_TEMP_PARAM]] = !{[[VIRT_T:![0-9]*]]}
 // CHECK: [[VIRT_T]] = !DITemplateTypeParameter(name: "T", type: !"_ZTS4elem")
 
+// CHECK: [[ELEM:![0-9]*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "elem"
+// CHECK-SAME:                                elements: [[ELEM_MEM:![0-9]*]]
+// CHECK-SAME:                                identifier: "_ZTS4elem"
+// CHECK: [[ELEM_MEM]] = !{[[ELEM_X:![0-9]*]]}
+// CHECK: [[ELEM_X]] = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !"_ZTS4elem"
+// CHECK-SAME:                        baseType: !"_ZTS4virtI4elemE"
+
 // CHECK: [[C:![0-9]*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "MyClass"
 // CHECK-SAME:                             elements: [[C_MEM:![0-9]*]]
 // CHECK-SAME:                             vtableHolder: !"_ZTS7MyClass"
@@ -43,13 +50,6 @@
 
 // CHECK: [[C_FUNC]] = !DISubprogram(name: "func",{{.*}} line: 7,
 
-// CHECK: [[ELEM:![0-9]*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "elem"
-// CHECK-SAME:                                elements: [[ELEM_MEM:![0-9]*]]
-// CHECK-SAME:                                identifier: "_ZTS4elem"
-// CHECK: [[ELEM_MEM]] = !{[[ELEM_X:![0-9]*]]}
-// CHECK: [[ELEM_X]] = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !"_ZTS4elem"
-// CHECK-SAME:                        baseType: !"_ZTS4virtI4elemE"
-
 // Check that the member function template specialization and implicit special
 // members (the default ctor) refer to their class by scope, even though they
 // didn't appear in the class's member list (C_MEM). This prevents the functions
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
@@ -702,6 +702,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.39286.patch
Type: text/x-patch
Size: 3635 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151105/2c54ec3f/attachment-0001.bin>


More information about the cfe-commits mailing list