aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDavid Stenberg <david.stenberg@ericsson.com>2018-11-02 11:46:24 +0000
committerDavid Stenberg <david.stenberg@ericsson.com>2018-11-02 11:46:24 +0000
commit11ef6e19fe894f726ad4b581262d8852e8d53740 (patch)
treedab410ddae4b439f9e58fcadf96fd012f9dfbefb /unittests
parent44ee0056851e1e133e53d05269fe9051f92c7b56 (diff)
Allow null-valued function operands in getCalledFunction()
Summary: Change the dynamic cast in CallBase::getCalledFunction() to allow null-valued function operands. This patch fixes a crash that occurred when a funtion operand of a call instruction was dropped, and later on a metadata-carrying instruction was printed out. When allocating the metadata slot numbers, getCalledFunction() would be invoked on the call with the dropped operand, resulting in a failed non-null assertion in isa<>. This fixes PR38924, in which a printout in DBCE crashed due to this. This aligns getCalledFunction() with getCalledValue(), as the latter allows the operand to be null. Reviewers: vsk, dexonsmith, hfinkel Reviewed By: dexonsmith Subscribers: hfinkel, llvm-commits Differential Revision: https://reviews.llvm.org/D52537 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345966 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/IR/MetadataTest.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp
index 83b166a263c..100c4ed5e15 100644
--- a/unittests/IR/MetadataTest.cpp
+++ b/unittests/IR/MetadataTest.cpp
@@ -402,6 +402,27 @@ TEST_F(MDNodeTest, PrintFromMetadataAsValue) {
EXPECT_PRINTER_EQ("metadata !0", MAV0->printAsOperand(OS, true, MST));
EXPECT_PRINTER_EQ("metadata !1", MAV1->printAsOperand(OS, true, MST));
}
+
+TEST_F(MDNodeTest, PrintWithDroppedCallOperand) {
+ Module M("test", Context);
+
+ auto *FTy = FunctionType::get(Type::getVoidTy(Context), false);
+ auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M);
+ auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M);
+ auto *BB0 = BasicBlock::Create(Context, "entry", F0);
+
+ CallInst *CI0 = CallInst::Create(F1, "", BB0);
+ CI0->dropAllReferences();
+
+ auto *R0 = ReturnInst::Create(Context, BB0);
+ auto *N0 = MDNode::getDistinct(Context, None);
+ R0->setMetadata("md", N0);
+
+ // Printing the metadata node would previously result in a failed assertion
+ // due to the call instruction's dropped function operand.
+ ModuleSlotTracker MST(&M);
+ EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, MST));
+}
#undef EXPECT_PRINTER_EQ
TEST_F(MDNodeTest, NullOperand) {