[PATCH] D11507: AMDGPU: Fix crash if called function is a bitcast
Matt Arsenault
Matthew.Arsenault at amd.com
Sun Jul 26 00:15:23 PDT 2015
arsenm created this revision.
arsenm added a subscriber: llvm-commits.
getCalledFunction() is null, so this would crash. Replace crash with an error on unsupported call.
http://reviews.llvm.org/D11507
Files:
lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
test/CodeGen/AMDGPU/promote-alloca-bitcast-function.ll
Index: test/CodeGen/AMDGPU/promote-alloca-bitcast-function.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AMDGPU/promote-alloca-bitcast-function.ll
@@ -0,0 +1,22 @@
+; RUN: not llc -march=amdgcn < %s 2>&1 | FileCheck %s
+
+; Make sure that AMDGPUPromoteAlloca doesn't crash if the called
+; function is a constantexpr cast of a function.
+
+declare void @foo(float*) #0
+declare void @foo.varargs(...) #0
+
+; CHECK: error: unsupported call to function foo in crash_call_constexpr_cast
+define void @crash_call_constexpr_cast() #0 {
+ %alloca = alloca i32
+ call void bitcast (void (float*)* @foo to void (i32*)*)(i32* %alloca) #0
+ ret void
+}
+
+define void @crash_call_constexpr_cast_varargs() #0 {
+ %alloca = alloca i32
+ call void bitcast (void (...)* @foo.varargs to void (i32*)*)(i32* %alloca) #0
+ ret void
+}
+
+attributes #0 = { nounwind }
Index: lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
===================================================================
--- lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -240,7 +240,12 @@
for (User *User : Val->users()) {
if(std::find(WorkList.begin(), WorkList.end(), User) != WorkList.end())
continue;
- if (isa<CallInst>(User)) {
+ if (CallInst *CI = dyn_cast<CallInst>(User)) {
+ // TODO: We might be able to handle some cases where the callee is a
+ // constantexpr bitcast of a function.
+ if (!CI->getCalledFunction())
+ return false;
+
WorkList.push_back(User);
continue;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11507.30645.patch
Type: text/x-patch
Size: 1598 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150726/f6dda06e/attachment.bin>
More information about the llvm-commits
mailing list