File tree Expand file tree Collapse file tree 5 files changed +58
-20
lines changed Expand file tree Collapse file tree 5 files changed +58
-20
lines changed Original file line number Diff line number Diff line change @@ -1770,8 +1770,15 @@ class DeferredDiagnosticsEmitter
1770
1770
// Emit any deferred diagnostics for FD
1771
1771
void emitDeferredDiags (FunctionDecl *FD, bool ShowCallStack) {
1772
1772
auto It = S.DeviceDeferredDiags .find (FD);
1773
- if (It == S.DeviceDeferredDiags .end ())
1773
+ if (It == S.DeviceDeferredDiags .end ()) {
1774
+ // If this is a template instantiation, check if its declaration
1775
+ // is on the deferred diagnostics stack.
1776
+ if (FD->isTemplateInstantiation ()) {
1777
+ FD = FD->getTemplateInstantiationPattern ();
1778
+ emitDeferredDiags (FD, ShowCallStack);
1779
+ }
1774
1780
return ;
1781
+ }
1775
1782
bool HasWarningOrError = false ;
1776
1783
bool FirstDiag = true ;
1777
1784
for (Sema::DeviceDeferredDiagnostic &D : It->second ) {
Original file line number Diff line number Diff line change 1
1
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
2
2
#include " Inputs/sycl.hpp"
3
- struct C {
4
- static int c;
5
- };
6
-
7
- template <typename T>
8
- struct D {
9
- static T d;
10
- };
11
3
12
4
template <typename T>
13
5
void test () {
14
6
// CHECK: @_ZZ4testIiEvvE1a = linkonce_odr addrspace(1) constant i32 0, comdat, align 4
15
7
static const int a = 0 ;
16
8
// CHECK: @_ZZ4testIiEvvE1b = linkonce_odr addrspace(1) constant i32 0, comdat, align 4
17
9
static const T b = T (0 );
18
- // CHECK: @_ZN1C1cE = external addrspace(1) global i32, align 4
19
- C::c = 10 ;
20
- const C struct_c;
21
- // CHECK: @_ZN1DIiE1dE = external addrspace(1) global i32, align 4
22
- D<int >::d = 11 ;
23
- const D<int > struct_d;
24
10
}
25
11
26
12
int main () {
Original file line number Diff line number Diff line change @@ -51,13 +51,34 @@ void usage() {
51
51
52
52
template <typename Name, typename Func>
53
53
__attribute__ ((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
54
+ // expected-error@+1{{SYCL kernel cannot use a non-const static data variable}}
54
55
static int z;
55
56
// expected-note-re@+3{{called by 'kernel_single_task<fake_kernel, (lambda at {{.*}})>}}
56
57
// expected-note-re@+2{{called by 'kernel_single_task<fake_kernel, (lambda at {{.*}})>}}
57
58
// expected-error@+1{{SYCL kernel cannot use a const static or global variable that is neither zero-initialized nor constant-initialized}}
58
59
kernelFunc (U<Base>::s2);
59
60
}
60
61
62
+ struct C {
63
+ static int c;
64
+ };
65
+
66
+ template <typename T>
67
+ struct D {
68
+ static T d;
69
+ };
70
+
71
+ template <typename T>
72
+ T D<T>::d = T();
73
+
74
+ template <typename T>
75
+ void test () {
76
+ // expected-error@+1{{SYCL kernel cannot use a non-const static data variable}}
77
+ C::c = 10 ;
78
+ // expected-error@+1{{SYCL kernel cannot use a non-const static data variable}}
79
+ D<int >::d = 11 ;
80
+ }
81
+
61
82
int main () {
62
83
static int s2;
63
84
kernel_single_task<class fake_kernel >([](S s4) {
@@ -66,6 +87,7 @@ int main() {
66
87
s4.foo ();
67
88
// expected-error@+1{{SYCL kernel cannot use a non-const static data variable}}
68
89
static int s3;
90
+ test<int >();
69
91
});
70
92
71
93
return 0 ;
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -fsycl-is-device -verify -Wno-sycl-2017-compat -fsyntax-only %s -internal-isystem %S/Inputs
2
+
3
+ // This test verifies that we generate deferred diagnostics when
4
+ // such diagnostics are in a function template.
5
+
6
+ #include " sycl.hpp"
7
+
8
+ using namespace cl ::sycl;
9
+ queue q;
10
+
11
+ int global_value = -1 ;
12
+
13
+ template <typename T>
14
+ void kernel_wrapper () {
15
+ q.submit ([&](handler &h) {
16
+ h.single_task ([=] {
17
+ // expected-error@+1{{SYCL kernel cannot use a non-const global variable}}
18
+ (void )global_value;
19
+ });
20
+ });
21
+ }
22
+
23
+ int main () {
24
+ kernel_wrapper<int >();
25
+ }
Original file line number Diff line number Diff line change @@ -45,14 +45,12 @@ void basicUsage() {
45
45
46
46
template <typename T> void templatedContext () {
47
47
48
- // FIXME: this is likely not diagnosed because of a common problem among
49
- // deferred diagnostics. They don't work from templated context if the
50
- // problematic code doesn't depend on a template parameter. See
51
- // https://github.com/intel/llvm/pull/5114 for an explanation of the problem
52
- // and possible solution.
48
+ // expected-error@+1 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
53
49
int (*p)(int ) = &badFoo;
50
+ // expected-error@+1 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
54
51
auto p1 = &ForMembers::badMember;
55
52
53
+ // expected-error@+2 {{taking address of a function not marked with 'intel::device_indirectly_callable' attribute is not allowed in SYCL device code}}
56
54
// expected-note@+1 {{called by 'templatedContext<int>'}}
57
55
templateCaller1<badFoo>(1 );
58
56
}
You can’t perform that action at this time.
0 commit comments