Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL] Allow SYCL_EXTERNAL to be applied to a function with raw pointers #861

Merged
merged 4 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ def OpenMPLoopForm : DiagGroup<"openmp-loop-form">;
def OpenMPTarget : DiagGroup<"openmp-target">;

// SYCL warnings
def SyclStrict : DiagGroup<"sycl-strict">;
def SyclTarget : DiagGroup<"sycl-target">;

// Backend warnings.
Expand Down
9 changes: 6 additions & 3 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10120,9 +10120,12 @@ def err_conflicting_sycl_kernel_attributes : Error<
def err_sycl_attibute_cannot_be_applied_here
: Error<"%0 attribute cannot be applied to a "
"%select{static function or function in an anonymous namespace"
"|class member function"
"|function with a raw pointer return type"
"|function with a raw pointer parameter type}1">;
"|class member function}1">;
def warn_sycl_attibute_function_raw_ptr
: Warning<"SYCL 1.2.1 specification does not allow %0 attribute applied "
"to a function with a raw pointer "
"%select{return type|parameter type}1">,
InGroup<SyclStrict>, DefaultError;
def err_ivdep_duplicate_arg : Error<
"duplicate argument to 'ivdep'. attribute requires one or both of a safelen "
"and array">;
Expand Down
10 changes: 4 additions & 6 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4329,15 +4329,13 @@ static void handleSYCLDeviceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
return;
}
if (FD->getReturnType()->isPointerType()) {
S.Diag(AL.getLoc(), diag::err_sycl_attibute_cannot_be_applied_here)
<< AL << 2 /* function with a raw pointer return type */;
return;
S.Diag(AL.getLoc(), diag::warn_sycl_attibute_function_raw_ptr)
<< AL << 0 /* function with a raw pointer return type */;
}
for (const ParmVarDecl *Param : FD->parameters())
if (Param->getType()->isPointerType()) {
S.Diag(AL.getLoc(), diag::err_sycl_attibute_cannot_be_applied_here)
<< AL << 3 /* function with a raw pointer parameter type */;
return;
S.Diag(AL.getLoc(), diag::warn_sycl_attibute_function_raw_ptr)
<< AL << 1 /* function with a raw pointer parameter type */;
}

S.addSyclDeviceDecl(D);
Expand Down
20 changes: 18 additions & 2 deletions clang/test/SemaSYCL/sycl-device.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify %s
// RUN: %clang_cc1 -verify -DNO_SYCL %s

// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify -DNOT_STRICT -Wno-error=sycl-strict -Wno-sycl-strict %s
bader marked this conversation as resolved.
Show resolved Hide resolved
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify -DWARN_STRICT -Wno-error=sycl-strict %s

#ifndef NO_SYCL

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

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

__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a function with a raw pointer parameter type}}
__attribute__((sycl_device))
void func3(int *) {}
#elif defined(WARN_STRICT)
__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}}
int* func3() { return nullptr; }

__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}}
void func3(int *) {}
#else
__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}}
int* func3() { return nullptr; }

__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}}
void func3(int *) {}
#endif

#else // NO_SYCL
__attribute__((sycl_device)) // expected-warning {{'sycl_device' attribute ignored}}
void baz() {}

Expand Down