Skip to content

Commit 538c4c9

Browse files
authored
[SYCL] Diagnose attempt to pass pointer to VLA as kernel arg (#2441)
VLA as well as pointers to VLA require additional AST transformation to make emission of corresponding type in LLVM IR possible. Without this transformation Codegen just crashes. Implementing this transformation is not reasonable whereas SYCL standard doesn't allow VLA in device code, so emit an error in case if pointer to VLA is passed as kernel argument.
1 parent db5037c commit 538c4c9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,18 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
12981298
return isValid();
12991299
}
13001300

1301+
bool handlePointerType(FieldDecl *FD, QualType FieldTy) final {
1302+
while (FieldTy->isAnyPointerType()) {
1303+
FieldTy = QualType{FieldTy->getPointeeOrArrayElementType(), 0};
1304+
if (FieldTy->isVariableArrayType()) {
1305+
Diag.Report(FD->getLocation(), diag::err_vla_unsupported);
1306+
IsInvalid = true;
1307+
break;
1308+
}
1309+
}
1310+
return isValid();
1311+
}
1312+
13011313
bool handleOtherType(FieldDecl *FD, QualType FieldTy) final {
13021314
Diag.Report(FD->getLocation(), diag::err_bad_kernel_param_type) << FieldTy;
13031315
IsInvalid = true;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64 -fsyntax-only -Wno-sycl-2017-compat -verify %s
2+
//
3+
// This test checks if compiler reports compilation error on an attempt to pass
4+
// a pointer to VLA as kernel argument
5+
6+
#include "Inputs/sycl.hpp"
7+
8+
void foo(unsigned X) {
9+
using VLATy = float(*)[X];
10+
VLATy PtrToVLA;
11+
cl::sycl::kernel_single_task<class Kernel>([=]() {
12+
// expected-error@+1 {{variable length arrays are not supported for the current target}}
13+
(void)PtrToVLA;
14+
});
15+
}

0 commit comments

Comments
 (0)