Skip to content

Commit 92abb1c

Browse files
committed
[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
1 parent 5ed162c commit 92abb1c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

llvm/lib/CodeGen/TypePromotion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ void IRPromoter::PromoteTree() {
539539
I->setOperand(i, UndefValue::get(ExtTy));
540540
}
541541

542-
// Mutate the result type, unless this is an icmp.
543-
if (!isa<ICmpInst>(I)) {
542+
// Mutate the result type, unless this is an icmp or switch.
543+
if (!isa<ICmpInst>(I) && !isa<SwitchInst>(I)) {
544544
I->mutateType(ExtTy);
545545
Promoted.insert(I);
546546
}

llvm/lib/IR/Verifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,7 @@ void Verifier::visitReturnInst(ReturnInst &RI) {
26912691
}
26922692

26932693
void Verifier::visitSwitchInst(SwitchInst &SI) {
2694+
Assert(SI.getType()->isVoidTy(), "Switch must have void result type!", &SI);
26942695
// Check to make sure that all of the constants in the switch instruction
26952696
// have the same type as the switched-on value.
26962697
Type *SwitchTy = SI.getCondition()->getType();

0 commit comments

Comments
 (0)