Skip to content

Commit 637b5b4

Browse files
committed
[KeyInstr][Inline] Don't propagate atoms to inlined nodebug instructions
1 parent e2d5b6e commit 637b5b4

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,13 @@ class DILocation : public MDNode {
21452145
return 0;
21462146
}
21472147

2148+
const DILocation *getOrCloneWithoutAtom() const {
2149+
if (!getAtomGroup() && !getAtomRank())
2150+
return this;
2151+
return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
2152+
isImplicitCode());
2153+
}
2154+
21482155
// Disallow replacing operands.
21492156
void replaceOperandWith(unsigned I, Metadata *New) = delete;
21502157

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,9 +1821,9 @@ static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
18211821
/// to encode location where these instructions are inlined.
18221822
static void fixupLineNumbers(Function *Fn, Function::iterator FI,
18231823
Instruction *TheCall, bool CalleeHasDebugInfo) {
1824-
const DebugLoc &TheCallDL = TheCall->getDebugLoc();
1825-
if (!TheCallDL)
1824+
if (!TheCall->getDebugLoc())
18261825
return;
1826+
DebugLoc TheCallDL = TheCall->getDebugLoc().get()->getOrCloneWithoutAtom();
18271827

18281828
auto &Ctx = Fn->getContext();
18291829
DILocation *InlinedAtNode = TheCallDL;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; RUN: opt %s -passes=inline -S -o - | FileCheck %s
2+
3+
;; $ cat test.cpp
4+
;; int g;
5+
;; [[clang::always_inline, gnu::nodebug]] void a() { g = 1; }
6+
;; void b() { a(); }
7+
;;
8+
;; Check the inlined instructions don't inherit the call's atom info.
9+
;; FIXME: Perhaps we want to do actually do that, to preserve existing
10+
;; behaviour? Unclear what's best.
11+
12+
; CHECK: _Z1bv()
13+
; CHECK: store i32 1, ptr @g, align 4, !dbg [[DBG:!.*]]
14+
; CHECK: [[DBG]] = !DILocation(line: 3, scope: ![[#]])
15+
16+
@g = hidden global i32 0, align 4
17+
18+
define hidden void @_Z1av() {
19+
entry:
20+
store i32 1, ptr @g, align 4
21+
ret void
22+
}
23+
24+
define hidden void @_Z1bv() !dbg !15 {
25+
entry:
26+
call void @_Z1av(), !dbg !18
27+
ret void, !dbg !19
28+
}
29+
30+
!llvm.dbg.cu = !{!0}
31+
!llvm.module.flags = !{!2, !3}
32+
!llvm.ident = !{!10}
33+
34+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_17, file: !1, producer: "clang version 19.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
35+
!1 = !DIFile(filename: "test.cpp", directory: "/")
36+
!2 = !{i32 7, !"Dwarf Version", i32 5}
37+
!3 = !{i32 2, !"Debug Info Version", i32 3}
38+
!10 = !{!"clang version 19.0.0"}
39+
!15 = distinct !DISubprogram(name: "b", scope: !1, file: !1, line: 3, type: !16, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
40+
!16 = !DISubroutineType(types: !17)
41+
!17 = !{}
42+
!18 = !DILocation(line: 3, scope: !15, atomGroup: 1, atomRank: 1)
43+
!19 = !DILocation(line: 3, scope: !15, atomGroup: 2, atomRank: 1)

0 commit comments

Comments
 (0)