[llvm] r322280 - [FuzzMutate] Avoid using swifterror as a source operand

Igor Laevsky via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 11 06:43:06 PST 2018


Author: igor.laevsky
Date: Thu Jan 11 06:43:05 2018
New Revision: 322280

URL: http://llvm.org/viewvc/llvm-project?rev=322280&view=rev
Log:
[FuzzMutate] Avoid using swifterror as a source operand

Differential Revision: https://reviews.llvm.org/D41107


Modified:
    llvm/trunk/include/llvm/FuzzMutate/OpDescriptor.h
    llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp

Modified: llvm/trunk/include/llvm/FuzzMutate/OpDescriptor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/FuzzMutate/OpDescriptor.h?rev=322280&r1=322279&r2=322280&view=diff
==============================================================================
--- llvm/trunk/include/llvm/FuzzMutate/OpDescriptor.h (original)
+++ llvm/trunk/include/llvm/FuzzMutate/OpDescriptor.h Thu Jan 11 06:43:05 2018
@@ -20,6 +20,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Instructions.h"
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Value.h"
 #include <functional>
@@ -128,7 +129,7 @@ static inline SourcePred anyFloatType()
 
 static inline SourcePred anyPtrType() {
   auto Pred = [](ArrayRef<Value *>, const Value *V) {
-    return V->getType()->isPointerTy();
+    return V->getType()->isPointerTy() && !V->isSwiftError();
   };
   auto Make = [](ArrayRef<Value *>, ArrayRef<Type *> Ts) {
     std::vector<Constant *> Result;
@@ -142,6 +143,9 @@ static inline SourcePred anyPtrType() {
 
 static inline SourcePred sizedPtrType() {
   auto Pred = [](ArrayRef<Value *>, const Value *V) {
+    if (V->isSwiftError())
+      return false;
+
     if (const auto *PtrT = dyn_cast<PointerType>(V->getType()))
       return PtrT->getElementType()->isSized();
     return false;

Modified: llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp?rev=322280&r1=322279&r2=322280&view=diff
==============================================================================
--- llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp (original)
+++ llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp Thu Jan 11 06:43:05 2018
@@ -266,4 +266,34 @@ TEST(RandomIRBuilderTest, FirstClassType
   }
 }
 
+TEST(RandomIRBuilderTest, SwiftError) {
+  // Check that we never pick swifterror value as a source for operation
+  // other than load, store and call.
+
+  LLVMContext Ctx;
+  const char *SourceCode = "declare void @use(i8** swifterror %err)"
+                           "define void @test() {\n"
+                           "entry:\n"
+                           "  %err = alloca swifterror i8*, align 8\n"
+                           "  call void @use(i8** swifterror %err)\n"
+                           "  ret void\n"
+                           "}";
+  auto M = parseAssembly(SourceCode, Ctx);
+
+  std::vector<Type *> Types = {Type::getInt8Ty(Ctx)};
+  RandomIRBuilder IB(Seed, Types);
+
+  // Get first basic block of the test function
+  Function &F = *M->getFunction("test");
+  BasicBlock &BB = *F.begin();
+  Instruction *Alloca = &*BB.begin();
+
+  fuzzerop::OpDescriptor Descr = fuzzerop::gepDescriptor(1);
+
+  for (int i = 0; i < 10; ++i) {
+    Value *V = IB.findOrCreateSource(BB, {Alloca}, {}, Descr.SourcePreds[0]);
+    ASSERT_FALSE(isa<AllocaInst>(V));
+  }
+}
+
 }




More information about the llvm-commits mailing list