[libFuzzer] don't crash if the condition in a switch has unusual type (e.g. i72)
authorKostya Serebryany <kcc@google.com>
Tue, 11 Aug 2015 00:24:39 +0000 (00:24 +0000)
committerKostya Serebryany <kcc@google.com>
Tue, 11 Aug 2015 00:24:39 +0000 (00:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244544 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/SanitizerCoverage.cpp
test/Instrumentation/SanitizerCoverage/switch-tracing.ll

index c91b89d..b6829ae 100644 (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()));
index 9ad1c7a..aac56db 100644 (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
+}