]> granicus.if.org Git - clang/commitdiff
Module Debugging: Make sure that anonymous tag decls that define global
authorAdrian Prantl <aprantl@apple.com>
Tue, 19 Jan 2016 23:42:44 +0000 (23:42 +0000)
committerAdrian Prantl <aprantl@apple.com>
Tue, 19 Jan 2016 23:42:44 +0000 (23:42 +0000)
variables are visited.

This shouldn't encourage anyone to put global variables into clang modules.
rdar://problem/24199640

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

lib/CodeGen/ObjectFilePCHContainerOperations.cpp
test/Modules/ExtDebugInfo.cpp
test/Modules/Inputs/DebugCXX.h
test/Modules/ModuleDebugInfo.cpp

index 2c0c3ca8a90e23dffd2dce257ce7ecc8ca12598b..cd17832554d7faa7cee39dffb92be31626696a71 100644 (file)
@@ -59,10 +59,8 @@ class PCHContainerGenerator : public ASTConsumer {
   struct DebugTypeVisitor : public RecursiveASTVisitor<DebugTypeVisitor> {
     clang::CodeGen::CGDebugInfo &DI;
     ASTContext &Ctx;
-    bool SkipTagDecls;
-    DebugTypeVisitor(clang::CodeGen::CGDebugInfo &DI, ASTContext &Ctx,
-                     bool SkipTagDecls)
-        : DI(DI), Ctx(Ctx), SkipTagDecls(SkipTagDecls) {}
+    DebugTypeVisitor(clang::CodeGen::CGDebugInfo &DI, ASTContext &Ctx)
+        : DI(DI), Ctx(Ctx) {}
 
     /// Determine whether this type can be represented in DWARF.
     static bool CanRepresent(const Type *Ty) {
@@ -80,7 +78,8 @@ class PCHContainerGenerator : public ASTConsumer {
       // TagDecls may be deferred until after all decls have been merged and we
       // know the complete type. Pure forward declarations will be skipped, but
       // they don't need to be emitted into the module anyway.
-      if (SkipTagDecls && isa<TagDecl>(D))
+      if (auto *TD = dyn_cast<TagDecl>(D))
+        if (!TD->isCompleteDefinition())
           return true;
 
       QualType QualTy = Ctx.getTypeDeclType(D);
@@ -173,7 +172,7 @@ public:
     // Collect debug info for all decls in this group.
     for (auto *I : D)
       if (!I->isFromASTFile()) {
-        DebugTypeVisitor DTV(*Builder->getModuleDebugInfo(), *Ctx, true);
+        DebugTypeVisitor DTV(*Builder->getModuleDebugInfo(), *Ctx);
         DTV.TraverseDecl(I);
       }
     return true;
@@ -194,7 +193,7 @@ public:
     if (D->getName().empty())
       return;
 
-    DebugTypeVisitor DTV(*Builder->getModuleDebugInfo(), *Ctx, false);
+    DebugTypeVisitor DTV(*Builder->getModuleDebugInfo(), *Ctx);
     DTV.TraverseDecl(D);
     Builder->UpdateCompletedType(D);
   }
index b0bca88b89e4273c94e5ab4e0b9a0f6f7e2f3761..6c5bd559fc99430072ec6d6f3e982fc50d462884 100644 (file)
@@ -39,6 +39,10 @@ TypedefUnion tdu;
 TypedefEnum tde;
 TypedefStruct tds;
 
+void foo() {
+  GlobalStruct.i = GlobalUnion.i = GlobalEnum;
+}
+
 // CHECK: ![[NS:.*]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]],
 // CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX
 
index 285e094171c3d710a72e46c5caa673b5f6153d3a..cd2b7a67498cd999ccec6e946e9dbc05f5fb73b6 100644 (file)
@@ -62,3 +62,7 @@ struct PureForwardDecl;
 typedef union { int i; } TypedefUnion;
 typedef enum { e0 = 0 } TypedefEnum;
 typedef struct { int i; } TypedefStruct;
+
+union { int i; } GlobalUnion;
+struct { int i; } GlobalStruct;
+enum { e5 = 5 } GlobalEnum;
index c1248fd4d8eebb7bcc7de1ed39f3415b6aa4c23a..1f574568b6fca426e767ced1b8ab57c02feefa2e 100644 (file)
 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX4EnumE")
 // CHECK: !DINamespace(name: "DebugCXX"
 
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME-NOT:         name:
+
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME-NOT:         name:
+
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
 // CHECK-SAME-NOT:         name:
 // CHECK-SAME:             identifier: "_ZTS11TypedefEnum")
 
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME-NOT:         name:
+// CHECK: !DIEnumerator(name: "e5", value: 5)
+
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Struct"
 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX6StructE")
 
 // CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "B",
 // no mangled name here yet.
 
+// CHECK: !DICompositeType(tag: DW_TAG_union_type,
+// CHECK-SAME-NOT:         name:
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK-SAME-NOT:         name:
+
 // CHECK-NEG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "PureForwardDecl"