[llvm] [llvm-c] Add missing nullptr check in LLVMGetFirstDbgRecord (PR #151101)

Maxime Arthaud via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 31 00:39:21 PDT 2025


https://github.com/arthaud updated https://github.com/llvm/llvm-project/pull/151101

>From 338ef0b2947b090c7aa50c8ff6949f8358aa6c99 Mon Sep 17 00:00:00 2001
From: Maxime Arthaud <maxime at arthaud.me>
Date: Tue, 29 Jul 2025 10:35:06 +0200
Subject: [PATCH] [llvm-c] Add missing nullptr check in LLVMGetFirstDbgRecord

Fix a crash when calling LLVMGetFirstDbgRecord or LLVMGetLastDbgRecord
on instructions without debug markers.
---
 llvm/lib/IR/Core.cpp | 4 ++++
 1 file changed, 4 insertions(+)

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;



More information about the llvm-commits mailing list