Skip to content

Commit

Permalink
[RandomIRBuilderTest] Convert to opaque pointers (NFC)
Browse files Browse the repository at this point in the history
The FirstClassTypes test is no longer relevant with opaque pointers,
or at least not in that form.
  • Loading branch information
nikic committed Jan 5, 2023
1 parent ebd9753 commit de918aa
Showing 1 changed file with 10 additions and 40 deletions.
50 changes: 10 additions & 40 deletions llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp
Expand Up @@ -91,7 +91,7 @@ TEST(RandomIRBuilderTest, InsertValueIndexes) {
const char *Source = "%T = type {i8, i32, i64}\n"
"define void @test() {\n"
" %A = alloca %T\n"
" %L = load %T, %T* %A"
" %L = load %T, ptr %A"
" ret void\n"
"}";
auto M = parseAssembly(Source, Ctx);
Expand Down Expand Up @@ -169,7 +169,7 @@ TEST(RandomIRBuilderTest, InsertValueArray) {
LLVMContext Ctx;
const char *SourceCode = "define void @test() {\n"
" %A = alloca [8 x i32]\n"
" %L = load [8 x i32], [8 x i32]* %A"
" %L = load [8 x i32], ptr %A"
" ret void\n"
"}";
auto M = parseAssembly(SourceCode, Ctx);
Expand Down Expand Up @@ -203,17 +203,17 @@ TEST(RandomIRBuilderTest, Invokes) {

LLVMContext Ctx;
const char *SourceCode =
"declare i32* @f()"
"declare ptr @f()"
"declare i32 @personality_function()"
"define i32* @test() personality i32 ()* @personality_function {\n"
"define ptr @test() personality ptr @personality_function {\n"
"entry:\n"
" %val = invoke i32* @f()\n"
" %val = invoke ptr @f()\n"
" to label %normal unwind label %exceptional\n"
"normal:\n"
" ret i32* %val\n"
" ret ptr %val\n"
"exceptional:\n"
" %landing_pad4 = landingpad token cleanup\n"
" ret i32* undef\n"
" ret ptr undef\n"
"}";
auto M = parseAssembly(SourceCode, Ctx);

Expand All @@ -233,46 +233,16 @@ 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));
}
}

TEST(RandomIRBuilderTest, SwiftError) {
// Check that we never pick swifterror value as a source for operation
// other than load, store and call.

LLVMContext Ctx;
const char *SourceCode = "declare void @use(i8** swifterror %err)"
const char *SourceCode = "declare void @use(ptr swifterror %err)"
"define void @test() {\n"
"entry:\n"
" %err = alloca swifterror i8*, align 8\n"
" call void @use(i8** swifterror %err)\n"
" %err = alloca swifterror ptr, align 8\n"
" call void @use(ptr swifterror %err)\n"
" ret void\n"
"}";
auto M = parseAssembly(SourceCode, Ctx);
Expand Down

0 comments on commit de918aa

Please sign in to comment.