Skip to content

Commit cdc6008

Browse files
author
Andrew Savonichev
committed
[SYCL] Allow SYCL_EXTERNAL to be applied to a function with raw pointers
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. Signed-off-by: Andrew Savonichev <andrew.savonichev@intel.com>
1 parent 20248cf commit cdc6008

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

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

10551055
// SYCL warnings
1056+
def Sycl : DiagGroup<"sycl">;
10561057
def SyclTarget : DiagGroup<"sycl-target">;
10571058

10581059
// Backend warnings.

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10120,9 +10120,12 @@ def err_conflicting_sycl_kernel_attributes : Error<
1012010120
def err_sycl_attibute_cannot_be_applied_here
1012110121
: Error<"%0 attribute cannot be applied to a "
1012210122
"%select{static function or function in an anonymous namespace"
10123-
"|class member function"
10124-
"|function with a raw pointer return type"
10125-
"|function with a raw pointer parameter type}1">;
10123+
"|class member function}1">;
10124+
def warn_sycl_attibute_address_space_ext
10125+
: Warning<"SYCL 1.2.1 specification does not allow %0 attribute applied "
10126+
"to a %select{function with a raw pointer return type"
10127+
"|function with a raw pointer parameter type}1">,
10128+
InGroup<Sycl>;
1012610129
def err_ivdep_duplicate_arg : Error<
1012710130
"duplicate argument to 'ivdep'. attribute requires one or both of a safelen "
1012810131
"and array">;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4329,15 +4329,13 @@ static void handleSYCLDeviceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
43294329
return;
43304330
}
43314331
if (FD->getReturnType()->isPointerType()) {
4332-
S.Diag(AL.getLoc(), diag::err_sycl_attibute_cannot_be_applied_here)
4333-
<< AL << 2 /* function with a raw pointer return type */;
4334-
return;
4332+
S.Diag(AL.getLoc(), diag::warn_sycl_attibute_address_space_ext)
4333+
<< AL << 0 /* function with a raw pointer return type */;
43354334
}
43364335
for (const ParmVarDecl *Param : FD->parameters())
43374336
if (Param->getType()->isPointerType()) {
4338-
S.Diag(AL.getLoc(), diag::err_sycl_attibute_cannot_be_applied_here)
4339-
<< AL << 3 /* function with a raw pointer parameter type */;
4340-
return;
4337+
S.Diag(AL.getLoc(), diag::warn_sycl_attibute_address_space_ext)
4338+
<< AL << 1 /* function with a raw pointer parameter type */;
43414339
}
43424340

43434341
S.addSyclDeviceDecl(D);

clang/test/SemaSYCL/sycl-device.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class A {
2525
int func3() {}
2626
};
2727

28-
__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a function with a raw pointer return type}}
28+
__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}}
2929
int* func3() { return nullptr; }
3030

31-
__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a function with a raw pointer parameter type}}
31+
__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}}
3232
void func3(int *) {}
3333

3434
#else

0 commit comments

Comments
 (0)