[llvm] Add missing nullptr check in LLVMGetFirstDbgRecord (PR #151101)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 29 01:39:06 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Maxime Arthaud (arthaud)
<details>
<summary>Changes</summary>
I'm using the LLVM C bindings through the llvm-sys rust crate, and notice that LLVMGetFirstDbgRecord and LLVMGetLastDbgRecord are segfault-ing when called on instructions without debug markers. I found out it's missing a null pointer check. This PR fixes the issue.
---
Full diff: https://github.com/llvm/llvm-project/pull/151101.diff
1 Files Affected:
- (modified) llvm/lib/IR/Core.cpp (+4)
``````````diff
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index f7ef4aa473ef5..56190545eb024 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -2984,6 +2984,8 @@ LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst) {
LLVMDbgRecordRef LLVMGetFirstDbgRecord(LLVMValueRef Inst) {
Instruction *Instr = unwrap<Instruction>(Inst);
+ if (!Instr->DebugMarker)
+ return nullptr;
auto I = Instr->DebugMarker->StoredDbgRecords.begin();
if (I == Instr->DebugMarker->StoredDbgRecords.end())
return nullptr;
@@ -2992,6 +2994,8 @@ LLVMDbgRecordRef LLVMGetFirstDbgRecord(LLVMValueRef Inst) {
LLVMDbgRecordRef LLVMGetLastDbgRecord(LLVMValueRef Inst) {
Instruction *Instr = unwrap<Instruction>(Inst);
+ if (!Instr->DebugMarker)
+ return nullptr;
auto I = Instr->DebugMarker->StoredDbgRecords.rbegin();
if (I == Instr->DebugMarker->StoredDbgRecords.rend())
return nullptr;
``````````
</details>
https://github.com/llvm/llvm-project/pull/151101
More information about the llvm-commits
mailing list