Skip to content

Commit fcedb94

Browse files
authored
Merge pull request #11723 from swiftlang/clang/macro-debug-info-to-21.x
🍒[clang] Use File Location for debug info resolution.
2 parents bff1370 + 651cb8a commit fcedb94

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ void CGDebugInfo::setLocation(SourceLocation Loc) {
357357
if (Loc.isInvalid())
358358
return;
359359

360-
CurLoc = CGM.getContext().getSourceManager().getExpansionLoc(Loc);
360+
CurLoc = CGM.getContext().getSourceManager().getFileLoc(Loc);
361361

362362
// If we've changed files in the middle of a lexical scope go ahead
363363
// and create a new lexical scope with file node if it's different
@@ -584,7 +584,7 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
584584
FileName = TheCU->getFile()->getFilename();
585585
CSInfo = TheCU->getFile()->getChecksum();
586586
} else {
587-
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
587+
PresumedLoc PLoc = SM.getPresumedLoc(SM.getFileLoc(Loc));
588588
FileName = PLoc.getFilename();
589589

590590
if (FileName.empty()) {
@@ -611,7 +611,8 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
611611
if (CSKind)
612612
CSInfo.emplace(*CSKind, Checksum);
613613
}
614-
return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
614+
return createFile(FileName, CSInfo,
615+
getSource(SM, SM.getFileID(SM.getFileLoc(Loc))));
615616
}
616617

617618
llvm::DIFile *CGDebugInfo::createFile(
@@ -666,7 +667,7 @@ unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
666667
if (Loc.isInvalid())
667668
return 0;
668669
SourceManager &SM = CGM.getContext().getSourceManager();
669-
return SM.getPresumedLoc(Loc).getLine();
670+
return SM.getPresumedLoc(SM.getFileLoc(Loc)).getLine();
670671
}
671672

672673
unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) {
@@ -678,7 +679,8 @@ unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) {
678679
if (Loc.isInvalid() && CurLoc.isInvalid())
679680
return 0;
680681
SourceManager &SM = CGM.getContext().getSourceManager();
681-
PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc);
682+
PresumedLoc PLoc =
683+
SM.getPresumedLoc(Loc.isValid() ? SM.getFileLoc(Loc) : CurLoc);
682684
return PLoc.isValid() ? PLoc.getColumn() : 0;
683685
}
684686

@@ -5002,7 +5004,7 @@ void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) {
50025004
// Update our current location
50035005
setLocation(Loc);
50045006

5005-
if (CurLoc.isInvalid() || CurLoc.isMacroID() || LexicalBlockStack.empty())
5007+
if (CurLoc.isInvalid() || LexicalBlockStack.empty())
50065008
return;
50075009

50085010
llvm::MDNode *Scope = LexicalBlockStack.back();
@@ -6278,7 +6280,8 @@ void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
62786280
void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
62796281
const StringLiteral *S) {
62806282
SourceLocation Loc = S->getStrTokenLoc(0);
6281-
PresumedLoc PLoc = CGM.getContext().getSourceManager().getPresumedLoc(Loc);
6283+
SourceManager &SM = CGM.getContext().getSourceManager();
6284+
PresumedLoc PLoc = SM.getPresumedLoc(SM.getFileLoc(Loc));
62826285
if (!PLoc.isValid())
62836286
return;
62846287

clang/test/CodeGen/macro-info.c

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)