Skip to content

Commit 2dc123b

Browse files
[clang][opencl] Allow passing all zeros to reqd_work_group_size (#131543)
Allow passing all zeros to reqd_work_group_size. Test plan: ninja check-all
1 parent 81ba006 commit 2dc123b

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,10 +2923,16 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
29232923
if (!S.checkUInt32Argument(AL, E, WGSize[i], i,
29242924
/*StrictlyUnsigned=*/true))
29252925
return;
2926-
if (WGSize[i] == 0) {
2927-
S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2928-
<< AL << E->getSourceRange();
2929-
return;
2926+
}
2927+
2928+
if (!llvm::all_of(WGSize, [](uint32_t Size) { return Size == 0; })) {
2929+
for (unsigned i = 0; i < 3; ++i) {
2930+
const Expr *E = AL.getArgAsExpr(i);
2931+
if (WGSize[i] == 0) {
2932+
S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2933+
<< AL << E->getSourceRange();
2934+
return;
2935+
}
29302936
}
29312937
}
29322938

clang/test/CodeGenCUDASPIRV/spirv-attrs.cu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#define __global__ __attribute__((global))
55

6+
__attribute__((reqd_work_group_size(0, 0, 0)))
7+
__global__ void reqd_work_group_size_0_0_0() {}
8+
69
__attribute__((reqd_work_group_size(128, 1, 1)))
710
__global__ void reqd_work_group_size_128_1_1() {}
811

@@ -15,13 +18,16 @@ __global__ void vec_type_hint_int() {}
1518
__attribute__((intel_reqd_sub_group_size(64)))
1619
__global__ void intel_reqd_sub_group_size_64() {}
1720

21+
22+
// CHECK: define spir_kernel void @_Z26reqd_work_group_size_0_0_0v() #[[ATTR:[0-9]+]] !reqd_work_group_size ![[WG_SIZE_ZEROS:[0-9]+]]
1823
// CHECK: define spir_kernel void @_Z28reqd_work_group_size_128_1_1v() #[[ATTR:[0-9]+]] !reqd_work_group_size ![[WG_SIZE:[0-9]+]]
1924
// CHECK: define spir_kernel void @_Z26work_group_size_hint_2_2_2v() #[[ATTR]] !work_group_size_hint ![[WG_HINT:[0-9]+]]
2025
// CHECK: define spir_kernel void @_Z17vec_type_hint_intv() #[[ATTR]] !vec_type_hint ![[VEC_HINT:[0-9]+]]
2126
// CHECK: define spir_kernel void @_Z28intel_reqd_sub_group_size_64v() #[[ATTR]] !intel_reqd_sub_group_size ![[SUB_GRP:[0-9]+]]
2227

2328
// CHECK: attributes #[[ATTR]] = { {{.*}} }
2429

30+
// CHECK: ![[WG_SIZE_ZEROS]] = !{i32 0, i32 0, i32 0}
2531
// CHECK: ![[WG_SIZE]] = !{i32 128, i32 1, i32 1}
2632
// CHECK: ![[WG_HINT]] = !{i32 2, i32 2, i32 2}
2733
// CHECK: ![[VEC_HINT]] = !{i32 undef, i32 1}

clang/test/SemaOpenCL/invalid-kernel-attrs.cl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ __kernel __attribute__((reqd_work_group_size(8,16,-32))) void neg2(){} // expect
4444
// 4294967294 is a negative integer if treated as signed.
4545
// Should compile successfully, since we expect an unsigned.
4646
__kernel __attribute__((reqd_work_group_size(8,16,4294967294))) void ok1(){}
47+
48+
__kernel __attribute__((reqd_work_group_size(0,0,0))) void ok_zeros(){}

0 commit comments

Comments
 (0)