Skip to content

[KeyInstr][Inline] Don't propagate atoms to inlined nodebug instructions #133485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,13 @@ class DILocation : public MDNode {
#endif
}

const DILocation *getWithoutAtom() const {
if (!getAtomGroup() && !getAtomRank())
return this;
return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
isImplicitCode());
}

// Disallow replacing operands.
void replaceOperandWith(unsigned I, Metadata *New) = delete;

Expand Down
10 changes: 8 additions & 2 deletions llvm/lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1827,10 +1827,16 @@ static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
/// to encode location where these instructions are inlined.
static void fixupLineNumbers(Function *Fn, Function::iterator FI,
Instruction *TheCall, bool CalleeHasDebugInfo) {
const DebugLoc &TheCallDL = TheCall->getDebugLoc();
if (!TheCallDL)
if (!TheCall->getDebugLoc())
return;

// Don't propagate the source location atom from the call to inlined nodebug
// instructions, and avoid putting it in the InlinedAt field of inlined
// not-nodebug instructions. FIXME: Possibly worth transferring/generating
// an atom for the returned value, otherwise we miss stepping on inlined
// nodebug functions (which is different to existing behaviour).
DebugLoc TheCallDL = TheCall->getDebugLoc().get()->getWithoutAtom();

auto &Ctx = Fn->getContext();
DILocation *InlinedAtNode = TheCallDL;

Expand Down
43 changes: 43 additions & 0 deletions llvm/test/DebugInfo/KeyInstructions/Generic/inline-nodbg.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
; RUN: opt %s -passes=inline -S -o - | FileCheck %s

;; $ cat test.cpp
;; int g;
;; [[clang::always_inline, gnu::nodebug]] void a() { g = 1; }
;; void b() { a(); }
;;
;; Check the inlined instructions don't inherit the call's atom info.
;; FIXME: Perhaps we want to do actually do that, to preserve existing
;; behaviour? Unclear what's best.

; CHECK: _Z1bv()
; CHECK: store i32 1, ptr @g, align 4, !dbg [[DBG:!.*]]
; CHECK: [[DBG]] = !DILocation(line: 3, scope: ![[#]])

@g = hidden global i32 0, align 4

define hidden void @_Z1av() {
entry:
store i32 1, ptr @g, align 4
ret void
}

define hidden void @_Z1bv() !dbg !15 {
entry:
call void @_Z1av(), !dbg !18
ret void, !dbg !19
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3}
!llvm.ident = !{!10}

!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)
!1 = !DIFile(filename: "test.cpp", directory: "/")
!2 = !{i32 7, !"Dwarf Version", i32 5}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!10 = !{!"clang version 19.0.0"}
!15 = distinct !DISubprogram(name: "b", scope: !1, file: !1, line: 3, type: !16, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
!16 = !DISubroutineType(types: !17)
!17 = !{}
!18 = !DILocation(line: 3, scope: !15, atomGroup: 1, atomRank: 1)
!19 = !DILocation(line: 3, scope: !15, atomGroup: 2, atomRank: 1)
Loading