Skip to content

Commit

Permalink
Verifier: Check some amdgpu calling convention restrictions
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299457 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
arsenm committed Apr 4, 2017
1 parent 5d76ab9 commit dce3b51
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,18 @@ void Verifier::visitFunction(const Function &F) {
default:
case CallingConv::C:
break;
case CallingConv::AMDGPU_KERNEL:
case CallingConv::SPIR_KERNEL:
Assert(F.getReturnType()->isVoidTy(),
"Calling convention requires void return type", &F);
LLVM_FALLTHROUGH;
case CallingConv::AMDGPU_VS:
case CallingConv::AMDGPU_GS:
case CallingConv::AMDGPU_PS:
case CallingConv::AMDGPU_CS:
Assert(!F.hasStructRetAttr(),
"Calling convention does not allow sret", &F);
LLVM_FALLTHROUGH;
case CallingConv::Fast:
case CallingConv::Cold:
case CallingConv::Intel_OCL_BI:
Expand Down
5 changes: 3 additions & 2 deletions test/CodeGen/AMDGPU/early-inline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ entry:
; CHECK: mul i32
; CHECK-NOT: call i32

define amdgpu_kernel i32 @caller(i32 %x) {
define amdgpu_kernel void @caller(i32 %x) {
entry:
%res = call i32 @callee(i32 %x)
ret i32 %res
store volatile i32 %res, i32 addrspace(1)* undef
ret void
}
55 changes: 55 additions & 0 deletions test/Verifier/amdgpu-cc.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

; CHECK: Calling convention requires void return type
; CHECK-NEXT: i32 ()* @nonvoid_cc_amdgpu_kernel
define amdgpu_kernel i32 @nonvoid_cc_amdgpu_kernel() {
ret i32 0
}

; CHECK: Calling convention does not support varargs or perfect forwarding!
; CHECK-NEXT: void (...)* @varargs_amdgpu_kernel
define amdgpu_kernel void @varargs_amdgpu_kernel(...) {
ret void
}

; CHECK: Calling convention does not allow sret
; CHECK-NEXT: void (i32*)* @sret_cc_amdgpu_kernel
define amdgpu_kernel void @sret_cc_amdgpu_kernel(i32* sret %ptr) {
ret void
}

; CHECK: Calling convention does not support varargs or perfect forwarding!
; CHECK-NEXT: void (...)* @varargs_amdgpu_vs
define amdgpu_vs void @varargs_amdgpu_vs(...) {
ret void
}

; CHECK: Calling convention does not support varargs or perfect forwarding!
; CHECK-NEXT: void (...)* @varargs_amdgpu_gs
define amdgpu_gs void @varargs_amdgpu_gs(...) {
ret void
}

; CHECK: Calling convention does not support varargs or perfect forwarding!
; CHECK-NEXT: void (...)* @varargs_amdgpu_ps
define amdgpu_ps void @varargs_amdgpu_ps(...) {
ret void
}

; CHECK: Calling convention does not support varargs or perfect forwarding!
; CHECK-NEXT: void (...)* @varargs_amdgpu_cs
define amdgpu_cs void @varargs_amdgpu_cs(...) {
ret void
}

; CHECK: Calling convention requires void return type
; CHECK-NEXT: i32 ()* @nonvoid_cc_spir_kernel
define spir_kernel i32 @nonvoid_cc_spir_kernel() {
ret i32 0
}

; CHECK: Calling convention does not support varargs or perfect forwarding!
; CHECK-NEXT: void (...)* @varargs_spir_kernel
define spir_kernel void @varargs_spir_kernel(...) {
ret void
}

0 comments on commit dce3b51

Please sign in to comment.