From: Igor Laevsky Date: Thu, 30 Nov 2017 15:31:13 +0000 (+0000) Subject: [FuzzMutate] Correctly handle vector types in the insertvalue operation X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=afc2161e86ce2b9a332393f9e7c0c30198aaa7f9;p=llvm [FuzzMutate] Correctly handle vector types in the insertvalue operation Differential Revision: https://reviews.llvm.org/D40397 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319442 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/FuzzMutate/Operations.cpp b/lib/FuzzMutate/Operations.cpp index 8bc902edc9c..af2775ebcfb 100644 --- a/lib/FuzzMutate/Operations.cpp +++ b/lib/FuzzMutate/Operations.cpp @@ -216,8 +216,9 @@ OpDescriptor llvm::fuzzerop::extractValueDescriptor(unsigned Weight) { static SourcePred matchScalarInAggregate() { auto Pred = [](ArrayRef Cur, const Value *V) { - if (isa(Cur[0]->getType())) - return V->getType() == Cur[0]->getType(); + if (auto *ArrayT = dyn_cast(Cur[0]->getType())) + return V->getType() == ArrayT->getElementType(); + auto *STy = cast(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 Cur, ArrayRef) { - if (isa(Cur[0]->getType())) - return makeConstantsWithType(Cur[0]->getType()); + if (auto *ArrayT = dyn_cast(Cur[0]->getType())) + return makeConstantsWithType(ArrayT->getElementType()); + std::vector Result; auto *STy = cast(Cur[0]->getType()); for (int I = 0, E = STy->getNumElements(); I < E; ++I) diff --git a/unittests/FuzzMutate/RandomIRBuilderTest.cpp b/unittests/FuzzMutate/RandomIRBuilderTest.cpp index 5e1b338a95f..7d69bda91cc 100644 --- a/unittests/FuzzMutate/RandomIRBuilderTest.cpp +++ b/unittests/FuzzMutate/RandomIRBuilderTest.cpp @@ -164,4 +164,40 @@ TEST(RandomIRBuilderTest, ShuffleVectorSink) { } } +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 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 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]); + } +} + }