diff options
Diffstat (limited to 'unittests/Bitcode/BitReaderTest.cpp')
-rw-r--r-- | unittests/Bitcode/BitReaderTest.cpp | 72 |
1 files changed, 68 insertions, 4 deletions
diff --git a/unittests/Bitcode/BitReaderTest.cpp b/unittests/Bitcode/BitReaderTest.cpp index 1f28ec6f0d6d9..2e6dd0b499dec 100644 --- a/unittests/Bitcode/BitReaderTest.cpp +++ b/unittests/Bitcode/BitReaderTest.cpp @@ -75,13 +75,77 @@ TEST(BitReaderTest, DematerializeFunctionPreservesLinkageType) { GlobalValue::InternalLinkage); // Check that the linkage type is preserved after dematerialization. - M->getFunction("func")->Dematerialize(); + M->getFunction("func")->dematerialize(); EXPECT_TRUE(M->getFunction("func")->empty()); EXPECT_TRUE(M->getFunction("func")->getLinkage() == GlobalValue::InternalLinkage); EXPECT_FALSE(verifyModule(*M, &dbgs())); } +// Tests that lazy evaluation can parse functions out of order. +TEST(BitReaderTest, MaterializeFunctionsOutOfOrder) { + SmallString<1024> Mem; + LLVMContext Context; + std::unique_ptr<Module> M = getLazyModuleFromAssembly( + Context, Mem, "define void @f() {\n" + " unreachable\n" + "}\n" + "define void @g() {\n" + " unreachable\n" + "}\n" + "define void @h() {\n" + " unreachable\n" + "}\n" + "define void @j() {\n" + " unreachable\n" + "}\n"); + EXPECT_FALSE(verifyModule(*M, &dbgs())); + + Function *F = M->getFunction("f"); + Function *G = M->getFunction("g"); + Function *H = M->getFunction("h"); + Function *J = M->getFunction("j"); + + // Initially all functions are not materialized (no basic blocks). + EXPECT_TRUE(F->empty()); + EXPECT_TRUE(G->empty()); + EXPECT_TRUE(H->empty()); + EXPECT_TRUE(J->empty()); + EXPECT_FALSE(verifyModule(*M, &dbgs())); + + // Materialize h. + H->materialize(); + EXPECT_TRUE(F->empty()); + EXPECT_TRUE(G->empty()); + EXPECT_FALSE(H->empty()); + EXPECT_TRUE(J->empty()); + EXPECT_FALSE(verifyModule(*M, &dbgs())); + + // Materialize g. + G->materialize(); + EXPECT_TRUE(F->empty()); + EXPECT_FALSE(G->empty()); + EXPECT_FALSE(H->empty()); + EXPECT_TRUE(J->empty()); + EXPECT_FALSE(verifyModule(*M, &dbgs())); + + // Materialize j. + J->materialize(); + EXPECT_TRUE(F->empty()); + EXPECT_FALSE(G->empty()); + EXPECT_FALSE(H->empty()); + EXPECT_FALSE(J->empty()); + EXPECT_FALSE(verifyModule(*M, &dbgs())); + + // Materialize f. + F->materialize(); + EXPECT_FALSE(F->empty()); + EXPECT_FALSE(G->empty()); + EXPECT_FALSE(H->empty()); + EXPECT_FALSE(J->empty()); + EXPECT_FALSE(verifyModule(*M, &dbgs())); +} + TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677 SmallString<1024> Mem; @@ -96,7 +160,7 @@ TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677 EXPECT_FALSE(verifyModule(*M, &dbgs())); // Try (and fail) to dematerialize @func. - M->getFunction("func")->Dematerialize(); + M->getFunction("func")->dematerialize(); EXPECT_FALSE(M->getFunction("func")->empty()); } @@ -127,7 +191,7 @@ TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionBefore) { EXPECT_FALSE(verifyModule(*M, &dbgs())); // Try (and fail) to dematerialize @func. - M->getFunction("func")->Dematerialize(); + M->getFunction("func")->dematerialize(); EXPECT_FALSE(M->getFunction("func")->empty()); EXPECT_FALSE(verifyModule(*M, &dbgs())); } @@ -159,7 +223,7 @@ TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionAfter) { EXPECT_FALSE(verifyModule(*M, &dbgs())); // Try (and fail) to dematerialize @func. - M->getFunction("func")->Dematerialize(); + M->getFunction("func")->dematerialize(); EXPECT_FALSE(M->getFunction("func")->empty()); EXPECT_FALSE(verifyModule(*M, &dbgs())); } |