[llvm] r320573 - [FuzzMutate] Only generate loads and stores to the first class sized types
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 13 03:49:04 PST 2017
Author: igor.laevsky
Date: Wed Dec 13 03:49:04 2017
New Revision: 320573
URL: http://llvm.org/viewvc/llvm-project?rev=320573&view=rev
Log:
[FuzzMutate] Only generate loads and stores to the first class sized types
Differential Revision: https://reviews.llvm.org/D41109
Modified:
llvm/trunk/lib/FuzzMutate/RandomIRBuilder.cpp
llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp
Modified: llvm/trunk/lib/FuzzMutate/RandomIRBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/FuzzMutate/RandomIRBuilder.cpp?rev=320573&r1=320572&r2=320573&view=diff
==============================================================================
--- llvm/trunk/lib/FuzzMutate/RandomIRBuilder.cpp (original)
+++ llvm/trunk/lib/FuzzMutate/RandomIRBuilder.cpp Wed Dec 13 03:49:04 2017
@@ -140,9 +140,15 @@ Value *RandomIRBuilder::findPointer(Basi
if (isa<TerminatorInst>(Inst))
return false;
- if (auto PtrTy = dyn_cast<PointerType>(Inst->getType()))
+ if (auto PtrTy = dyn_cast<PointerType>(Inst->getType())) {
+ // We can never generate loads from non first class or non sized types
+ if (!PtrTy->getElementType()->isSized() ||
+ !PtrTy->getElementType()->isFirstClassType())
+ return false;
+
// TODO: Check if this is horribly expensive.
return Pred.matches(Srcs, UndefValue::get(PtrTy->getElementType()));
+ }
return false;
};
if (auto RS = makeSampler(Rand, make_filter_range(Insts, IsMatchingPtr)))
Modified: llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp?rev=320573&r1=320572&r2=320573&view=diff
==============================================================================
--- llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp (original)
+++ llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp Wed Dec 13 03:49:04 2017
@@ -236,4 +236,34 @@ TEST(RandomIRBuilderTest, Invokes) {
}
}
+TEST(RandomIRBuilderTest, FirstClassTypes) {
+ // Check that we never insert new source as a load from non first class
+ // or unsized type.
+
+ LLVMContext Ctx;
+ const char *SourceCode = "%Opaque = type opaque\n"
+ "define void @test(i8* %ptr) {\n"
+ "entry:\n"
+ " %tmp = bitcast i8* %ptr to i32* (i32*)*\n"
+ " %tmp1 = bitcast i8* %ptr to %Opaque*\n"
+ " ret void\n"
+ "}";
+ auto M = parseAssembly(SourceCode, Ctx);
+
+ std::vector<Type *> Types = {Type::getInt8Ty(Ctx)};
+ RandomIRBuilder IB(Seed, Types);
+
+ Function &F = *M->getFunction("test");
+ BasicBlock &BB = *F.begin();
+ // Non first class type
+ Instruction *FuncPtr = &*BB.begin();
+ // Unsized type
+ Instruction *OpaquePtr = &*std::next(BB.begin());
+
+ for (int i = 0; i < 10; ++i) {
+ Value *V = IB.findOrCreateSource(BB, {FuncPtr, OpaquePtr});
+ ASSERT_FALSE(isa<LoadInst>(V));
+ }
+}
+
}
More information about the llvm-commits
mailing list