Skip to content

Commit 49c747c

Browse files
committed
Add diagnostics for conflicting attributes from transitive calls
1 parent eb3a32e commit 49c747c

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,33 @@ void Sema::MarkDevice(void) {
20272027
Diag(Attr->getLocation(), diag::note_conflicting_attribute);
20282028
SYCLKernel->setInvalidDecl();
20292029
}
2030+
} else if (auto *Existing = SYCLKernel->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
2031+
if (Existing->getXDim() < Attr->getXDim() ||
2032+
Existing->getYDim() < Attr->getYDim() ||
2033+
Existing->getZDim() < Attr->getZDim()) {
2034+
Diag(SYCLKernel->getLocation(),
2035+
diag::err_conflicting_sycl_kernel_attributes);
2036+
Diag(Existing->getLocation(), diag::note_conflicting_attribute);
2037+
Diag(Attr->getLocation(), diag::note_conflicting_attribute);
2038+
SYCLKernel->setInvalidDecl();
2039+
}
2040+
} else {
2041+
SYCLKernel->addAttr(A);
2042+
}
2043+
break;
2044+
}
2045+
case attr::Kind::SYCLIntelMaxWorkGroupSize: {
2046+
auto *Attr = cast<SYCLIntelMaxWorkGroupSizeAttr>(A);
2047+
if (auto *Existing = SYCLKernel->getAttr<ReqdWorkGroupSizeAttr>()) {
2048+
if (Existing->getXDim() > Attr->getXDim() ||
2049+
Existing->getYDim() > Attr->getYDim() ||
2050+
Existing->getZDim() > Attr->getZDim()) {
2051+
Diag(SYCLKernel->getLocation(),
2052+
diag::err_conflicting_sycl_kernel_attributes);
2053+
Diag(Existing->getLocation(), diag::note_conflicting_attribute);
2054+
Diag(Attr->getLocation(), diag::note_conflicting_attribute);
2055+
SYCLKernel->setInvalidDecl();
2056+
}
20302057
} else {
20312058
SYCLKernel->addAttr(A);
20322059
}
@@ -2035,7 +2062,6 @@ void Sema::MarkDevice(void) {
20352062
case attr::Kind::SYCLIntelKernelArgsRestrict:
20362063
case attr::Kind::SYCLIntelNumSimdWorkItems:
20372064
case attr::Kind::SYCLIntelMaxGlobalWorkDim:
2038-
case attr::Kind::SYCLIntelMaxWorkGroupSize:
20392065
case attr::Kind::SYCLIntelNoGlobalWorkOffset:
20402066
case attr::Kind::SYCLSimd: {
20412067
if ((A->getKind() == attr::Kind::SYCLSimd) && KernelBody &&
Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
1+
// RUN: %clang_cc1 %s -fsyntax-only -fsycl -fsycl-is-device -triple spir64 -verify
2+
// RUN: %clang_cc1 %s -fsyntax-only -fsycl -fsycl-is-device -triple spir64 -DTRIGGER_ERROR -verify
13
// RUN: %clang_cc1 %s -fsyntax-only -ast-dump -fsycl -fsycl-is-device -triple spir64 | FileCheck %s
24

3-
[[intelfpga::no_global_work_offset]] void not_direct() {}
5+
#ifndef TRIGGER_ERROR
6+
[[intelfpga::no_global_work_offset]] void not_direct_one() {} // expected-no-diagnostics
47

5-
void func() { not_direct(); }
8+
[[cl::intel_reqd_sub_group_size(1)]] void func_one() {
9+
not_direct_one();
10+
}
11+
12+
#else
13+
[[cl::reqd_work_group_size(2, 2, 2)]] void not_direct_two() {} // expected-note {{conflicting attribute is here}}
14+
15+
[[intelfpga::max_work_group_size(1, 1, 1)]] // expected-note {{conflicting attribute is here}}
16+
void
17+
func_two() {
18+
not_direct_two();
19+
}
20+
21+
[[cl::reqd_work_group_size(4, 4, 4)]] // expected-note 2 {{conflicting attribute is here}}
22+
void
23+
func_three() {
24+
not_direct_two();
25+
}
26+
#endif
627

728
template <typename Name, typename Type>
829
[[clang::sycl_kernel]] void __my_kernel__(Type bar) {
930
bar();
10-
func();
31+
#ifndef TRIGGER_ERROR
32+
func_one();
33+
#else
34+
func_two();
35+
func_three();
36+
#endif
1137
}
1238

1339
template <typename Name, typename Type>
@@ -16,8 +42,13 @@ void parallel_for(Type lambda) {
1642
}
1743

1844
void invoke_foo2() {
45+
#ifndef TRIGGER_ERROR
1946
// CHECK-LABEL: FunctionDecl {{.*}} invoke_foo2 'void ()'
2047
// CHECK: `-FunctionDecl {{.*}}KernelName 'void ()'
21-
// CHECK: -SYCLIntelNoGlobalWorkOffsetAttr {{.*}} Enabled
48+
// CHECK: -IntelReqdSubGroupSizeAttr {{.*}}
49+
// CHECK: `-SYCLIntelNoGlobalWorkOffsetAttr {{.*}} Enabled
2250
parallel_for<class KernelName>([]() {});
51+
#else
52+
parallel_for<class KernelName>([]() {}); // expected-error 2 {{conflicting attributes applied to a SYCL kernel or SYCL_EXTERNAL function}}
53+
#endif
2354
}

0 commit comments

Comments
 (0)