Skip to content

Commit 2840458

Browse files
Andrew Savonichevbader
authored andcommitted
[SYCL] Allow SYCL_EXTERNAL to be applied to a function with raw pointers (#861)
SYCL 1.2.1 specification does not allow SYCL_EXTERNAL to be applied to a function with a pointer argument or with a pointer return value. This is required to limit address space inference work to a single translation unit. Given that we make inference after we link all translation units together, it should not really matter now. And there are several cases where external functions with pointers can be useful, so this patch tuns an error into a warning. The default behavior is to report an error. `-Wno-error=sycl-strict` allows raw pointer function parameters or return type. Signed-off-by: Andrew Savonichev <[email protected]>
1 parent d1c6dbe commit 2840458

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ def OpenMPLoopForm : DiagGroup<"openmp-loop-form">;
10541054
def OpenMPTarget : DiagGroup<"openmp-target">;
10551055

10561056
// SYCL warnings
1057+
def SyclStrict : DiagGroup<"sycl-strict">;
10571058
def SyclTarget : DiagGroup<"sycl-target">;
10581059

10591060
// Backend warnings.

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10154,9 +10154,12 @@ def err_conflicting_sycl_kernel_attributes : Error<
1015410154
def err_sycl_attibute_cannot_be_applied_here
1015510155
: Error<"%0 attribute cannot be applied to a "
1015610156
"%select{static function or function in an anonymous namespace"
10157-
"|class member function"
10158-
"|function with a raw pointer return type"
10159-
"|function with a raw pointer parameter type}1">;
10157+
"|class member function}1">;
10158+
def warn_sycl_attibute_function_raw_ptr
10159+
: Warning<"SYCL 1.2.1 specification does not allow %0 attribute applied "
10160+
"to a function with a raw pointer "
10161+
"%select{return type|parameter type}1">,
10162+
InGroup<SyclStrict>, DefaultError;
1016010163
def err_ivdep_duplicate_arg : Error<
1016110164
"duplicate argument to 'ivdep'. attribute requires one or both of a safelen "
1016210165
"and array">;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4365,15 +4365,13 @@ static void handleSYCLDeviceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
43654365
return;
43664366
}
43674367
if (FD->getReturnType()->isPointerType()) {
4368-
S.Diag(AL.getLoc(), diag::err_sycl_attibute_cannot_be_applied_here)
4369-
<< AL << 2 /* function with a raw pointer return type */;
4370-
return;
4368+
S.Diag(AL.getLoc(), diag::warn_sycl_attibute_function_raw_ptr)
4369+
<< AL << 0 /* function with a raw pointer return type */;
43714370
}
43724371
for (const ParmVarDecl *Param : FD->parameters())
43734372
if (Param->getType()->isPointerType()) {
4374-
S.Diag(AL.getLoc(), diag::err_sycl_attibute_cannot_be_applied_here)
4375-
<< AL << 3 /* function with a raw pointer parameter type */;
4376-
return;
4373+
S.Diag(AL.getLoc(), diag::warn_sycl_attibute_function_raw_ptr)
4374+
<< AL << 1 /* function with a raw pointer parameter type */;
43774375
}
43784376

43794377
S.addSyclDeviceDecl(D);

clang/test/SemaSYCL/sycl-device.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify %s
22
// RUN: %clang_cc1 -verify -DNO_SYCL %s
33

4+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify -DNOT_STRICT -Wno-error=sycl-strict -Wno-sycl-strict %s
5+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify -DWARN_STRICT -Wno-error=sycl-strict %s
6+
47
#ifndef NO_SYCL
58

69
__attribute__((sycl_device)) // expected-warning {{'sycl_device' attribute only applies to functions}}
@@ -25,14 +28,27 @@ class A {
2528
int func3() {}
2629
};
2730

28-
__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a function with a raw pointer return type}}
31+
#if defined(NOT_STRICT)
32+
__attribute__((sycl_device))
2933
int* func3() { return nullptr; }
3034

31-
__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a function with a raw pointer parameter type}}
35+
__attribute__((sycl_device))
3236
void func3(int *) {}
37+
#elif defined(WARN_STRICT)
38+
__attribute__((sycl_device)) // expected-warning {{SYCL 1.2.1 specification does not allow 'sycl_device' attribute applied to a function with a raw pointer return type}}
39+
int* func3() { return nullptr; }
3340

41+
__attribute__((sycl_device)) // expected-warning {{SYCL 1.2.1 specification does not allow 'sycl_device' attribute applied to a function with a raw pointer parameter type}}
42+
void func3(int *) {}
3443
#else
44+
__attribute__((sycl_device)) // expected-error {{SYCL 1.2.1 specification does not allow 'sycl_device' attribute applied to a function with a raw pointer return type}}
45+
int* func3() { return nullptr; }
46+
47+
__attribute__((sycl_device)) // expected-error {{SYCL 1.2.1 specification does not allow 'sycl_device' attribute applied to a function with a raw pointer parameter type}}
48+
void func3(int *) {}
49+
#endif
3550

51+
#else // NO_SYCL
3652
__attribute__((sycl_device)) // expected-warning {{'sycl_device' attribute ignored}}
3753
void baz() {}
3854

0 commit comments

Comments
 (0)