[llvm] [KeyInstr][Inline] Don't propagate atoms to inlined nodebug instructions (PR #133485)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Wed May 7 02:06:26 PDT 2025
https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/133485
>From d5d367610d2ab9d79f20b477219a09a3ae9c8093 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 24 Mar 2025 17:23:59 +0000
Subject: [PATCH 1/2] [KeyInstr][Inline] Don't propagate atoms to inlined
nodebug instructions
---
llvm/include/llvm/IR/DebugInfoMetadata.h | 7 +++
llvm/lib/Transforms/Utils/InlineFunction.cpp | 4 +-
.../KeyInstructions/Generic/inline-nodbg.ll | 43 +++++++++++++++++++
3 files changed, 52 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/DebugInfo/KeyInstructions/Generic/inline-nodbg.ll
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index 0f6a206cab75f..cdfe09acd21d2 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2284,6 +2284,13 @@ class DILocation : public MDNode {
#endif
}
+ const DILocation *getOrCloneWithoutAtom() const {
+ if (!getAtomGroup() && !getAtomRank())
+ return this;
+ return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
+ isImplicitCode());
+ }
+
// Disallow replacing operands.
void replaceOperandWith(unsigned I, Metadata *New) = delete;
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index eaf57e7bf899d..3267f6d33c8ad 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1827,9 +1827,9 @@ 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;
+ DebugLoc TheCallDL = TheCall->getDebugLoc().get()->getOrCloneWithoutAtom();
auto &Ctx = Fn->getContext();
DILocation *InlinedAtNode = TheCallDL;
diff --git a/llvm/test/DebugInfo/KeyInstructions/Generic/inline-nodbg.ll b/llvm/test/DebugInfo/KeyInstructions/Generic/inline-nodbg.ll
new file mode 100644
index 0000000000000..33f7f673d91c3
--- /dev/null
+++ b/llvm/test/DebugInfo/KeyInstructions/Generic/inline-nodbg.ll
@@ -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: ![[#]])
+
+ at 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)
>From 696b1b4f684e618c6065c3a12ae35267af735b12 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Wed, 7 May 2025 10:06:14 +0100
Subject: [PATCH 2/2] address review comments
---
llvm/include/llvm/IR/DebugInfoMetadata.h | 2 +-
llvm/lib/Transforms/Utils/InlineFunction.cpp | 8 +++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index cdfe09acd21d2..d82c69aebb026 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2284,7 +2284,7 @@ class DILocation : public MDNode {
#endif
}
- const DILocation *getOrCloneWithoutAtom() const {
+ const DILocation *getWithoutAtom() const {
if (!getAtomGroup() && !getAtomRank())
return this;
return get(getContext(), getLine(), getColumn(), getScope(), getInlinedAt(),
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 3267f6d33c8ad..24121465530cd 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1829,7 +1829,13 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
Instruction *TheCall, bool CalleeHasDebugInfo) {
if (!TheCall->getDebugLoc())
return;
- DebugLoc TheCallDL = TheCall->getDebugLoc().get()->getOrCloneWithoutAtom();
+
+ // 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;
More information about the llvm-commits
mailing list