summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@google.com>2015-05-06 16:52:35 +0000
committerDerek Schuff <dschuff@google.com>2015-05-06 16:52:35 +0000
commit5d8dfd39e1135dfdea044ff40f1c6dbef3489e73 (patch)
tree77165b4a3eff0d1ae8469bdeefeaf39474fc9ad6 /llvm/unittests
parent3b0adaf6b031288c10b8badfd491832a03dce89b (diff)
downloadbcm5719-llvm-5d8dfd39e1135dfdea044ff40f1c6dbef3489e73.tar.gz
bcm5719-llvm-5d8dfd39e1135dfdea044ff40f1c6dbef3489e73.zip
Add bitcode test to verify functions can be materialized out of order.
Summary: Adds test to check that when getLazyBitcodeModule is called: 1) Functions are not materailzed by default. 2) Only the requested function gets materialized (if no block addresses are used). Reviewers: jvoung, rafael Reviewed By: rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D8907 llvm-svn: 236611
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/Bitcode/BitReaderTest.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/llvm/unittests/Bitcode/BitReaderTest.cpp b/llvm/unittests/Bitcode/BitReaderTest.cpp
index 1f28ec6f0d6..c746f591672 100644
--- a/llvm/unittests/Bitcode/BitReaderTest.cpp
+++ b/llvm/unittests/Bitcode/BitReaderTest.cpp
@@ -82,6 +82,70 @@ TEST(BitReaderTest, DematerializeFunctionPreservesLinkageType) {
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;
OpenPOWER on IntegriCloud