[llvm] r369588 - [Attributor] Fix: Gracefully handle non-instruction users
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 14:48:56 PDT 2019
Author: jdoerfert
Date: Wed Aug 21 14:48:56 2019
New Revision: 369588
URL: http://llvm.org/viewvc/llvm-project?rev=369588&view=rev
Log:
[Attributor] Fix: Gracefully handle non-instruction users
Function can have users that are not instructions, e.g., bitcasts. For
now, we simply give up when we see them.
Added:
llvm/trunk/test/Transforms/FunctionAttrs/misc.ll
Modified:
llvm/trunk/lib/Transforms/IPO/Attributor.cpp
Modified: llvm/trunk/lib/Transforms/IPO/Attributor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Attributor.cpp?rev=369588&r1=369587&r2=369588&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Attributor.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Attributor.cpp Wed Aug 21 14:48:56 2019
@@ -2321,7 +2321,11 @@ bool Attributor::checkForAllCallSites(co
}
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 =
Added: llvm/trunk/test/Transforms/FunctionAttrs/misc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/misc.ll?rev=369588&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/misc.ll (added)
+++ llvm/trunk/test/Transforms/FunctionAttrs/misc.ll Wed Aug 21 14:48:56 2019
@@ -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*)*)
More information about the llvm-commits
mailing list