Skip to content

Commit 6a6b791

Browse files
committed
Merging r243461:
------------------------------------------------------------------------ r243461 | Matthew.Arsenault | 2015-07-28 14:29:14 -0400 (Tue, 28 Jul 2015) | 5 lines AMDGPU: Fix crash if called function is a bitcast getCalledFunction() is null, so this would crash. Replace crash with an error on unsupported call. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_37@253227 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent aac32f3 commit 6a6b791

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,12 @@ static bool collectUsesWithPtrTypes(Value *Val, std::vector<Value*> &WorkList) {
240240
for (User *User : Val->users()) {
241241
if(std::find(WorkList.begin(), WorkList.end(), User) != WorkList.end())
242242
continue;
243-
if (isa<CallInst>(User)) {
243+
if (CallInst *CI = dyn_cast<CallInst>(User)) {
244+
// TODO: We might be able to handle some cases where the callee is a
245+
// constantexpr bitcast of a function.
246+
if (!CI->getCalledFunction())
247+
return false;
248+
244249
WorkList.push_back(User);
245250
continue;
246251
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: not llc -march=amdgcn < %s 2>&1 | FileCheck %s
2+
3+
; Make sure that AMDGPUPromoteAlloca doesn't crash if the called
4+
; function is a constantexpr cast of a function.
5+
6+
declare void @foo(float*) #0
7+
declare void @foo.varargs(...) #0
8+
9+
; CHECK: error: unsupported call to function foo in crash_call_constexpr_cast
10+
define void @crash_call_constexpr_cast() #0 {
11+
%alloca = alloca i32
12+
call void bitcast (void (float*)* @foo to void (i32*)*)(i32* %alloca) #0
13+
ret void
14+
}
15+
16+
define void @crash_call_constexpr_cast_varargs() #0 {
17+
%alloca = alloca i32
18+
call void bitcast (void (...)* @foo.varargs to void (i32*)*)(i32* %alloca) #0
19+
ret void
20+
}
21+
22+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)