[llvm] [IR] Add non-const DbgRecord::getInstruction() overload (PR #206059)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 26 08:00:45 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-debuginfo
Author: Konrad Kreczko (kkreczko)
<details>
<summary>Changes</summary>
DbgRecord exposes const+non-const overload pairs for getParent(), getModule() and getContext(), but getInstruction() was const-only and returned a const Instruction*. Code holding a non-const DbgRecord that needs a mutable host instruction, for example to use as a DIBuilder insert position, was therefore forced to const_cast the result.
Add a non-const getInstruction() overload returning a mutable Instruction*, matching the existing accessor pairs and removing the need for those casts. The const overload is unchanged.
AI tools were used to write this description.
---
Full diff: https://github.com/llvm/llvm-project/pull/206059.diff
2 Files Affected:
- (modified) llvm/include/llvm/IR/DebugProgramInstruction.h (+3-1)
- (modified) llvm/lib/IR/DebugProgramInstruction.cpp (+2)
``````````diff
diff --git a/llvm/include/llvm/IR/DebugProgramInstruction.h b/llvm/include/llvm/IR/DebugProgramInstruction.h
index b7cedc60689c7..f216ad54d8a97 100644
--- a/llvm/include/llvm/IR/DebugProgramInstruction.h
+++ b/llvm/include/llvm/IR/DebugProgramInstruction.h
@@ -189,9 +189,11 @@ class DbgRecord : public ilist_node<DbgRecord> {
LLVM_ABI LLVMContext &getContext();
LLVM_ABI const LLVMContext &getContext() const;
+ LLVM_ABI Instruction *getInstruction();
LLVM_ABI const Instruction *getInstruction() const;
- LLVM_ABI const BasicBlock *getParent() const;
+
LLVM_ABI BasicBlock *getParent();
+ LLVM_ABI const BasicBlock *getParent() const;
LLVM_ABI void removeFromParent();
LLVM_ABI void eraseFromParent();
diff --git a/llvm/lib/IR/DebugProgramInstruction.cpp b/llvm/lib/IR/DebugProgramInstruction.cpp
index 98335728665ba..fe25cd3959bfb 100644
--- a/llvm/lib/IR/DebugProgramInstruction.cpp
+++ b/llvm/lib/IR/DebugProgramInstruction.cpp
@@ -526,6 +526,8 @@ const Instruction *DbgRecord::getInstruction() const {
return Marker->MarkedInstr;
}
+Instruction *DbgRecord::getInstruction() { return Marker->MarkedInstr; }
+
const BasicBlock *DbgRecord::getParent() const {
return Marker->MarkedInstr->getParent();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/206059
More information about the llvm-commits
mailing list