]> granicus.if.org Git - clang/commitdiff
Include debug info for nested structs and classes
authorAdrian McCarthy <amccarth@google.com>
Wed, 6 Jul 2016 14:46:42 +0000 (14:46 +0000)
committerAdrian McCarthy <amccarth@google.com>
Wed, 6 Jul 2016 14:46:42 +0000 (14:46 +0000)
This includes nested types in the member list, even if there are no members of that type. Note that structs and classes have themselves as an "implicit struct" as the first member, so we skip implicit ones.

Differential Revision: http://reviews.llvm.org/D21705

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274628 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h
test/CodeGenCXX/debug-info-dup-fwd-decl.cpp
test/CodeGenCXX/debug-info-indirect-field-decl.cpp
test/CodeGenCXX/debug-info-ms-abi.cpp

index d51e1d978bbf43444f665106bce3ef632bd62298..661c888b07b9e9d914b3cde17655b4331c579f78 100644 (file)
@@ -1095,6 +1095,13 @@ void CGDebugInfo::CollectRecordNormalField(
   elements.push_back(FieldType);
 }
 
+void CGDebugInfo::CollectRecordNestedRecord(
+    const RecordDecl *RD, SmallVectorImpl<llvm::Metadata *> &elements) {
+  QualType Ty = CGM.getContext().getTypeDeclType(RD);
+  llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateMainFile());
+  elements.push_back(nestedType);
+}
+
 void CGDebugInfo::CollectRecordFields(
     const RecordDecl *record, llvm::DIFile *tunit,
     SmallVectorImpl<llvm::Metadata *> &elements,
@@ -1131,6 +1138,9 @@ void CGDebugInfo::CollectRecordFields(
 
         // Bump field number for next field.
         ++fieldNo;
+      } else if (const auto *nestedRec = dyn_cast<CXXRecordDecl>(I)) {
+        if (!nestedRec->isImplicit() && nestedRec->getDeclContext() == record)
+          CollectRecordNestedRecord(nestedRec, elements);
       }
   }
 }
@@ -3633,8 +3643,8 @@ void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) {
   if (CGM.getCodeGenOpts().getDebugInfo() < codegenoptions::LimitedDebugInfo)
     return;
   const NamespaceDecl *NSDecl = UD.getNominatedNamespace();
-  if (!NSDecl->isAnonymousNamespace() || 
-      CGM.getCodeGenOpts().DebugExplicitImport) { 
+  if (!NSDecl->isAnonymousNamespace() ||
+      CGM.getCodeGenOpts().DebugExplicitImport) {
     DBuilder.createImportedModule(
         getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())),
         getOrCreateNameSpace(NSDecl),
index 366dd81ac8128a0188b6310893b8aeeca49d537c..70c16462965f685247a0d3eb7ec0779eeb979106 100644 (file)
@@ -254,6 +254,8 @@ class CGDebugInfo {
                                 llvm::DIFile *F,
                                 SmallVectorImpl<llvm::Metadata *> &E,
                                 llvm::DIType *RecordTy, const RecordDecl *RD);
+  void CollectRecordNestedRecord(const RecordDecl *RD,
+                                 SmallVectorImpl<llvm::Metadata *> &E);
   void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
                            SmallVectorImpl<llvm::Metadata *> &E,
                            llvm::DICompositeType *RecordTy);
index f7a2cfe7bae6f4ac420158e7a6ba43844b700e2f..3b23ebf7dedc984f144e04b0b0046ff8e02c0e4e 100644 (file)
@@ -19,6 +19,6 @@ protected:
 
 Test t;
 
-// CHECK: !DIDerivedType(tag: DW_TAG_pointer_type
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "data"
+// CHECK: !DIDerivedType(tag: DW_TAG_pointer_type
 // CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "data"
index 70b233cac4dcb57fe9bd0b7af184c76993ea6cba..5642719a517a911629c427f638ac1c6cb4ee367f 100644 (file)
@@ -8,18 +8,18 @@ template <class T, int T::*ptr> class Foo {  };
 struct Bar {
   int i1;
   // CHECK: ![[INT:[0-9]+]] = !DIBasicType(name: "int"
-  // CHECK: !DIDerivedType(tag: DW_TAG_member, scope:
-  // CHECK-SAME:           line: [[@LINE+4]]
-  // CHECK-SAME:           baseType: ![[UNION:[0-9]+]]
-  // CHECK-SAME:           size: 32, align: 32, offset: 32
-  // CHECK: ![[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,{{.*}} identifier: "_ZTSN3BarUt_E")
+  // CHECK: ![[UNION:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_union_type,{{.*}} identifier: "_ZTSN3BarUt_E")
   union {
     // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i2",
-    // CHECK-SAME:           line: [[@LINE+5]]
+    // CHECK-SAME:           line: [[@LINE+9]]
     // CHECK-SAME:           baseType: ![[INT]]
     // CHECK-SAME:           size: 32, align: 32
     // CHECK-NOT:            offset:
     // CHECK-SAME:           ){{$}}
+    // CHECK: !DIDerivedType(tag: DW_TAG_member, scope:
+    // CHECK-SAME:           line: [[@LINE-8]]
+    // CHECK-SAME:           baseType: ![[UNION]]
+    // CHECK-SAME:           size: 32, align: 32, offset: 32
     int i2;
   };
 };
index a146ce94176e9176b3a6da7953c326e6c08f7919..2652128b39de3b4f8f74ef82d56c89a897c2fa00 100644 (file)
@@ -14,6 +14,9 @@ Foo::Nested n;
 // CHECK: ![[Foo:[^ ]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo",
 // CHECK-SAME: identifier: ".?AUFoo@@"
 
+// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Nested",
+// CHECK-SAME: identifier: ".?AUNested@Foo@@"
+
 // CHECK: !DISubprogram(name: "f",
 // CHECK-SAME: containingType: ![[Foo]], virtuality: DW_VIRTUALITY_virtual, virtualIndex: 0,
 // CHECK-SAME: flags: DIFlagPrototyped | DIFlagIntroducedVirtual,
@@ -25,6 +28,3 @@ Foo::Nested n;
 // CHECK: !DISubprogram(name: "h",
 // CHECK-SAME: containingType: ![[Foo]], virtuality: DW_VIRTUALITY_virtual, virtualIndex: 2,
 // CHECK-SAME: flags: DIFlagPrototyped | DIFlagIntroducedVirtual,
-
-// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Nested",
-// CHECK-SAME: identifier: ".?AUNested@Foo@@"