[FuzzMutate] Avoid using swifterror as a source operand

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

llvm-svn: 322280
diff --git a/llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp b/llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp
index b60da6c..d6ad07d 100644
--- a/llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp
+++ b/llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp
@@ -266,4 +266,34 @@
   }
 }
 
+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));
+  }
+}
+
 }