llvm.org GIT mirror llvm / 8460fe0
AMDGPU: Fix crashes in invalid call cases We have to at least tolerate calls to kernels, possibly with a mismatched calling convention on the callsite. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355049 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 11 months ago
5 changed file(s) with 54 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
772772 } else {
773773 // We force CodeGen to run in SCC order, so the callee's register
774774 // usage etc. should be the cumulative usage of all callees.
775
775776 auto I = CallGraphResourceInfo.find(Callee);
776 assert(I != CallGraphResourceInfo.end() &&
777 "callee should have been handled before caller");
777 if (I == CallGraphResourceInfo.end()) {
778 // Avoid crashing on undefined behavior with an illegal call to a
779 // kernel. If a callsite's calling convention doesn't match the
780 // function's, it's undefined behavior. If the callsite calling
781 // convention does match, that would have errored earlier.
782 // FIXME: The verifier shouldn't allow this.
783 if (AMDGPU::isEntryFunctionCC(Callee->getCallingConv()))
784 report_fatal_error("invalid call to entry function");
785
786 llvm_unreachable("callee should have been handled before caller");
787 }
778788
779789 MaxSGPR = std::max(I->second.NumExplicitSGPR - 1, MaxSGPR);
780790 MaxVGPR = std::max(I->second.NumVGPR - 1, MaxVGPR);
847847 CCAssignFn *AMDGPUCallLowering::CCAssignFnForCall(CallingConv::ID CC,
848848 bool IsVarArg) {
849849 switch (CC) {
850 case CallingConv::AMDGPU_KERNEL:
851 case CallingConv::SPIR_KERNEL:
852 llvm_unreachable("kernels should not be handled here");
853850 case CallingConv::AMDGPU_VS:
854851 case CallingConv::AMDGPU_GS:
855852 case CallingConv::AMDGPU_PS:
862859 case CallingConv::Fast:
863860 case CallingConv::Cold:
864861 return CC_AMDGPU_Func;
862 case CallingConv::AMDGPU_KERNEL:
863 case CallingConv::SPIR_KERNEL:
865864 default:
866 report_fatal_error("Unsupported calling convention.");
865 report_fatal_error("Unsupported calling convention for call");
867866 }
868867 }
869868
0 ; RUN: not llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs -o /dev/null %s 2>&1 | FileCheck %s
1
2 ; FIXME: It should be invalid IR to have a call to a kernel, but this
3 ; is currently relied on, but should be eliminated before codegen.
4 define amdgpu_kernel void @callee_kernel(i32 addrspace(1)* %out) #0 {
5 entry:
6 store volatile i32 0, i32 addrspace(1)* %out
7 ret void
8 }
9
10 ; Make sure there's no crash when the callsite calling convention
11 ; doesn't match.
12 ; CHECK: LLVM ERROR: invalid call to entry function
13 define amdgpu_kernel void @caller_kernel(i32 addrspace(1)* %out) #0 {
14 entry:
15 call void @callee_kernel(i32 addrspace(1)* %out)
16 ret void
17 }
18
19 attributes #0 = { nounwind noinline }
0 ; RUN: not llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs -o /dev/null %s 2>&1 | FileCheck %s
1
2 ; FIXME: It should be invalid IR to have a call to a kernel, but this
3 ; is currently relied on, but should be eliminated before codegen.
4 define amdgpu_kernel void @callee_kernel(i32 addrspace(1)* %out) #0 {
5 entry:
6 store volatile i32 0, i32 addrspace(1)* %out
7 ret void
8 }
9
10 ; CHECK: LLVM ERROR: Unsupported calling convention for call
11 define amdgpu_kernel void @caller_kernel(i32 addrspace(1)* %out) #0 {
12 entry:
13 call amdgpu_kernel void @callee_kernel(i32 addrspace(1)* %out)
14 ret void
15 }
16
17 attributes #0 = { nounwind noinline }
22 ; RUN: llc -march=r600 -mcpu=redwood -verify-machineinstrs < %s | FileCheck %s
33
44 ; CHECK-NOT: {{^}}func:
5 define internal fastcc i32 @func(i32 %a) {
5 define internal i32 @func(i32 %a) {
66 entry:
77 %tmp0 = add i32 %a, 1
88 ret i32 %tmp0
1717 ret void
1818 }
1919
20 ; CHECK: {{^}}kernel2:
21 ; CHECK-NOT: call
22 define amdgpu_kernel void @kernel2(i32 addrspace(1)* %out) {
23 entry:
24 call void @kernel(i32 addrspace(1)* %out)
25 ret void
26 }
27
2820 ; CHECK-NOT: func_alias
2921 @func_alias = alias i32 (i32), i32 (i32)* @func
3022
3628 store i32 %tmp0, i32 addrspace(1)* %out
3729 ret void
3830 }
39
40 ; CHECK-NOT: kernel_alias
41 @kernel_alias = alias void (i32 addrspace(1)*), void (i32 addrspace(1)*)* @kernel
42
43 ; CHECK: {{^}}kernel4:
44 ; CHECK-NOT: call
45 define amdgpu_kernel void @kernel4(i32 addrspace(1)* %out) {
46 entry:
47 call void @kernel_alias(i32 addrspace(1)* %out)
48 ret void
49 }