[libFuzzer] don't crash if the condition in a switch has unusual type (e.g. i72)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244544 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kostya Serebryany 2015-08-11 00:24:39 +00:00
parent 6ea7654870
commit 0e2c9c8c4a
2 changed files with 27 additions and 0 deletions

View File

@ -375,6 +375,9 @@ void SanitizerCoverageModule::InjectTraceForSwitch(
IRBuilder<> IRB(I);
SmallVector<Constant *, 16> Initializers;
Value *Cond = SI->getCondition();
if (Cond->getType()->getScalarSizeInBits() >
Int64Ty->getScalarSizeInBits())
continue;
Initializers.push_back(ConstantInt::get(Int64Ty, SI->getNumCases()));
Initializers.push_back(
ConstantInt::get(Int64Ty, Cond->getType()->getScalarSizeInBits()));

View File

@ -30,3 +30,27 @@ sw.bb.2: ; preds = %entry
sw.epilog: ; preds = %entry, %sw.bb.2, %sw.bb.1, %sw.bb
ret void
}
define void @fooi72(i72 %x) {
entry:
switch i72 %x, label %sw.epilog [
i72 1, label %sw.bb
i72 101, label %sw.bb.1
i72 1001, label %sw.bb.2
]
sw.bb: ; preds = %entry
tail call void @_Z3bari(i32 4)
br label %sw.epilog
sw.bb.1: ; preds = %entry
tail call void @_Z3bari(i32 5)
br label %sw.epilog
sw.bb.2: ; preds = %entry
tail call void @_Z3bari(i32 6)
br label %sw.epilog
sw.epilog: ; preds = %entry, %sw.bb.2, %sw.bb.1, %sw.bb
ret void
}