Skip to content

Commit e7ab569

Browse files
Fznamznonvmaksimo
authored andcommitted
err_typecheck_zero_array_size now accepts an argument, the error message has changed. Remove asserts from SemaSYCL since deferred diagnostics happen after it.
1 parent b7d7612 commit e7ab569

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ static void checkSYCLType(Sema &S, QualType Ty, SourceRange Loc,
444444

445445
// zero length arrays
446446
if (isZeroSizedArray(Ty)) {
447-
S.SYCLDiagIfDeviceCode(Loc.getBegin(), diag::err_typecheck_zero_array_size);
447+
S.SYCLDiagIfDeviceCode(Loc.getBegin(), diag::err_typecheck_zero_array_size)
448+
<< 1;
448449
Emitting = true;
449450
}
450451

@@ -1274,7 +1275,6 @@ class KernelObjVisitor {
12741275
assert(CAT && "Should only be called on constant-size array.");
12751276
QualType ET = CAT->getElementType();
12761277
uint64_t ElemCount = CAT->getSize().getZExtValue();
1277-
assert(ElemCount > 0 && "SYCL prohibits 0 sized arrays");
12781278

12791279
(void)std::initializer_list<int>{
12801280
(Handlers.enterArray(Field, ArrayTy, ET), 0)...};
@@ -3072,10 +3072,6 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
30723072
CollectionInitExprs.pop_back();
30733073
ArrayInfos.pop_back();
30743074

3075-
assert(
3076-
!SemaRef.getASTContext().getAsConstantArrayType(ArrayType)->getSize() ==
3077-
0 &&
3078-
"Constant arrays must have at least 1 element");
30793075
// Remove the IndexExpr.
30803076
MemberExprBases.pop_back();
30813077

clang/test/SemaSYCL/deferred-diagnostics-emit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void variadic(int, ...) {}
2121

2222
// there are more types like this checked in sycl-restrict.cpp
2323
int calledFromKernel(int a) {
24-
// expected-error@+1 {{zero-length arrays are not permitted in C++}}
24+
// expected-error@+1 {{zero-length arrays are not permitted in SYCL device code}}
2525
int MalArray[0];
2626

2727
// expected-error@+1 {{'__float128' is not supported on this target}}
@@ -67,9 +67,9 @@ void setup_sycl_operation(const T VA[]) {
6767
// expected-note@#KernelSingleTaskKernelFuncCall {{called by 'kernel_single_task<AName, (lambda}}
6868
h.single_task<class AName>([]() {
6969
// ======= Zero Length Arrays Not Allowed in Kernel ==========
70-
// expected-error@+1 {{zero-length arrays are not permitted in C++}}
70+
// expected-error@+1 {{zero-length arrays are not permitted in SYCL device code}}
7171
int MalArray[0];
72-
// expected-error@+1 {{zero-length arrays are not permitted in C++}}
72+
// expected-error@+1 {{zero-length arrays are not permitted in SYCL device code}}
7373
intDef MalArrayDef[0];
7474
// ---- false positive tests. These should not generate any errors.
7575
foo<int[0]>();
@@ -170,7 +170,7 @@ int main(int argc, char **argv) {
170170
deviceQueue.submit([&](sycl::handler &h) {
171171
// expected-note@#KernelSingleTaskKernelFuncCall 8 {{called by 'kernel_single_task<AName, (lambda}}
172172
h.single_task<class AName>([]() {
173-
// expected-error@+1 {{zero-length arrays are not permitted in C++}}
173+
// expected-error@+1 {{zero-length arrays are not permitted in SYCL device code}}
174174
int BadArray[0];
175175

176176
// expected-error@+1 {{'__float128' is not supported on this target}}

clang/test/SemaSYCL/sycl-restrict.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ using safealias_t = int;
167167

168168
//struct
169169
struct frankenStruct {
170-
// expected-error@+1 {{zero-length arrays are not permitted in C++}}
170+
// expected-error@+1 {{zero-length arrays are not permitted in SYCL device code}}
171171
int mosterArr[0];
172172
// expected-error@+1 {{'__float128' is not supported on this target}}
173173
__float128 scaryQuad;
@@ -302,9 +302,9 @@ void usage(myFuncDef functionPtr) {
302302
safealias_t<long double> notALD = 55;
303303

304304
// ======= Zero Length Arrays Not Allowed in Kernel ==========
305-
// expected-error@+1 {{zero-length arrays are not permitted in C++}}
305+
// expected-error@+1 {{zero-length arrays are not permitted in SYCL device code}}
306306
int MalArray[0];
307-
// expected-error@+1 {{zero-length arrays are not permitted in C++}}
307+
// expected-error@+1 {{zero-length arrays are not permitted in SYCL device code}}
308308
intDef MalArrayDef[0];
309309
// ---- false positive tests. These should not generate any errors.
310310
foo<int[0]>();

0 commit comments

Comments
 (0)