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] Report deferred diagnostics in function templates #5114

Merged
merged 8 commits into from
Jan 21, 2022
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
9 changes: 8 additions & 1 deletion clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1770,8 +1770,15 @@ class DeferredDiagnosticsEmitter
// Emit any deferred diagnostics for FD
void emitDeferredDiags(FunctionDecl *FD, bool ShowCallStack) {
auto It = S.DeviceDeferredDiags.find(FD);
if (It == S.DeviceDeferredDiags.end())
if (It == S.DeviceDeferredDiags.end()) {
Fznamznon marked this conversation as resolved.
Show resolved Hide resolved
// If this is a template instantiation, check if its declaration
// is on the deferred diagnostics stack.
if (FD->isTemplateInstantiation()) {
FD = FD->getTemplateInstantiationPattern();
emitDeferredDiags(FD, ShowCallStack);
}
return;
}
bool HasWarningOrError = false;
bool FirstDiag = true;
for (Sema::DeviceDeferredDiagnostic &D : It->second) {
Expand Down
14 changes: 0 additions & 14 deletions clang/test/CodeGenSYCL/static-var-address-space.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
#include "Inputs/sycl.hpp"
struct C {
static int c;
};

template <typename T>
struct D {
static T d;
};

template <typename T>
void test() {
// CHECK: @_ZZ4testIiEvvE1a = linkonce_odr addrspace(1) constant i32 0, comdat, align 4
static const int a = 0;
// CHECK: @_ZZ4testIiEvvE1b = linkonce_odr addrspace(1) constant i32 0, comdat, align 4
static const T b = T(0);
// CHECK: @_ZN1C1cE = external addrspace(1) global i32, align 4
C::c = 10;
const C struct_c;
// CHECK: @_ZN1DIiE1dE = external addrspace(1) global i32, align 4
D<int>::d = 11;
const D<int> struct_d;
}

int main() {
Expand Down
22 changes: 22 additions & 0 deletions clang/test/SemaSYCL/sycl-device-const-static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,34 @@ void usage() {

template <typename Name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
// expected-error@+1{{SYCL kernel cannot use a non-const static data variable}}
Fznamznon marked this conversation as resolved.
Show resolved Hide resolved
static int z;
// expected-note-re@+3{{called by 'kernel_single_task<fake_kernel, (lambda at {{.*}})>}}
// expected-note-re@+2{{called by 'kernel_single_task<fake_kernel, (lambda at {{.*}})>}}
// expected-error@+1{{SYCL kernel cannot use a const static or global variable that is neither zero-initialized nor constant-initialized}}
kernelFunc(U<Base>::s2);
}

struct C {
static int c;
};

template <typename T>
struct D {
static T d;
};

template <typename T>
T D<T>::d = T();

template <typename T>
void test() {
// expected-error@+1{{SYCL kernel cannot use a non-const static data variable}}
C::c = 10;
// expected-error@+1{{SYCL kernel cannot use a non-const static data variable}}
D<int>::d = 11;
}

int main() {
static int s2;
kernel_single_task<class fake_kernel>([](S s4) {
Expand All @@ -66,6 +87,7 @@ int main() {
s4.foo();
// expected-error@+1{{SYCL kernel cannot use a non-const static data variable}}
static int s3;
test<int>();
});

return 0;
Expand Down
25 changes: 25 additions & 0 deletions clang/test/SemaSYCL/sycl-device-template-diag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %clang_cc1 -fsycl-is-device -verify -Wno-sycl-2017-compat -fsyntax-only %s -internal-isystem %S/Inputs

// This test verifies that we generate deferred diagnostics when
// such diagnostics are in a function template.

#include "sycl.hpp"

using namespace cl::sycl;
queue q;

int global_value = -1;

template <typename T>
void kernel_wrapper() {
q.submit([&](handler &h) {
h.single_task([=] {
// expected-error@+1{{SYCL kernel cannot use a non-const global variable}}
(void)global_value;
});
});
}

int main() {
kernel_wrapper<int>();
}
8 changes: 3 additions & 5 deletions clang/test/SemaSYCL/wrong-address-taking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ void basicUsage() {

template <typename T> void templatedContext() {

// FIXME: this is likely not diagnosed because of a common problem among
// deferred diagnostics. They don't work from templated context if the
// problematic code doesn't depend on a template parameter. See
// https://github.com/intel/llvm/pull/5114 for an explanation of the problem
// and possible solution.
// expected-error@+1 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
int (*p)(int) = &badFoo;
// expected-error@+1 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
auto p1 = &ForMembers::badMember;

// expected-error@+2 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
// expected-note@+1 {{called by 'templatedContext<int>'}}
templateCaller1<badFoo>(1);
}
Expand Down