Allow null-valued function operands in getCalledFunction()
authorDavid Stenberg <david.stenberg@ericsson.com>
Fri, 2 Nov 2018 11:46:24 +0000 (11:46 +0000)
committerDavid Stenberg <david.stenberg@ericsson.com>
Fri, 2 Nov 2018 11:46:24 +0000 (11:46 +0000)
commit5595b1ea28575d2880a8e1f201e337513a4ccd9a
tree6e0905c2b497f2ff5e699227dfc78c424532012c
parent9c0fdc15e00c16ac42219c26086f5bee5668d456
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

llvm-svn: 345966
llvm/include/llvm/IR/Instructions.h
llvm/unittests/IR/MetadataTest.cpp