[llvm] r319440 - [FuzzMutate] Pick correct index for the insertvalue instruction
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 30 07:26:48 PST 2017
Author: igor.laevsky
Date: Thu Nov 30 07:26:48 2017
New Revision: 319440
URL: http://llvm.org/viewvc/llvm-project?rev=319440&view=rev
Log:
[FuzzMutate] Pick correct index for the insertvalue instruction
Differential Revision: https://reviews.llvm.org/D40395
Modified:
llvm/trunk/lib/FuzzMutate/Operations.cpp
llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp
Modified: llvm/trunk/lib/FuzzMutate/Operations.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/FuzzMutate/Operations.cpp?rev=319440&r1=319439&r2=319440&view=diff
==============================================================================
--- llvm/trunk/lib/FuzzMutate/Operations.cpp (original)
+++ llvm/trunk/lib/FuzzMutate/Operations.cpp Thu Nov 30 07:26:48 2017
@@ -240,9 +240,9 @@ static SourcePred validInsertValueIndex(
auto Pred = [](ArrayRef<Value *> Cur, const Value *V) {
auto *CTy = cast<CompositeType>(Cur[0]->getType());
if (auto *CI = dyn_cast<ConstantInt>(V))
- if (CI->getBitWidth() == 32)
- if (CTy->getTypeAtIndex(CI->getZExtValue()) == V->getType())
- return true;
+ if (CI->getBitWidth() == 32 &&
+ CTy->getTypeAtIndex(CI->getZExtValue()) == Cur[1]->getType())
+ return true;
return false;
};
auto Make = [](ArrayRef<Value *> Cur, ArrayRef<Type *> Ts) {
Modified: llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp?rev=319440&r1=319439&r2=319440&view=diff
==============================================================================
--- llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp (original)
+++ llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp Thu Nov 30 07:26:48 2017
@@ -84,4 +84,50 @@ TEST(RandomIRBuilderTest, ShuffleVectorI
}
}
+TEST(RandomIRBuilderTest, InsertValueIndexes) {
+ // Check that we will generate correct indexes for the insertvalue operation
+
+ LLVMContext Ctx;
+ const char *Source =
+ "%T = type {i8, i32, i64}\n"
+ "define void @test() {\n"
+ " %A = alloca %T\n"
+ " %L = load %T, %T* %A"
+ " ret void\n"
+ "}";
+ auto M = parseAssembly(Source, Ctx);
+
+ fuzzerop::OpDescriptor IVDescr = fuzzerop::insertValueDescriptor(1);
+
+ std::vector<Type *> Types =
+ {Type::getInt8Ty(Ctx), Type::getInt32Ty(Ctx), Type::getInt64Ty(Ctx)};
+ RandomIRBuilder IB(Seed, Types);
+
+ // Get first basic block of the first function
+ Function &F = *M->begin();
+ BasicBlock &BB = *F.begin();
+
+ // Pick first source
+ Instruction *Src = &*std::next(BB.begin());
+
+ SmallVector<Value *, 2> Srcs(2);
+ ASSERT_TRUE(IVDescr.SourcePreds[0].matches({}, Src));
+ Srcs[0] = Src;
+
+ // Generate constants for each of the types and check that we pick correct
+ // index for the given type
+ for (auto *T: Types) {
+ // Loop to account for possible random decisions
+ for (int i = 0; i < 10; ++i) {
+ // Create value we want to insert. Only it's type matters.
+ Srcs[1] = ConstantInt::get(T, 5);
+
+ // Try to pick correct index
+ Value *Src = IB.findOrCreateSource(
+ BB, &*BB.begin(), Srcs, IVDescr.SourcePreds[2]);
+ ASSERT_TRUE(IVDescr.SourcePreds[2].matches(Srcs, Src));
+ }
+ }
+}
+
}
More information about the llvm-commits
mailing list