[PATCH] D41109: [FuzzMutate] Only generate loads and stores to the first class sized types
Igor Laevsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 12 04:21:31 PST 2017
igor-laevsky created this revision.
igor-laevsky added a reviewer: bogner.
We can't load or store from the non sized or non first class types. I.e loading from a function pointer or opaque struct shouldn't be allowed.
Repository:
rL LLVM
https://reviews.llvm.org/D41109
Files:
lib/FuzzMutate/RandomIRBuilder.cpp
unittests/FuzzMutate/RandomIRBuilderTest.cpp
Index: unittests/FuzzMutate/RandomIRBuilderTest.cpp
===================================================================
--- unittests/FuzzMutate/RandomIRBuilderTest.cpp
+++ unittests/FuzzMutate/RandomIRBuilderTest.cpp
@@ -266,4 +266,34 @@
}
}
+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));
+ }
+}
+
}
Index: lib/FuzzMutate/RandomIRBuilder.cpp
===================================================================
--- lib/FuzzMutate/RandomIRBuilder.cpp
+++ lib/FuzzMutate/RandomIRBuilder.cpp
@@ -140,9 +140,15 @@
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)))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41109.126527.patch
Type: text/x-patch
Size: 2136 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171212/daa26590/attachment.bin>
More information about the llvm-commits
mailing list