Skip to content

Commit 7e476eb

Browse files
authored
[AMDGPU][Clang] Add check of size for __builtin_amdgcn_global_load_lds (#93064)
1 parent ac88ad3 commit 7e476eb

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12385,4 +12385,8 @@ def err_acc_reduction_composite_type
1238512385
def err_acc_reduction_composite_member_type :Error<
1238612386
"OpenACC 'reduction' composite variable must not have non-scalar field">;
1238712387
def note_acc_reduction_composite_member_loc : Note<"invalid field is here">;
12388+
12389+
// AMDGCN builtins diagnostics
12390+
def err_amdgcn_global_load_lds_size_invalid_value : Error<"invalid size value">;
12391+
def note_amdgcn_global_load_lds_size_valid_value : Note<"size must be 1, 2, or 4">;
1238812392
} // end of sema component.

clang/lib/Sema/SemaChecking.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5696,6 +5696,28 @@ bool Sema::CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID,
56965696
// position of memory order and scope arguments in the builtin
56975697
unsigned OrderIndex, ScopeIndex;
56985698
switch (BuiltinID) {
5699+
case AMDGPU::BI__builtin_amdgcn_global_load_lds: {
5700+
constexpr const int SizeIdx = 2;
5701+
llvm::APSInt Size;
5702+
Expr *ArgExpr = TheCall->getArg(SizeIdx);
5703+
ExprResult R = VerifyIntegerConstantExpression(ArgExpr, &Size);
5704+
if (R.isInvalid())
5705+
return true;
5706+
switch (Size.getSExtValue()) {
5707+
case 1:
5708+
case 2:
5709+
case 4:
5710+
return false;
5711+
default:
5712+
Diag(ArgExpr->getExprLoc(),
5713+
diag::err_amdgcn_global_load_lds_size_invalid_value)
5714+
<< ArgExpr->getSourceRange();
5715+
Diag(ArgExpr->getExprLoc(),
5716+
diag::note_amdgcn_global_load_lds_size_valid_value)
5717+
<< ArgExpr->getSourceRange();
5718+
return true;
5719+
}
5720+
}
56995721
case AMDGPU::BI__builtin_amdgcn_get_fpenv:
57005722
case AMDGPU::BI__builtin_amdgcn_set_fpenv:
57015723
return false;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -triple amdgcn-unknown-unknown -target-cpu gfx940 -S -verify -o - %s
2+
// REQUIRES: amdgpu-registered-target
3+
4+
typedef unsigned int u32;
5+
6+
void test_global_load_lds_unsupported_size(global u32* src, local u32 *dst, u32 size) {
7+
__builtin_amdgcn_global_load_lds(src, dst, size, /*offset=*/0, /*aux=*/0); // expected-error{{expression is not an integer constant expression}}
8+
__builtin_amdgcn_global_load_lds(src, dst, /*size=*/5, /*offset=*/0, /*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must be 1, 2, or 4}}
9+
__builtin_amdgcn_global_load_lds(src, dst, /*size=*/0, /*offset=*/0, /*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must be 1, 2, or 4}}
10+
__builtin_amdgcn_global_load_lds(src, dst, /*size=*/3, /*offset=*/0, /*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must be 1, 2, or 4}}
11+
__builtin_amdgcn_global_load_lds(src, dst, /*size=*/12, /*offset=*/0, /*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must be 1, 2, or 4}}
12+
__builtin_amdgcn_global_load_lds(src, dst, /*size=*/16, /*offset=*/0, /*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must be 1, 2, or 4}}
13+
__builtin_amdgcn_global_load_lds(src, dst, /*size=*/-1, /*offset=*/0, /*aux=*/0); // expected-error{{invalid size value}} expected-note {{size must be 1, 2, or 4}}
14+
}

llvm/include/llvm/IR/IntrinsicsAMDGPU.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,7 @@ class AMDGPUGlobalLoadLDS :
24722472
[],
24732473
[LLVMQualPointerType<1>, // Base global pointer to load from
24742474
LLVMQualPointerType<3>, // LDS base pointer to store to
2475-
llvm_i32_ty, // Data byte size: 1/2/4 (/12/16 for gfx950)
2475+
llvm_i32_ty, // Data byte size: 1/2/4
24762476
llvm_i32_ty, // imm offset (applied to both global and LDS address)
24772477
llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = sc0,
24782478
// bit 1 = sc1,

0 commit comments

Comments
 (0)