Skip to content

Commit f875544

Browse files
[clang] Use File Location for debug info resolution.
1 parent a55c4c8 commit f875544

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void CGDebugInfo::setLocation(SourceLocation Loc) {
318318
if (Loc.isInvalid())
319319
return;
320320

321-
CurLoc = CGM.getContext().getSourceManager().getExpansionLoc(Loc);
321+
CurLoc = CGM.getContext().getSourceManager().getFileLoc(Loc);
322322

323323
// If we've changed files in the middle of a lexical scope go ahead
324324
// and create a new lexical scope with file node if it's different
@@ -545,7 +545,7 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
545545
FileName = TheCU->getFile()->getFilename();
546546
CSInfo = TheCU->getFile()->getChecksum();
547547
} else {
548-
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
548+
PresumedLoc PLoc = SM.getPresumedLoc(SM.getFileLoc(Loc));
549549
FileName = PLoc.getFilename();
550550

551551
if (FileName.empty()) {
@@ -572,7 +572,8 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
572572
if (CSKind)
573573
CSInfo.emplace(*CSKind, Checksum);
574574
}
575-
return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
575+
return createFile(FileName, CSInfo,
576+
getSource(SM, SM.getFileID(SM.getExpansionLoc(Loc))));
576577
}
577578

578579
llvm::DIFile *CGDebugInfo::createFile(
@@ -627,7 +628,7 @@ unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
627628
if (Loc.isInvalid())
628629
return 0;
629630
SourceManager &SM = CGM.getContext().getSourceManager();
630-
return SM.getPresumedLoc(Loc).getLine();
631+
return SM.getPresumedLoc(SM.getFileLoc(Loc)).getLine();
631632
}
632633

633634
unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) {
@@ -639,7 +640,7 @@ unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) {
639640
if (Loc.isInvalid() && CurLoc.isInvalid())
640641
return 0;
641642
SourceManager &SM = CGM.getContext().getSourceManager();
642-
PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc);
643+
PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? SM.getFileLoc(Loc) : CurLoc);
643644
return PLoc.isValid() ? PLoc.getColumn() : 0;
644645
}
645646

@@ -4973,7 +4974,7 @@ void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) {
49734974
// Update our current location
49744975
setLocation(Loc);
49754976

4976-
if (CurLoc.isInvalid() || CurLoc.isMacroID() || LexicalBlockStack.empty())
4977+
if (CurLoc.isInvalid() || LexicalBlockStack.empty())
49774978
return;
49784979

49794980
llvm::MDNode *Scope = LexicalBlockStack.back();
@@ -6244,7 +6245,8 @@ void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
62446245
void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
62456246
const StringLiteral *S) {
62466247
SourceLocation Loc = S->getStrTokenLoc(0);
6247-
PresumedLoc PLoc = CGM.getContext().getSourceManager().getPresumedLoc(Loc);
6248+
SourceManager &SM = CGM.getContext().getSourceManager();
6249+
PresumedLoc PLoc = SM.getPresumedLoc(SM.getFileLoc(Loc));
62486250
if (!PLoc.isValid())
62496251
return;
62506252

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %clang_cc1 %s -debug-info-kind=standalone -emit-llvm -o - | FileCheck %s
2+
3+
#define GLOBAL(num) global## num
4+
#define DECL_GLOBAL(x) int x
5+
#define SAME_ORDER(x, y) x; y
6+
#define SWAP_ORDER(x,y) y; x
7+
8+
9+
10+
SAME_ORDER(
11+
int
12+
// CHECK: DIGlobalVariable(name: "global",{{.*}} line: [[@LINE+1]]
13+
GLOBAL // <- global
14+
() = 42,
15+
const char* s() {
16+
// CHECK: DIGlobalVariable({{.*}}line: [[@LINE+1]],{{.*}} type: [[TYPEID:![0-9]+]]
17+
return "1234567890";
18+
}
19+
)
20+
21+
SWAP_ORDER(
22+
int GLOBAL( // <- global2
23+
2) = 43,
24+
// CHECK: DIGlobalVariable(name: "global3",{{.*}} line: [[@LINE+3]]
25+
// CHECK: DIGlobalVariable(name: "global2",{{.*}} line: [[@LINE-3]]
26+
DECL_GLOBAL(
27+
GLOBAL( // <- global3
28+
3)) = 44
29+
);
30+
31+
32+
DECL_GLOBAL(
33+
// CHECK: DIGlobalVariable(name: "global4",{{.*}} line: [[@LINE+1]]
34+
GLOBAL( // <- global4
35+
4));

0 commit comments

Comments
 (0)