[llvm] [llvm-isel-fuzzer] Fix crash in `IRMutator::getEffectiveTerminator` (PR #180853)
Demetrius Kanios via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 10 14:48:25 PST 2026
https://github.com/QuantumSegfault created https://github.com/llvm/llvm-project/pull/180853
`IRMutator::getEffectiveTerminator` would assume that when an UnreachableInst is the terminator of a block, that there is always a previous instruction. This is not the case (you can have a unreachable isolated in a block).
This swaps `dyn_cast` with `dyn_cast_if_present` accordingly.
>From a84b2ca2eb02d5efeeb405a6a87e5fc24d94afc1 Mon Sep 17 00:00:00 2001
From: Demetrius Kanios <demetrius at kanios.net>
Date: Tue, 10 Feb 2026 14:08:51 -0800
Subject: [PATCH] Fix crash in `IRMutator::getEffectiveTerminator`
---
llvm/lib/FuzzMutate/IRMutator.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/FuzzMutate/IRMutator.cpp b/llvm/lib/FuzzMutate/IRMutator.cpp
index d1abf78222c8c..75ee2611065c2 100644
--- a/llvm/lib/FuzzMutate/IRMutator.cpp
+++ b/llvm/lib/FuzzMutate/IRMutator.cpp
@@ -26,6 +26,7 @@
#include "llvm/IR/Operator.h"
#include "llvm/IR/PassInstrumentation.h"
#include "llvm/IR/Verifier.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Transforms/Scalar/DCE.h"
@@ -124,7 +125,7 @@ static inline Instruction *getEffectiveTerminator(BasicBlock &BB) {
// Certain intrinsics, such as @llvm.amdgcn.cs.chain, must be immediately
// followed by an unreachable instruction..
if (UnreachableInst *UI = dyn_cast<UnreachableInst>(BB.getTerminator())) {
- if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(UI->getPrevNode())) {
+ if (IntrinsicInst *II = dyn_cast_if_present<IntrinsicInst>(UI->getPrevNode())) {
return II;
}
}
More information about the llvm-commits
mailing list