summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2011-10-12 18:39:35 +0000
committerEric Christopher <echristo@apple.com>2011-10-12 18:39:35 +0000
commit28e06354b5d4dd539be6781e388ff27c0dffd807 (patch)
tree6e224a320ad39dcab3b12a05e16bd4a6c97d162e
parentd596c4d3f8931f4d479e965bf46d0e7edad85570 (diff)
downloadclang-28e06354b5d4dd539be6781e388ff27c0dffd807.tar.gz
Revert file/scope handling patches. gdb testing revealed a couple of bugs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141796 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGBlocks.cpp2
-rw-r--r--lib/CodeGen/CGClass.cpp2
-rw-r--r--lib/CodeGen/CGDebugInfo.cpp156
-rw-r--r--lib/CodeGen/CGDebugInfo.h18
-rw-r--r--lib/CodeGen/CGExpr.cpp6
-rw-r--r--lib/CodeGen/CGObjC.cpp24
-rw-r--r--lib/CodeGen/CGStmt.cpp43
-rw-r--r--lib/CodeGen/CodeGenModule.cpp4
-rw-r--r--test/CodeGen/debug-info-line.c14
9 files changed, 149 insertions, 120 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
index 9694953766..5cbaff908c 100644
--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -996,7 +996,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
for (BlockDecl::capture_const_iterator ci = blockDecl->capture_begin(),
ce = blockDecl->capture_end(); ci != ce; ++ci) {
const VarDecl *variable = ci->getVariable();
- DI->EmitLocation(Builder, variable->getLocation());
+ DI->setLocation(variable->getLocation());
const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
if (capture.isConstant()) {
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp
index c28ecc05de..2ddb5025b1 100644
--- a/lib/CodeGen/CGClass.cpp
+++ b/lib/CodeGen/CGClass.cpp
@@ -693,7 +693,7 @@ void CodeGenFunction::EmitConstructorBody(FunctionArgList &Args) {
// delegation optimization.
if (CtorType == Ctor_Complete && IsConstructorDelegationValid(Ctor)) {
if (CGDebugInfo *DI = getDebugInfo())
- DI->EmitLocation(Builder, Ctor->getLocEnd());
+ DI->EmitLocation(Builder);
EmitDelegateCXXConstructorCall(Ctor, Ctor_Base, Args);
return;
}
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index 120486dbe2..0902b94b5a 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -55,37 +55,6 @@ void CGDebugInfo::setLocation(SourceLocation Loc) {
if (!Loc.isValid()) return;
CurLoc = CGM.getContext().getSourceManager().getExpansionLoc(Loc);
-
- // If we've changed files in the middle of a lexical scope go ahead
- // and create a new lexical scope with file node if it's different
- // from the one in the scope.
- if (LexicalBlockStack.empty()) return;
-
- SourceManager &SM = CGM.getContext().getSourceManager();
- PresumedLoc PCLoc = SM.getPresumedLoc(CurLoc);
- PresumedLoc PPLoc = SM.getPresumedLoc(PrevLoc);
-
- if (PCLoc.isInvalid() || PPLoc.isInvalid() ||
- !strcmp(PPLoc.getFilename(), PCLoc.getFilename()))
- return;
-
- llvm::MDNode *LB = LexicalBlockStack.back();
- llvm::DIScope Scope = llvm::DIScope(LB);
- if (Scope.isLexicalBlockFile()) {
- llvm::DILexicalBlockFile LBF = llvm::DILexicalBlockFile(LB);
- llvm::DIDescriptor D
- = DBuilder.createLexicalBlockFile(LBF.getScope(),
- getOrCreateFile(CurLoc));
- llvm::MDNode *N = D;
- LexicalBlockStack.pop_back();
- LexicalBlockStack.push_back(N);
- } else {
- llvm::DIDescriptor D
- = DBuilder.createLexicalBlockFile(Scope, getOrCreateFile(CurLoc));
- llvm::MDNode *N = D;
- LexicalBlockStack.pop_back();
- LexicalBlockStack.push_back(N);
- }
}
/// getContextDescriptor - Get context info for the decl.
@@ -236,7 +205,7 @@ llvm::DIFile CGDebugInfo::getOrCreateMainFile() {
/// getLineNumber - Get line number for the location. If location is invalid
/// then use current location.
unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
- assert (Loc.isValid() || CurLoc.isValid() && "Invalid current location!");
+ assert (CurLoc.isValid() && "Invalid current location!");
SourceManager &SM = CGM.getContext().getSourceManager();
PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc);
return PLoc.isValid()? PLoc.getLine() : 0;
@@ -245,7 +214,7 @@ unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
/// getColumnNumber - Get column number for the location. If location is
/// invalid then use current location.
unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc) {
- assert (Loc.isValid() || CurLoc.isValid() && "Invalid current location!");
+ assert (CurLoc.isValid() && "Invalid current location!");
SourceManager &SM = CGM.getContext().getSourceManager();
PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc);
return PLoc.isValid()? PLoc.getColumn() : 0;
@@ -1803,24 +1772,79 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType,
llvm::MDNode *SPN = SP;
LexicalBlockStack.push_back(SPN);
RegionMap[D] = llvm::WeakVH(SP);
+
+ // Clear stack used to keep track of #line directives.
+ LineDirectiveFiles.clear();
+}
+
+// UpdateLineDirectiveRegion - Update region stack only if #line directive
+// has introduced scope change.
+void CGDebugInfo::UpdateLineDirectiveRegion(CGBuilderTy &Builder) {
+ if (CurLoc.isInvalid() || CurLoc.isMacroID() ||
+ PrevLoc.isInvalid() || PrevLoc.isMacroID())
+ return;
+ SourceManager &SM = CGM.getContext().getSourceManager();
+ PresumedLoc PCLoc = SM.getPresumedLoc(CurLoc);
+ PresumedLoc PPLoc = SM.getPresumedLoc(PrevLoc);
+
+ if (PCLoc.isInvalid() || PPLoc.isInvalid() ||
+ !strcmp(PPLoc.getFilename(), PCLoc.getFilename()))
+ return;
+
+ // If #line directive stack is empty then we are entering a new scope.
+ if (LineDirectiveFiles.empty()) {
+ EmitLexicalBlockStart(Builder);
+ LineDirectiveFiles.push_back(PCLoc.getFilename());
+ return;
+ }
+
+ assert (LexicalBlockStack.size() >= LineDirectiveFiles.size()
+ && "error handling #line regions!");
+
+ bool SeenThisFile = false;
+ // Chek if current file is already seen earlier.
+ for(std::vector<const char *>::iterator I = LineDirectiveFiles.begin(),
+ E = LineDirectiveFiles.end(); I != E; ++I)
+ if (!strcmp(PCLoc.getFilename(), *I)) {
+ SeenThisFile = true;
+ break;
+ }
+
+ // If #line for this file is seen earlier then pop out #line regions.
+ if (SeenThisFile) {
+ while (!LineDirectiveFiles.empty()) {
+ const char *LastFile = LineDirectiveFiles.back();
+ LexicalBlockStack.pop_back();
+ LineDirectiveFiles.pop_back();
+ if (!strcmp(PPLoc.getFilename(), LastFile))
+ break;
+ }
+ return;
+ }
+
+ // .. otherwise insert new #line region.
+ EmitLexicalBlockStart(Builder);
+ LineDirectiveFiles.push_back(PCLoc.getFilename());
+
+ return;
}
/// EmitLocation - Emit metadata to indicate a change in line/column
/// information in the source file.
-void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) {
-
- // Update our current location
- setLocation(Loc);
-
+void CGDebugInfo::EmitLocation(CGBuilderTy &Builder) {
if (CurLoc.isInvalid() || CurLoc.isMacroID()) return;
// Don't bother if things are the same as last time.
SourceManager &SM = CGM.getContext().getSourceManager();
- if (CurLoc == PrevLoc ||
+ if (CurLoc == PrevLoc ||
SM.getExpansionLoc(CurLoc) == SM.getExpansionLoc(PrevLoc))
// New Builder may not be in sync with CGDebugInfo.
if (!Builder.getCurrentDebugLocation().isUnknown())
return;
+
+ // The file may have had a line directive change. Process any of
+ // those before updating the state.
+ UpdateLineDirectiveRegion(Builder);
// Update last state.
PrevLoc = CurLoc;
@@ -1831,42 +1855,27 @@ void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) {
Scope));
}
-/// CreateLexicalBlock - Creates a new lexical block node and pushes it on
-/// the stack.
-void CGDebugInfo::CreateLexicalBlock(SourceLocation Loc) {
+/// EmitLexicalBlockStart - Constructs the debug code for entering a declarative
+/// region - beginning of a DW_TAG_lexical_block.
+void CGDebugInfo::EmitLexicalBlockStart(CGBuilderTy &Builder) {
llvm::DIDescriptor D =
- DBuilder.createLexicalBlock(LexicalBlockStack.empty() ?
- llvm::DIDescriptor() :
- llvm::DIDescriptor(LexicalBlockStack.back()),
- getOrCreateFile(CurLoc),
- getLineNumber(CurLoc),
- getColumnNumber(CurLoc));
+ DBuilder.createLexicalBlock(LexicalBlockStack.empty() ?
+ llvm::DIDescriptor() :
+ llvm::DIDescriptor(LexicalBlockStack.back()),
+ getOrCreateFile(CurLoc),
+ getLineNumber(CurLoc),
+ getColumnNumber(CurLoc));
llvm::MDNode *DN = D;
LexicalBlockStack.push_back(DN);
}
-/// EmitLexicalBlockStart - Constructs the debug code for entering a declarative
-/// region - beginning of a DW_TAG_lexical_block.
-void CGDebugInfo::EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc) {
- // Set our current location.
- setLocation(Loc);
-
- // Create a new lexical block and push it on the stack.
- CreateLexicalBlock(CurLoc);
-
- // Emit a line table change for the current location inside the new scope.
- Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(getLineNumber(CurLoc),
- getColumnNumber(CurLoc),
- LexicalBlockStack.back()));
-}
-
/// EmitLexicalBlockEnd - Constructs the debug code for exiting a declarative
/// region - end of a DW_TAG_lexical_block.
-void CGDebugInfo::EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc) {
+void CGDebugInfo::EmitLexicalBlockEnd(CGBuilderTy &Builder) {
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
- // Provide an entry in the line table for the end of the block.
- EmitLocation(Builder, Loc);
+ // Provide a region stop point.
+ EmitLocation(Builder);
LexicalBlockStack.pop_back();
}
@@ -1879,7 +1888,7 @@ void CGDebugInfo::EmitFunctionEnd(CGBuilderTy &Builder) {
// Pop all regions for this function.
while (LexicalBlockStack.size() != RCount)
- EmitLexicalBlockEnd(Builder, CurLoc);
+ EmitLexicalBlockEnd(Builder);
FnBeginRegionCount.pop_back();
}
@@ -2018,9 +2027,9 @@ void CGDebugInfo::EmitDeclare(const VarDecl *VD, unsigned Tag,
addr, ArgNo);
// Insert an llvm.dbg.declare into the current block.
- // Insert an llvm.dbg.declare into the current block.
llvm::Instruction *Call =
DBuilder.insertDeclare(Storage, D, Builder.GetInsertBlock());
+
Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope));
return;
}
@@ -2033,6 +2042,7 @@ void CGDebugInfo::EmitDeclare(const VarDecl *VD, unsigned Tag,
// Insert an llvm.dbg.declare into the current block.
llvm::Instruction *Call =
DBuilder.insertDeclare(Storage, D, Builder.GetInsertBlock());
+
Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope));
return;
}
@@ -2063,6 +2073,7 @@ void CGDebugInfo::EmitDeclare(const VarDecl *VD, unsigned Tag,
// Insert an llvm.dbg.declare into the current block.
llvm::Instruction *Call =
DBuilder.insertDeclare(Storage, D, Builder.GetInsertBlock());
+
Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope));
}
}
@@ -2127,10 +2138,11 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
llvm::DIDescriptor(LexicalBlockStack.back()),
VD->getName(), Unit, Line, Ty, addr);
// Insert an llvm.dbg.declare into the current block.
- llvm::Instruction *Call =
+ llvm::Instruction *Call =
DBuilder.insertDeclare(Storage, D, Builder.GetInsertPoint());
- Call->setDebugLoc(llvm::DebugLoc::get(Line, Column,
- LexicalBlockStack.back()));
+
+ llvm::MDNode *Scope = LexicalBlockStack.back();
+ Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope));
}
/// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
@@ -2303,8 +2315,6 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
llvm::DIFile Unit = getOrCreateFile(D->getLocation());
unsigned LineNo = getLineNumber(D->getLocation());
- setLocation(D->getLocation());
-
QualType T = D->getType();
if (T->isIncompleteArrayType()) {
diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h
index a4533a83d5..e6c701a9a8 100644
--- a/lib/CodeGen/CGDebugInfo.h
+++ b/lib/CodeGen/CGDebugInfo.h
@@ -64,6 +64,10 @@ class CGDebugInfo {
// the end of a function.
std::vector<unsigned> FnBeginRegionCount;
+ /// LineDirectiveFiles - This stack is used to keep track of
+ /// scopes introduced by #line directives.
+ std::vector<const char *> LineDirectiveFiles;
+
/// DebugInfoNames - This is a storage for names that are
/// constructed on demand. For example, C++ destructors, C++ operators etc..
llvm::BumpPtrAllocator DebugInfoNames;
@@ -147,10 +151,10 @@ class CGDebugInfo {
llvm::DIFile F,
SmallVectorImpl<llvm::Value *> &EltTys);
- // CreateLexicalBlock - Create a new lexical block node and push it on
- // the stack.
- void CreateLexicalBlock(SourceLocation Loc);
-
+ // UpdateLineDirectiveRegion - Update region stack only if #line directive
+ // has introduced scope change.
+ void UpdateLineDirectiveRegion(CGBuilderTy &Builder);
+
public:
CGDebugInfo(CodeGenModule &CGM);
~CGDebugInfo();
@@ -162,7 +166,7 @@ public:
/// EmitLocation - Emit metadata to indicate a change in line/column
/// information in the source file.
- void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc);
+ void EmitLocation(CGBuilderTy &Builder);
/// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
/// start of a new function.
@@ -178,11 +182,11 @@ public:
/// EmitLexicalBlockStart - Emit metadata to indicate the beginning of a
/// new lexical block and push the block onto the stack.
- void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
+ void EmitLexicalBlockStart(CGBuilderTy &Builder);
/// EmitLexicalBlockEnd - Emit metadata to indicate the end of a new lexical
/// block and pop the current block.
- void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
+ void EmitLexicalBlockEnd(CGBuilderTy &Builder);
/// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
/// variable declaration.
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index ad27506d56..329dc5aa97 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -2180,8 +2180,10 @@ LValue CodeGenFunction::EmitMaterializeTemporaryExpr(
RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
ReturnValueSlot ReturnValue) {
- if (CGDebugInfo *DI = getDebugInfo())
- DI->EmitLocation(Builder, E->getLocStart());
+ if (CGDebugInfo *DI = getDebugInfo()) {
+ DI->setLocation(E->getLocStart());
+ DI->EmitLocation(Builder);
+ }
// Builtins never have block type.
if (E->getCallee()->getType()->isBlockPointerType())
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index 51f20534d1..344c1ee180 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -1208,8 +1208,10 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
}
CGDebugInfo *DI = getDebugInfo();
- if (DI)
- DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin());
+ if (DI) {
+ DI->setLocation(S.getSourceRange().getBegin());
+ DI->EmitLexicalBlockStart(Builder);
+ }
// The local variable comes into scope immediately.
AutoVarEmission variable = AutoVarEmission::invalid();
@@ -1463,8 +1465,10 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
EmitStoreThroughLValue(RValue::get(null), elementLValue);
}
- if (DI)
- DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd());
+ if (DI) {
+ DI->setLocation(S.getSourceRange().getEnd());
+ DI->EmitLexicalBlockEnd(Builder);
+ }
// Leave the cleanup we entered in ARC.
if (getLangOptions().ObjCAutoRefCount)
@@ -2500,8 +2504,10 @@ void CodeGenFunction::EmitObjCAutoreleasePoolStmt(
const CompoundStmt &S = cast<CompoundStmt>(*subStmt);
CGDebugInfo *DI = getDebugInfo();
- if (DI)
- DI->EmitLexicalBlockStart(Builder, S.getLBracLoc());
+ if (DI) {
+ DI->setLocation(S.getLBracLoc());
+ DI->EmitLexicalBlockStart(Builder);
+ }
// Keep track of the current cleanup stack depth.
RunCleanupsScope Scope(*this);
@@ -2517,8 +2523,10 @@ void CodeGenFunction::EmitObjCAutoreleasePoolStmt(
E = S.body_end(); I != E; ++I)
EmitStmt(*I);
- if (DI)
- DI->EmitLexicalBlockEnd(Builder, S.getRBracLoc());
+ if (DI) {
+ DI->setLocation(S.getRBracLoc());
+ DI->EmitLexicalBlockEnd(Builder);
+ }
}
/// EmitExtendGCLifetime - Given a pointer to an Objective-C object,
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index c56931bbc6..06a045f69b 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -31,12 +31,11 @@ using namespace CodeGen;
void CodeGenFunction::EmitStopPoint(const Stmt *S) {
if (CGDebugInfo *DI = getDebugInfo()) {
- SourceLocation Loc;
if (isa<DeclStmt>(S))
- Loc = S->getLocEnd();
+ DI->setLocation(S->getLocEnd());
else
- Loc = S->getLocStart();
- DI->EmitLocation(Builder, Loc);
+ DI->setLocation(S->getLocStart());
+ DI->EmitLocation(Builder);
}
}
@@ -191,8 +190,10 @@ RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
"LLVM IR generation of compound statement ('{}')");
CGDebugInfo *DI = getDebugInfo();
- if (DI)
- DI->EmitLexicalBlockStart(Builder, S.getLBracLoc());
+ if (DI) {
+ DI->setLocation(S.getLBracLoc());
+ DI->EmitLexicalBlockStart(Builder);
+ }
// Keep track of the current cleanup stack depth.
RunCleanupsScope Scope(*this);
@@ -201,8 +202,10 @@ RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
E = S.body_end()-GetLast; I != E; ++I)
EmitStmt(*I);
- if (DI)
- DI->EmitLexicalBlockEnd(Builder, S.getRBracLoc());
+ if (DI) {
+ DI->setLocation(S.getRBracLoc());
+ DI->EmitLexicalBlockEnd(Builder);
+ }
RValue RV;
if (!GetLast)
@@ -567,8 +570,10 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S) {
RunCleanupsScope ForScope(*this);
CGDebugInfo *DI = getDebugInfo();
- if (DI)
- DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin());
+ if (DI) {
+ DI->setLocation(S.getSourceRange().getBegin());
+ DI->EmitLexicalBlockStart(Builder);
+ }
// Evaluate the first part before the loop.
if (S.getInit())
@@ -647,8 +652,10 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S) {
ForScope.ForceCleanup();
- if (DI)
- DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd());
+ if (DI) {
+ DI->setLocation(S.getSourceRange().getEnd());
+ DI->EmitLexicalBlockEnd(Builder);
+ }
// Emit the fall-through block.
EmitBlock(LoopExit.getBlock(), true);
@@ -660,8 +667,10 @@ void CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S) {
RunCleanupsScope ForScope(*this);
CGDebugInfo *DI = getDebugInfo();
- if (DI)
- DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin());
+ if (DI) {
+ DI->setLocation(S.getSourceRange().getBegin());
+ DI->EmitLexicalBlockStart(Builder);
+ }
// Evaluate the first pieces before the loop.
EmitStmt(S.getRangeStmt());
@@ -717,8 +726,10 @@ void CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S) {
ForScope.ForceCleanup();
- if (DI)
- DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd());
+ if (DI) {
+ DI->setLocation(S.getSourceRange().getEnd());
+ DI->EmitLexicalBlockEnd(Builder);
+ }
// Emit the fall-through block.
EmitBlock(LoopExit.getBlock(), true);
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 924ec8448e..aab513fdce 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1392,8 +1392,10 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
EmitCXXGlobalVarDeclInitFunc(D, GV);
// Emit global variable debug information.
- if (CGDebugInfo *DI = getModuleDebugInfo())
+ if (CGDebugInfo *DI = getModuleDebugInfo()) {
+ DI->setLocation(D->getLocation());
DI->EmitGlobalVariable(GV, D);
+ }
}
llvm::GlobalValue::LinkageTypes
diff --git a/test/CodeGen/debug-info-line.c b/test/CodeGen/debug-info-line.c
index 9e6e9714aa..b255d90b34 100644
--- a/test/CodeGen/debug-info-line.c
+++ b/test/CodeGen/debug-info-line.c
@@ -1,9 +1,8 @@
-// RUN: %clang -emit-llvm -S -g %s -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g %s -o %t
+// RUN: grep DW_TAG_lexical_block %t | count 3
// Radar 8396182
-// There is only one lexical block, but we need a DILexicalBlock and two
-// DILexicalBlockFile to correctly represent file info. This means we have
-// two lexical blocks shown as the latter is also tagged as a lexical block.
+// There are three lexical blocks in this test case.
int foo() {
int i = 1;
@@ -14,10 +13,3 @@ int foo() {
# 5 "m.c" 2
return i + j;
}
-
-// CHECK: DW_TAG_lexical_block
-// CHECK: DW_TAG_lexical_block
-// CHECK: !"m.h"
-// CHECK: DW_TAG_lexical_block
-// CHECK: !"m.c"
-// CHECK-NOT: DW_TAG_lexical_block