From 780cef1f34373b872ea3cfc8e0180a889ce388fe Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 29 Jun 2020 10:37:15 -0400 Subject: [PATCH] Verifier: Check byref address space for AMDGPU calling conventions --- llvm/lib/IR/Verifier.cpp | 13 ++++++++++++- llvm/test/Verifier/amdgpu-cc.ll | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index f638ed7040b..67a295e7a71 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2314,13 +2314,24 @@ void Verifier::visitFunction(const Function &F) { Assert(!F.hasStructRetAttr(), "Calling convention does not allow sret", &F); if (F.getCallingConv() != CallingConv::SPIR_KERNEL) { - for (unsigned i = 0, e = F.arg_size(); i != e; ++i) { + const unsigned StackAS = DL.getAllocaAddrSpace(); + unsigned i = 0; + for (const Argument &Arg : F.args()) { Assert(!Attrs.hasParamAttribute(i, Attribute::ByVal), "Calling convention disallows byval", &F); Assert(!Attrs.hasParamAttribute(i, Attribute::Preallocated), "Calling convention disallows preallocated", &F); Assert(!Attrs.hasParamAttribute(i, Attribute::InAlloca), "Calling convention disallows inalloca", &F); + + if (Attrs.hasParamAttribute(i, Attribute::ByRef)) { + // FIXME: Should also disallow LDS and GDS, but we don't have the enum + // value here. + Assert(Arg.getType()->getPointerAddressSpace() != StackAS, + "Calling convention disallows stack byref", &F); + } + + ++i; } } diff --git a/llvm/test/Verifier/amdgpu-cc.ll b/llvm/test/Verifier/amdgpu-cc.ll index 25b8d9088ac..1cd1b346741 100644 --- a/llvm/test/Verifier/amdgpu-cc.ll +++ b/llvm/test/Verifier/amdgpu-cc.ll @@ -121,3 +121,9 @@ define amdgpu_kernel void @preallocated_as0_cc_amdgpu_kernel(i32* preallocated(i define amdgpu_kernel void @inalloca_as0_cc_amdgpu_kernel(i32* inalloca %ptr) { ret void } + +; CHECK: Calling convention disallows stack byref +; CHECK-NEXT: void (i32 addrspace(5)*)* @byref_as5_cc_amdgpu_kernel +define amdgpu_kernel void @byref_as5_cc_amdgpu_kernel(i32 addrspace(5)* byref(i32) %ptr) { + ret void +} -- 2.11.0