Skip to content

Commit

Permalink
Fix a crash in InstCombine where we could try to truncate a switch co…
Browse files Browse the repository at this point in the history
…mparison to zero width.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231761 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
resistor committed Mar 10, 2015
1 parent bb6a88c commit 3a3665f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions test/Transforms/InstCombine/switch-truncate-crash.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; RUN: opt -instcombine < %s

define void @test() {
switch i32 0, label %out [i32 0, label %out]
out:
ret void
}

0 comments on commit 3a3665f

Please sign in to comment.