aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-12-02 11:55:56 +0100
committerNikita Popov <nikita.ppv@gmail.com>2021-12-02 11:58:39 +0100
commita0ff26e08c0cca4917a08c8b8383b8338aa8e73e (patch)
tree2aa413831bd936464c521657aaf16dda1116a73a /llvm/lib/Transforms/Utils/Local.cpp
parent69deb1371fd4cd2fbf37a82cbc21df79c6d51c70 (diff)
downloadllvm-a0ff26e08c0cca4917a08c8b8383b8338aa8e73e.zip
llvm-a0ff26e08c0cca4917a08c8b8383b8338aa8e73e.tar.gz
llvm-a0ff26e08c0cca4917a08c8b8383b8338aa8e73e.tar.bz2
[GlobalOpt] Fix assertion failure during instruction deletion
This fixes the assertion failure reported in https://reviews.llvm.org/D114889#3166417, by making RecursivelyDeleteTriviallyDeadInstructionsPermissive() more permissive. As the function accepts a WeakTrackingVH, even if originally only Instructions were inserted, we may end up with different Value types after a RAUW operation. As such, we should not assume that the vector only contains instructions. Notably this matches the behavior of the RecursivelyDeleteTriviallyDeadInstructions() function variant which accepts a single value rather than vector.
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 99eed9e..ec926b1 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -529,8 +529,8 @@ bool llvm::RecursivelyDeleteTriviallyDeadInstructionsPermissive(
std::function<void(Value *)> AboutToDeleteCallback) {
unsigned S = 0, E = DeadInsts.size(), Alive = 0;
for (; S != E; ++S) {
- auto *I = cast<Instruction>(DeadInsts[S]);
- if (!isInstructionTriviallyDead(I)) {
+ auto *I = dyn_cast<Instruction>(DeadInsts[S]);
+ if (!I || !isInstructionTriviallyDead(I)) {
DeadInsts[S] = nullptr;
++Alive;
}