From 0ebf1bb150b36128098a9f269d708361c4feebfa Mon Sep 17 00:00:00 2001 From: Yunzhong Gao Date: Fri, 30 Aug 2013 08:53:09 +0000 Subject: [PATCH] Revert r189649 because it was breaking sanitizer bots. llvm-svn: 189660 --- clang/lib/CodeGen/CGDebugInfo.cpp | 58 +++++++++---------- clang/lib/CodeGen/CGDebugInfo.h | 6 +- clang/lib/CodeGen/CGExpr.cpp | 12 +++- clang/lib/CodeGen/CodeGenFunction.cpp | 25 ++------ clang/lib/CodeGen/CodeGenFunction.h | 3 +- clang/test/CodeGen/debug-info-line5.cpp | 18 ------ clang/test/CodeGen/debug-info-line5.h | 2 - clang/test/CodeGen/debug-info-scope.c | 11 +--- .../test/CodeGenCXX/debug-info-namespace.cpp | 12 ---- 9 files changed, 48 insertions(+), 99 deletions(-) delete mode 100644 clang/test/CodeGen/debug-info-line5.cpp delete mode 100644 clang/test/CodeGen/debug-info-line5.h diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 89e205902550..fe503982be3c 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -3142,31 +3142,14 @@ CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) { } /// EmitGlobalVariable - Emit information about a global variable. -/// \param VarOrInit either the global variable itself or the initializer -/// \param D the global declaration -void CGDebugInfo::EmitGlobalVariable(llvm::Value *VarOrInit, +void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, const VarDecl *D) { assert(DebugKind >= CodeGenOptions::LimitedDebugInfo); // Create global variable debug descriptor. llvm::DIFile Unit = getOrCreateFile(D->getLocation()); unsigned LineNo = getLineNumber(D->getLocation()); - StringRef DeclName = D->getName(); - StringRef LinkageName; - bool IsLocalToUnit = true; - // For deferred global variables, the current source location is usually - // where they are being referenced. Do not change the current source location - // to the place where they are declared, lest we get a bogus line table. - // FIXME: maybe we do not need to set the source location here at all. - if (llvm::GlobalVariable *Var = dyn_cast(VarOrInit)) { - setLocation(D->getLocation()); - IsLocalToUnit = Var->hasInternalLinkage(); - if (D->getDeclContext() && !isa(D->getDeclContext()) - && !isa(D->getDeclContext())) - LinkageName = Var->getName(); - if (LinkageName == DeclName) - LinkageName = StringRef(); - } + setLocation(D->getLocation()); QualType T = D->getType(); if (T->isIncompleteArrayType()) { @@ -3178,11 +3161,18 @@ void CGDebugInfo::EmitGlobalVariable(llvm::Value *VarOrInit, T = CGM.getContext().getConstantArrayType(ET, ConstVal, ArrayType::Normal, 0); } + StringRef DeclName = D->getName(); + StringRef LinkageName; + if (D->getDeclContext() && !isa(D->getDeclContext()) + && !isa(D->getDeclContext())) + LinkageName = Var->getName(); + if (LinkageName == DeclName) + LinkageName = StringRef(); llvm::DIDescriptor DContext = getContextDescriptor(dyn_cast(D->getDeclContext())); llvm::DIGlobalVariable GV = DBuilder.createStaticVariable( DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit), - IsLocalToUnit, VarOrInit, + Var->hasInternalLinkage(), Var, getOrCreateStaticDataMemberDeclarationOrNull(D)); DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(GV))); } @@ -3213,16 +3203,26 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, Var->hasInternalLinkage(), Var); } -/// EmitEnumConstant - Emit debug info for an enumerator constant -void CGDebugInfo::EmitEnumConstant(const EnumConstantDecl *ECD) -{ +/// EmitGlobalVariable - Emit global variable's debug info. +void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, + llvm::Constant *Init) { assert(DebugKind >= CodeGenOptions::LimitedDebugInfo); - llvm::DIFile Unit = getOrCreateFile(ECD->getLocation()); - llvm::DIType Ty = getOrCreateType(ECD->getType(), Unit); - - const EnumDecl *ED = cast(ECD->getDeclContext()); - assert(isa(ED->getTypeForDecl()) && "Enum without EnumType?"); - Ty = getOrCreateType(QualType(ED->getTypeForDecl(), 0), Unit); + // Create the descriptor for the variable. + llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); + StringRef Name = VD->getName(); + llvm::DIType Ty = getOrCreateType(VD->getType(), Unit); + if (const EnumConstantDecl *ECD = dyn_cast(VD)) { + const EnumDecl *ED = cast(ECD->getDeclContext()); + assert(isa(ED->getTypeForDecl()) && "Enum without EnumType?"); + Ty = getOrCreateType(QualType(ED->getTypeForDecl(), 0), Unit); + } + // Do not use DIGlobalVariable for enums. + if (Ty.getTag() == llvm::dwarf::DW_TAG_enumeration_type) + return; + llvm::DIGlobalVariable GV = DBuilder.createStaticVariable( + Unit, Name, Name, Unit, getLineNumber(VD->getLocation()), Ty, true, Init, + getOrCreateStaticDataMemberDeclarationOrNull(cast(VD))); + DeclCache.insert(std::make_pair(VD->getCanonicalDecl(), llvm::WeakVH(GV))); } llvm::DIScope CGDebugInfo::getCurrentContextDescriptor(const Decl *D) { diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 9642a83dfddc..a8ba14b8b3fe 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -264,13 +264,13 @@ public: CGBuilderTy &Builder); /// EmitGlobalVariable - Emit information about a global variable. - void EmitGlobalVariable(llvm::Value *VarOrInit, const VarDecl *Decl); + void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); /// EmitGlobalVariable - Emit information about an objective-c interface. void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); - /// EmitEnumConstant - Emit information about an enumerator constant - void EmitEnumConstant(const EnumConstantDecl *ECD); + /// EmitGlobalVariable - Emit global variable's debug info. + void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init); /// \brief - Emit C++ using directive. void EmitUsingDirective(const UsingDirectiveDecl &UD); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 31da6df1efa5..12aa0a2b7c43 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -967,9 +967,15 @@ CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) { // Emit as a constant. llvm::Constant *C = CGM.EmitConstantValue(result.Val, resultType, this); - // Make sure we emit a debug reference to the global variable or - // enumerator constant. - EmitValueDeclDbgValue(value, C); + // Make sure we emit a debug reference to the global variable. + // This should probably fire even for + if (isa(value)) { + if (!getContext().DeclMustBeEmitted(cast(value))) + EmitDeclRefExprDbgValue(refExpr, C); + } else { + assert(isa(value)); + EmitDeclRefExprDbgValue(refExpr, C); + } // If we emitted a reference constant, we need to dereference that. if (resultIsReference) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index c0357238d21c..20352f9f685e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1376,27 +1376,12 @@ llvm::Value* CodeGenFunction::EmitVAListRef(const Expr* E) { return EmitLValue(E).getAddress(); } -void CodeGenFunction::EmitValueDeclDbgValue(const ValueDecl *Val, - llvm::Constant *Init) { +void CodeGenFunction::EmitDeclRefExprDbgValue(const DeclRefExpr *E, + llvm::Constant *Init) { assert (Init && "Invalid DeclRefExpr initializer!"); - CGDebugInfo *Dbg = getDebugInfo(); - if (!Dbg || - CGM.getCodeGenOpts().getDebugInfo() < CodeGenOptions::LimitedDebugInfo) - return; - - // Make sure we emit a debug reference to the global variable. - if (const VarDecl *VD = dyn_cast(Val)) { - // Do not duplicate DIE entry for local variables; they are not deferred - // like global variables are. - if (VD->isFileVarDecl() && !getLangOpts().EmitAllDecls && - !getContext().DeclMustBeEmitted(Val)) - Dbg->EmitGlobalVariable(Init, VD); - - // Make sure we emit a debug reference to an enumerator constant. - } else { - assert(isa(Val)); - Dbg->EmitEnumConstant(dyn_cast(Val)); - } + if (CGDebugInfo *Dbg = getDebugInfo()) + if (CGM.getCodeGenOpts().getDebugInfo() >= CodeGenOptions::LimitedDebugInfo) + Dbg->EmitGlobalVariable(E->getDecl(), Init); } CodeGenFunction::PeepholeProtection diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 9913c68fcf87..20c0b82553ca 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -2047,8 +2047,7 @@ public: LValue EmitStmtExprLValue(const StmtExpr *E); LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); - void EmitValueDeclDbgValue(const ValueDecl *Val, llvm::Constant *Init); - + void EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::Constant *Init); //===--------------------------------------------------------------------===// // Scalar Expression Emission diff --git a/clang/test/CodeGen/debug-info-line5.cpp b/clang/test/CodeGen/debug-info-line5.cpp deleted file mode 100644 index 0f1042738f46..000000000000 --- a/clang/test/CodeGen/debug-info-line5.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %clang %s -g -gcolumn-info -S -emit-llvm -o - | FileCheck %s -// Line table entries should reference this cpp file, not the header - -#include "debug-info-line5.h" - -int result; -int foo(unsigned); - -int main() -{ - while ( 1 ) - { - result = foo(Marker); - } - return result; -} - -// CHECK: !{{[0-9]*}} = metadata !{i32 {{[0-9]*}}, i32 {{[0-9]*}}, null, metadata !"Marker", {{.*}} ; [ DW_TAG_variable ] [Marker] diff --git a/clang/test/CodeGen/debug-info-line5.h b/clang/test/CodeGen/debug-info-line5.h deleted file mode 100644 index 690c9b765081..000000000000 --- a/clang/test/CodeGen/debug-info-line5.h +++ /dev/null @@ -1,2 +0,0 @@ -// Declaration of "Marker" -const unsigned Marker = 0xFF999999; diff --git a/clang/test/CodeGen/debug-info-scope.c b/clang/test/CodeGen/debug-info-scope.c index 05cd299ff366..9decaeafd50e 100644 --- a/clang/test/CodeGen/debug-info-scope.c +++ b/clang/test/CodeGen/debug-info-scope.c @@ -1,16 +1,7 @@ // RUN: %clang_cc1 -g -emit-llvm < %s | FileCheck %s - -// Make sure that the debug info of the local variable d does not shadow -// the global variable d -// CHECK: [ DW_TAG_variable ] [d] [line 6] [def] -const int d = 100; - // Two variables with same name in separate scope. // Radar 8330217. int main() { -// CHECK-NOT: [ DW_TAG_variable ] [d] [line 13] -// CHECK: [ DW_TAG_auto_variable ] [d] [line 13] - const int d = 4; int j = 0; int k = 0; // CHECK: DW_TAG_auto_variable ] [i] @@ -21,5 +12,5 @@ int main() { // CHECK-NEXT: DW_TAG_lexical_block for (int i = 0; i < 10; i++) k++; - return d; // make a reference to d so that its debug info gets included + return 0; } diff --git a/clang/test/CodeGenCXX/debug-info-namespace.cpp b/clang/test/CodeGenCXX/debug-info-namespace.cpp index 17352e881824..ec7e69a0cc7b 100644 --- a/clang/test/CodeGenCXX/debug-info-namespace.cpp +++ b/clang/test/CodeGenCXX/debug-info-namespace.cpp @@ -39,16 +39,6 @@ int func(bool b) { // This should work even if 'i' and 'func' were declarations & not definitions, // but it doesn't yet. -namespace C -{ - const int j = 32; -} - -int func2() -{ - return C::j; -} - // CHECK: [[CU:![0-9]*]] = {{.*}}[[MODULES:![0-9]*]], metadata !""} ; [ DW_TAG_compile_unit ] // CHECK: [[FILE:![0-9]*]] {{.*}}debug-info-namespace.cpp" // CHECK: [[FOO:![0-9]*]] {{.*}} ; [ DW_TAG_structure_type ] [foo] [line 5, size 0, align 0, offset 0] [decl] [from ] @@ -60,8 +50,6 @@ int func2() // CHECK: [[FUNC:![0-9]*]] {{.*}} ; [ DW_TAG_subprogram ] {{.*}} [def] [func] // CHECK: [[FILE2]]} ; [ DW_TAG_file_type ] [{{.*}}foo.cpp] // CHECK: [[I:![0-9]*]] = {{.*}}, metadata [[NS]], metadata !"i", {{.*}} ; [ DW_TAG_variable ] [i] -// CHECK: [[VAR:![0-9]*]] = {{.*}}, metadata [[SPACE:![0-9]*]], metadata !"j", {{.*}} ; [ DW_TAG_variable ] [j] -// CHECK: [[SPACE]] = {{.*}}, metadata !"C", {{.*}} ; [ DW_TAG_namespace ] [C] // CHECK: [[MODULES]] = metadata !{metadata [[M1:![0-9]*]], metadata [[M2:![0-9]*]], metadata [[M3:![0-9]*]], metadata [[M4:![0-9]*]], metadata [[M5:![0-9]*]], metadata [[M6:![0-9]*]], metadata [[M7:![0-9]*]], metadata [[M8:![0-9]*]], metadata [[M9:![0-9]*]], metadata [[M10:![0-9]*]], metadata [[M11:![0-9]*]], metadata [[M12:![0-9]*]]} // CHECK: [[M1]] = metadata !{i32 {{[0-9]*}}, metadata [[CTXT]], metadata [[NS]], i32 11} ; [ DW_TAG_imported_module ] // CHECK: [[M2]] = metadata !{i32 {{[0-9]*}}, metadata [[CU]], metadata [[CTXT]], i32 {{[0-9]*}}} ; [ DW_TAG_imported_module ]