[llvm] 92abb1c - [TypePromotion] Don't mutate the result type of SwitchInst.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 16 08:54:41 PDT 2021
Author: Craig Topper
Date: 2021-08-16T08:54:34-07:00
New Revision: 92abb1cf90ff65e729fca9d518150ad4c04d25e1
URL: https://github.com/llvm/llvm-project/commit/92abb1cf90ff65e729fca9d518150ad4c04d25e1
DIFF: https://github.com/llvm/llvm-project/commit/92abb1cf90ff65e729fca9d518150ad4c04d25e1.diff
LOG: [TypePromotion] Don't mutate the result type of SwitchInst.
SwitchInst should have a void result type.
Add a check to the verifier to catch this error.
Reviewed By: samparker
Differential Revision: https://reviews.llvm.org/D108084
Added:
Modified:
llvm/lib/CodeGen/TypePromotion.cpp
llvm/lib/IR/Verifier.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp b/llvm/lib/CodeGen/TypePromotion.cpp
index 2ce6ea1d42120..1c9717e05eaf1 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -539,8 +539,8 @@ void IRPromoter::PromoteTree() {
I->setOperand(i, UndefValue::get(ExtTy));
}
- // Mutate the result type, unless this is an icmp.
- if (!isa<ICmpInst>(I)) {
+ // Mutate the result type, unless this is an icmp or switch.
+ if (!isa<ICmpInst>(I) && !isa<SwitchInst>(I)) {
I->mutateType(ExtTy);
Promoted.insert(I);
}
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 5e93aa08c5af3..9392b4684d73f 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2691,6 +2691,7 @@ void Verifier::visitReturnInst(ReturnInst &RI) {
}
void Verifier::visitSwitchInst(SwitchInst &SI) {
+ Assert(SI.getType()->isVoidTy(), "Switch must have void result type!", &SI);
// Check to make sure that all of the constants in the switch instruction
// have the same type as the switched-on value.
Type *SwitchTy = SI.getCondition()->getType();
More information about the llvm-commits
mailing list