Skip to content

Commit 4e5736d

Browse files
committed
[Clang][AMDGPU] Accept builtins in lambda declarations
Sema::getCurFunctionDecl(AllowLambda = false) returns a nullptr when the lambda declaration is outside a function (for example, when used in an assignment). Using Sema::getCurFunctionDecl(AllowLambda = true) returns the declaration of the enclosing lambda.
1 parent d54c28b commit 4e5736d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

clang/lib/Sema/SemaAMDGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID,
2727
// position of memory order and scope arguments in the builtin
2828
unsigned OrderIndex, ScopeIndex;
2929

30-
const auto *FD = SemaRef.getCurFunctionDecl();
30+
const auto *FD = SemaRef.getCurFunctionDecl(true);
3131
assert(FD && "AMDGPU builtins should not be used outside of a function");
3232
llvm::StringMap<bool> CallerFeatureMap;
3333
getASTContext().getFunctionFeatureMap(CallerFeatureMap, FD);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// REQUIRES: amdgpu-registered-target
2+
// RUN: %clang_cc1 -std=c++20 -triple amdgcn -target-cpu tahiti -fsyntax-only -fcuda-is-device -verify=expected -o - %s
3+
// RUN: %clang_cc1 -std=c++20 -triple amdgcn -target-cpu gfx950 -fsyntax-only -fcuda-is-device -o - %s
4+
5+
#define __device__ __attribute__((device))
6+
#define __shared__ __attribute__((shared))
7+
8+
struct S {
9+
static constexpr auto make_buffer_rsrc_lambda = [](void *p, short stride, int num, int flags) {
10+
return __builtin_amdgcn_make_buffer_rsrc(p, stride, num, flags);
11+
};
12+
13+
static constexpr auto global_load_lds_lambda = [](void* src, __shared__ void *dst) {
14+
__builtin_amdgcn_global_load_lds(src, dst, 16, 0, 0); // expected-error{{invalid size value}} expected-note{{size must be 1, 2, or 4}}
15+
};
16+
};
17+
18+
__device__ __amdgpu_buffer_rsrc_t test_simple_builtin(void *p, short stride, int num, int flags) {
19+
return S::make_buffer_rsrc_lambda(p, stride, num, flags);
20+
}
21+
22+
__device__ void test_target_dependant_builtin(void *src, __shared__ void *dst) {
23+
S::global_load_lds_lambda(src, dst);
24+
}

0 commit comments

Comments
 (0)