summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Analysis/LazyCallGraphTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2016-12-27 05:00:45 +0000
committerChandler Carruth <chandlerc@gmail.com>2016-12-27 05:00:45 +0000
commit162504578bf160985aa0da73fcce6dbb1b027503 (patch)
tree6cb685869db2656b1f91be438bfdf7d7fe888bdc /llvm/unittests/Analysis/LazyCallGraphTest.cpp
parent70536f4e47f8098fa869bb6651b8d138865d86d1 (diff)
downloadbcm5719-llvm-162504578bf160985aa0da73fcce6dbb1b027503.tar.gz
bcm5719-llvm-162504578bf160985aa0da73fcce6dbb1b027503.zip
[LCG] Teach the LazyCallGraph to handle visiting the blockaddress
constant expression and to correctly form function reference edges through them without crashing because one of the operands (the `BasicBlock` isn't actually a constant despite being an operand of a constant). llvm-svn: 290581
Diffstat (limited to 'llvm/unittests/Analysis/LazyCallGraphTest.cpp')
-rw-r--r--llvm/unittests/Analysis/LazyCallGraphTest.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/LazyCallGraphTest.cpp b/llvm/unittests/Analysis/LazyCallGraphTest.cpp
index d3022519f16..45c24eedf7e 100644
--- a/llvm/unittests/Analysis/LazyCallGraphTest.cpp
+++ b/llvm/unittests/Analysis/LazyCallGraphTest.cpp
@@ -2016,4 +2016,35 @@ TEST(LazyCallGraphTest, InternalRefEdgeToCallBothPartitionAndMerge) {
EXPECT_EQ(&AC, &RC[4]);
}
+// Test for IR containing constants using blockaddress constant expressions.
+// These are truly unique constructs: constant expressions with non-constant
+// operands.
+TEST(LazyCallGraphTest, HandleBlockAddress) {
+ LLVMContext Context;
+ std::unique_ptr<Module> M =
+ parseAssembly(Context, "define void @f() {\n"
+ "entry:\n"
+ " ret void\n"
+ "bb:\n"
+ " unreachable\n"
+ "}\n"
+ "define void @g(i8** %ptr) {\n"
+ "entry:\n"
+ " store i8* blockaddress(@f, %bb), i8** %ptr\n"
+ " ret void\n"
+ "}\n");
+ LazyCallGraph CG(*M);
+
+ auto I = CG.postorder_ref_scc_begin();
+ LazyCallGraph::RefSCC &FRC = *I++;
+ LazyCallGraph::RefSCC &GRC = *I++;
+ EXPECT_EQ(CG.postorder_ref_scc_end(), I);
+
+ LazyCallGraph::Node &F = *CG.lookup(lookupFunction(*M, "f"));
+ LazyCallGraph::Node &G = *CG.lookup(lookupFunction(*M, "g"));
+ EXPECT_EQ(&FRC, CG.lookupRefSCC(F));
+ EXPECT_EQ(&GRC, CG.lookupRefSCC(G));
+ EXPECT_TRUE(GRC.isParentOf(FRC));
+}
+
}
OpenPOWER on IntegriCloud