diff options
| -rw-r--r-- | llvm/lib/Transforms/IPO/Attributor.cpp | 6 | ||||
| -rw-r--r-- | llvm/test/Transforms/FunctionAttrs/misc.ll | 23 |
2 files changed, 28 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 71daf79a04d..6caa0275c7d 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -2321,7 +2321,11 @@ bool Attributor::checkForAllCallSites(const function_ref<bool(CallSite)> &Pred, } for (const Use &U : AssociatedFunction->uses()) { - Instruction *I = cast<Instruction>(U.getUser()); + Instruction *I = dyn_cast<Instruction>(U.getUser()); + // TODO: Deal with abstract call sites here. + if (!I) + return false; + Function *Caller = I->getFunction(); const auto &LivenessAA = diff --git a/llvm/test/Transforms/FunctionAttrs/misc.ll b/llvm/test/Transforms/FunctionAttrs/misc.ll new file mode 100644 index 00000000000..96ceb8743fd --- /dev/null +++ b/llvm/test/Transforms/FunctionAttrs/misc.ll @@ -0,0 +1,23 @@ +; RUN: opt -S -attributor -attributor-disable=false < %s | FileCheck %s + +define void @external() { +entry: + %a = alloca i32, align 4 + %tmp = bitcast i32* %a to i8* + call void @foo(i32* nonnull %a) +; Check we do not crash on these uses +; CHECK: call void @callback1(void (i32*)* nonnull @foo) + call void @callback1(void (i32*)* nonnull @foo) +; CHECK: call void @callback2(void (i8*)* nonnull bitcast (void (i32*)* @foo to void (i8*)*)) + call void @callback2(void (i8*)* bitcast (void (i32*)* @foo to void (i8*)*)) + %tmp1 = bitcast i32* %a to i8* + ret void +} + +define internal void @foo(i32* %a) { +entry: + ret void +} + +declare void @callback1(void (i32*)*) +declare void @callback2(void (i8*)*) |

