From: Owen Anderson Date: Tue, 10 Mar 2015 06:51:39 +0000 (+0000) Subject: Fix a crash in InstCombine where we could try to truncate a switch comparison to... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3a3665fd38a3522f5c014d36d8dd0943dd5762d2;p=oota-llvm.git Fix a crash in InstCombine where we could try to truncate a switch comparison to zero width. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231761 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 9e8b5774517..1fe036b5fbb 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2060,7 +2060,8 @@ Instruction *InstCombiner::visitSwitchInst(SwitchInst &SI) { // x86 generates redundant zero-extenstion instructions if the operand is // truncated to i8 or i16. bool TruncCond = false; - if (BitWidth > NewWidth && NewWidth >= DL.getLargestLegalIntTypeSize()) { + if (NewWidth > 0 && BitWidth > NewWidth && + NewWidth >= DL.getLargestLegalIntTypeSize()) { TruncCond = true; IntegerType *Ty = IntegerType::get(SI.getContext(), NewWidth); Builder->SetInsertPoint(&SI); diff --git a/test/Transforms/InstCombine/switch-truncate-crash.ll b/test/Transforms/InstCombine/switch-truncate-crash.ll new file mode 100644 index 00000000000..cc3c1ff28ed --- /dev/null +++ b/test/Transforms/InstCombine/switch-truncate-crash.ll @@ -0,0 +1,7 @@ +; RUN: opt -instcombine < %s + +define void @test() { + switch i32 0, label %out [i32 0, label %out] +out: + ret void +}