[llvm] r319442 - [FuzzMutate] Correctly handle vector types in the insertvalue operation
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 30 07:31:13 PST 2017
Author: igor.laevsky
Date: Thu Nov 30 07:31:13 2017
New Revision: 319442
URL: http://llvm.org/viewvc/llvm-project?rev=319442&view=rev
Log:
[FuzzMutate] Correctly handle vector types in the insertvalue operation
Differential Revision: https://reviews.llvm.org/D40397
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=319442&r1=319441&r2=319442&view=diff
==============================================================================
--- llvm/trunk/lib/FuzzMutate/Operations.cpp (original)
+++ llvm/trunk/lib/FuzzMutate/Operations.cpp Thu Nov 30 07:31:13 2017
@@ -216,8 +216,9 @@ OpDescriptor llvm::fuzzerop::extractValu
static SourcePred matchScalarInAggregate() {
auto Pred = [](ArrayRef<Value *> Cur, const Value *V) {
- if (isa<ArrayType>(Cur[0]->getType()))
- return V->getType() == Cur[0]->getType();
+ if (auto *ArrayT = dyn_cast<ArrayType>(Cur[0]->getType()))
+ return V->getType() == ArrayT->getElementType();
+
auto *STy = cast<StructType>(Cur[0]->getType());
for (int I = 0, E = STy->getNumElements(); I < E; ++I)
if (STy->getTypeAtIndex(I) == V->getType())
@@ -225,8 +226,9 @@ static SourcePred matchScalarInAggregate
return false;
};
auto Make = [](ArrayRef<Value *> Cur, ArrayRef<Type *>) {
- if (isa<ArrayType>(Cur[0]->getType()))
- return makeConstantsWithType(Cur[0]->getType());
+ if (auto *ArrayT = dyn_cast<ArrayType>(Cur[0]->getType()))
+ return makeConstantsWithType(ArrayT->getElementType());
+
std::vector<Constant *> Result;
auto *STy = cast<StructType>(Cur[0]->getType());
for (int I = 0, E = STy->getNumElements(); I < E; ++I)
Modified: llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp?rev=319442&r1=319441&r2=319442&view=diff
==============================================================================
--- llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp (original)
+++ llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp Thu Nov 30 07:31:13 2017
@@ -164,4 +164,40 @@ TEST(RandomIRBuilderTest, ShuffleVectorS
}
}
+TEST(RandomIRBuilderTest, InsertValueArray) {
+ // Check that we can generate insertvalue for the vector operations
+
+ LLVMContext Ctx;
+ const char *SourceCode =
+ "define void @test() {\n"
+ " %A = alloca [8 x i32]\n"
+ " %L = load [8 x i32], [8 x i32]* %A"
+ " ret void\n"
+ "}";
+ auto M = parseAssembly(SourceCode, Ctx);
+
+ fuzzerop::OpDescriptor Descr = 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 *Source = &*std::next(BB.begin());
+ ASSERT_TRUE(Descr.SourcePreds[0].matches({}, Source));
+
+ SmallVector<Value *, 2> Srcs(2);
+
+ // Check that we can always pick the last two operands.
+ for (int i = 0; i < 10; ++i) {
+ Srcs[0] = Source;
+ Srcs[1] = IB.findOrCreateSource(BB, {Source}, Srcs, Descr.SourcePreds[1]);
+ IB.findOrCreateSource(BB, {}, Srcs, Descr.SourcePreds[2]);
+ }
+}
+
}
More information about the llvm-commits
mailing list