Skip to content

Commit c21340d

Browse files
committed
[KeyInstr][Inline] Don't propagate atoms to inlined nodebug instructions (llvm#133485)
RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668
1 parent 746005d commit c21340d

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,13 @@ class DILocation : public MDNode {
21372137
#endif
21382138
}
21392139

2140+
const DILocation *getWithoutAtom() const {
2141+
if (!getAtomGroup() && !getAtomRank())
2142+
return this;
2143+
return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
2144+
isImplicitCode());
2145+
}
2146+
21402147
// Disallow replacing operands.
21412148
void replaceOperandWith(unsigned I, Metadata *New) = delete;
21422149

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,10 +1822,16 @@ static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
18221822
/// to encode location where these instructions are inlined.
18231823
static void fixupLineNumbers(Function *Fn, Function::iterator FI,
18241824
Instruction *TheCall, bool CalleeHasDebugInfo) {
1825-
const DebugLoc &TheCallDL = TheCall->getDebugLoc();
1826-
if (!TheCallDL)
1825+
if (!TheCall->getDebugLoc())
18271826
return;
18281827

1828+
// Don't propagate the source location atom from the call to inlined nodebug
1829+
// instructions, and avoid putting it in the InlinedAt field of inlined
1830+
// not-nodebug instructions. FIXME: Possibly worth transferring/generating
1831+
// an atom for the returned value, otherwise we miss stepping on inlined
1832+
// nodebug functions (which is different to existing behaviour).
1833+
DebugLoc TheCallDL = TheCall->getDebugLoc().get()->getWithoutAtom();
1834+
18291835
auto &Ctx = Fn->getContext();
18301836
DILocation *InlinedAtNode = TheCallDL;
18311837

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)