From dc4531e552af6c880a69d226d3666756198fbdc8 Mon Sep 17 00:00:00 2001 From: Amjad Aboud Date: Sat, 30 Apr 2016 01:44:38 +0000 Subject: [PATCH] Reverting 268055 as it caused PR27579. llvm-svn: 268151 --- clang/lib/CodeGen/CGDebugInfo.cpp | 41 ++++------------------ clang/lib/CodeGen/CGDebugInfo.h | 11 ------ clang/lib/CodeGen/CGDecl.cpp | 21 ++++------- .../test/CodeGenCXX/debug-info-anon-union-vars.cpp | 16 ++++----- clang/test/CodeGenCXX/debug-info-lb.cpp | 27 -------------- 5 files changed, 22 insertions(+), 94 deletions(-) delete mode 100644 clang/test/CodeGenCXX/debug-info-lb.cpp diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 69976d7..29f5971 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -814,18 +814,15 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty, llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty, llvm::DIFile *Unit) { - TypedefNameDecl *TD = Ty->getDecl(); // We don't set size information, but do specify where the typedef was // declared. - SourceLocation Loc = TD->getLocation(); - - llvm::DIScope *TDContext = getDeclarationLexicalScope(*TD, QualType(Ty, 0)); + SourceLocation Loc = Ty->getDecl()->getLocation(); // Typedefs are derived from some other type. return DBuilder.createTypedef( getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit), Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc), - TDContext); + getDeclContextDescriptor(Ty->getDecl())); } llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty, @@ -1460,23 +1457,6 @@ llvm::DIType *CGDebugInfo::getOrCreateStandaloneType(QualType D, return T; } -void CGDebugInfo::recordDeclarationLexicalScope(const Decl &D) { - assert(LexicalBlockMap.find(&D) == LexicalBlockMap.end() && - "D is already mapped to lexical block scope"); - if (!LexicalBlockStack.empty()) - LexicalBlockMap[&D] = LexicalBlockStack.back(); -} - -llvm::DIScope *CGDebugInfo::getDeclarationLexicalScope(const Decl &D, - QualType Ty) { - auto I = LexicalBlockMap.find(&D); - if (I != LexicalBlockMap.end()) { - RetainedTypes.push_back(Ty.getAsOpaquePtr()); - return I->second; - } - return getDeclContextDescriptor(cast(&D)); -} - void CGDebugInfo::completeType(const EnumDecl *ED) { if (DebugKind <= codegenoptions::DebugLineTablesOnly) return; @@ -2080,7 +2060,7 @@ llvm::DIType *CGDebugInfo::CreateEnumType(const EnumType *Ty) { // entered into the ReplaceMap: finalize() will replace the first // FwdDecl with the second and then replace the second with // complete type. - llvm::DIScope *EDContext = getDeclarationLexicalScope(*ED, QualType(Ty, 0)); + llvm::DIScope *EDContext = getDeclContextDescriptor(ED); llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation()); llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType( llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0)); @@ -2124,7 +2104,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) { llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation()); unsigned Line = getLineNumber(ED->getLocation()); - llvm::DIScope *EnumContext = getDeclarationLexicalScope(*ED, QualType(Ty, 0)); + llvm::DIScope *EnumContext = getDeclContextDescriptor(ED); llvm::DIType *ClassTy = ED->isFixed() ? getOrCreateType(ED->getIntegerType(), DefUnit) : nullptr; return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit, @@ -2385,7 +2365,7 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) { unsigned Line = getLineNumber(RD->getLocation()); StringRef RDName = getClassName(RD); - llvm::DIScope *RDContext = getDeclarationLexicalScope(*RD, QualType(Ty, 0)); + llvm::DIScope *RDContext = getDeclContextDescriptor(RD); // If we ended up creating the type during the context chain construction, // just return that. @@ -2556,15 +2536,8 @@ void CGDebugInfo::collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit, if (DC->isRecord()) DC = CGM.getContext().getTranslationUnitDecl(); - if (VD->isStaticLocal()) { - // Get context for static locals (that are technically globals) the same way - // we do for "local" locals -- by using current lexical block. - assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); - VDContext = LexicalBlockStack.back(); - } else { - llvm::DIScope *Mod = getParentModuleOrNull(VD); - VDContext = getContextDescriptor(cast(DC), Mod ? Mod : TheCU); - } + llvm::DIScope *Mod = getParentModuleOrNull(VD); + VDContext = getContextDescriptor(cast(DC), Mod ? Mod : TheCU); } llvm::DISubprogram * diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 6ec10d9..669ab9d 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -107,11 +107,6 @@ class CGDebugInfo { /// Keep track of our current nested lexical block. std::vector> LexicalBlockStack; - - /// Map of AST declaration to its lexical block scope. - llvm::DenseMap> - LexicalBlockMap; - llvm::DenseMap RegionMap; /// Keep track of LexicalBlockStack counter at the beginning of a /// function. This is used to pop unbalanced regions at the end of a @@ -374,12 +369,6 @@ public: /// Emit an Objective-C interface type standalone debug info. llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc); - /// Map AST declaration to its lexical block scope if available. - void recordDeclarationLexicalScope(const Decl &D); - - /// Get lexical scope of AST declaration. - llvm::DIScope *getDeclarationLexicalScope(const Decl &D, QualType Ty); - /// Emit standalone debug info for a type. llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc); diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index fd4a1dc..c39b980 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -87,7 +87,11 @@ void CodeGenFunction::EmitDecl(const Decl &D) { case Decl::UsingShadow: case Decl::ObjCTypeParam: llvm_unreachable("Declaration should not be in declstmts!"); - case Decl::Function: // void X(); + case Decl::Function: // void X(); + case Decl::Record: // struct/union/class X; + case Decl::Enum: // enum X; + case Decl::EnumConstant: // enum ? { X = ? } + case Decl::CXXRecord: // struct/union/class X; [C++] case Decl::StaticAssert: // static_assert(X, ""); [C++0x] case Decl::Label: // __label__ x; case Decl::Import: @@ -97,21 +101,13 @@ void CodeGenFunction::EmitDecl(const Decl &D) { // None of these decls require codegen support. return; - case Decl::Record: // struct/union/class X; - case Decl::Enum: // enum X; - case Decl::EnumConstant: // enum ? { X = ? } - case Decl::CXXRecord: // struct/union/class X; [C++] - if (CGDebugInfo *DI = getDebugInfo()) - DI->recordDeclarationLexicalScope(D); - return; - case Decl::NamespaceAlias: if (CGDebugInfo *DI = getDebugInfo()) - DI->EmitNamespaceAlias(cast(D)); + DI->EmitNamespaceAlias(cast(D)); return; case Decl::Using: // using X; [C++] if (CGDebugInfo *DI = getDebugInfo()) - DI->EmitUsingDecl(cast(D)); + DI->EmitUsingDecl(cast(D)); return; case Decl::UsingDirective: // using namespace X; [C++] if (CGDebugInfo *DI = getDebugInfo()) @@ -132,9 +128,6 @@ void CodeGenFunction::EmitDecl(const Decl &D) { const TypedefNameDecl &TD = cast(D); QualType Ty = TD.getUnderlyingType(); - if (CGDebugInfo *DI = getDebugInfo()) - DI->recordDeclarationLexicalScope(D); - if (Ty->isVariablyModifiedType()) EmitVariablyModifiedType(Ty); } diff --git a/clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp b/clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp index a85729b..b844d42 100644 --- a/clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp +++ b/clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp @@ -44,13 +44,8 @@ void instantiate(int x) { buildBytes(x); } -// CHECK: ![[UNION:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_union_type, -// CHECK-NOT: name: -// CHECK: elements -// CHECK: [[FILE:.*]] = !DIFile(filename: "{{.*}}debug-info-anon-union-vars.cpp", -// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i", scope: ![[UNION]], -// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "c", scope: ![[UNION]], -// CHECK: !DIGlobalVariable(name: "c",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true +// CHECK: !DIGlobalVariable(name: "c",{{.*}} file: [[FILE:.*]], line: 6,{{.*}} isLocal: true, isDefinition: true +// CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-anon-union-vars.cpp", // CHECK: !DIGlobalVariable(name: "d",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true // CHECK: !DIGlobalVariable(name: "a",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true // CHECK: !DIGlobalVariable(name: "b",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true @@ -60,4 +55,9 @@ void instantiate(int x) { // CHECK: !DILocalVariable(name: "c", {{.*}}, flags: DIFlagArtificial // CHECK: !DILocalVariable( // CHECK-NOT: name: -// CHECK: type: ![[UNION]] +// CHECK: type: ![[UNION:[0-9]+]] +// CHECK: ![[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type, +// CHECK-NOT: name: +// CHECK: elements +// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i", scope: ![[UNION]], +// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "c", scope: ![[UNION]], diff --git a/clang/test/CodeGenCXX/debug-info-lb.cpp b/clang/test/CodeGenCXX/debug-info-lb.cpp deleted file mode 100644 index a96d155..0000000 --- a/clang/test/CodeGenCXX/debug-info-lb.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s - -void foo() { - static int bar = 1; - { - struct X {}; - typedef char Y; - static int bar = 0; - // The following basic block is intended, in order to check the case where - // types "X", "Y" are defined in a different scope than where they are used. - // They should have the scope they are defined at as their parent scope. - { - X a; - Y b; - } - } -} - -// CHECK: !{{[0-9]+}} = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[LBScope:![0-9]+]], -// CHECK: [[LBScope]] = distinct !DILexicalBlock(scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 5) - -// CHECK: [[FuncScope:![0-9]+]] = distinct !DISubprogram(name: "foo", - -// CHECK: !{{[0-9]+}} = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: [[LBScope]], -// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[FuncScope]], file: !{{[0-9]+}}, line: 4 -// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[LBScope]], file: !{{[0-9]+}}, line: 8 - -- 2.7.4