Skip to content

Commit d5d3676

Browse files
committed
[KeyInstr][Inline] Don't propagate atoms to inlined nodebug instructions
1 parent a13c0b6 commit d5d3676

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
@@ -2284,6 +2284,13 @@ class DILocation : public MDNode {
22842284
#endif
22852285
}
22862286

2287+
const DILocation *getOrCloneWithoutAtom() const {
2288+
if (!getAtomGroup() && !getAtomRank())
2289+
return this;
2290+
return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
2291+
isImplicitCode());
2292+
}
2293+
22872294
// Disallow replacing operands.
22882295
void replaceOperandWith(unsigned I, Metadata *New) = delete;
22892296

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,9 +1827,9 @@ static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
18271827
/// to encode location where these instructions are inlined.
18281828
static void fixupLineNumbers(Function *Fn, Function::iterator FI,
18291829
Instruction *TheCall, bool CalleeHasDebugInfo) {
1830-
const DebugLoc &TheCallDL = TheCall->getDebugLoc();
1831-
if (!TheCallDL)
1830+
if (!TheCall->getDebugLoc())
18321831
return;
1832+
DebugLoc TheCallDL = TheCall->getDebugLoc().get()->getOrCloneWithoutAtom();
18331833

18341834
auto &Ctx = Fn->getContext();
18351835
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)