Skip to content

Commit 0098eab

Browse files
authored
[SYCL] Fix FE attribute handling in SYCL_EXTERNAL functions. (#1778)
SYCL_EXTERNAL functions are not included into the device declarations set which is iterated during SYCL attribute propagation and checking. Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
1 parent 88d2031 commit 0098eab

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10825,7 +10825,7 @@ def err_sycl_non_std_layout_type : Error<
1082510825
def err_sycl_non_constant_array_type : Error<
1082610826
"kernel parameter is not a constant size array %0">;
1082710827
def err_conflicting_sycl_kernel_attributes : Error<
10828-
"conflicting attributes applied to a SYCL kernel">;
10828+
"conflicting attributes applied to a SYCL kernel or SYCL_EXTERNAL function">;
1082910829
def err_conflicting_sycl_function_attributes : Error<
1083010830
"%0 attribute conflicts with '%1' attribute">;
1083110831
def err_sycl_x_y_z_arguments_must_be_one : Error<

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12582,7 +12582,7 @@ class Sema final {
1258212582
private:
1258312583
// We store SYCL Kernels here and handle separately -- which is a hack.
1258412584
// FIXME: It would be best to refactor this.
12585-
SmallVector<Decl*, 4> SyclDeviceDecls;
12585+
llvm::SetVector<Decl *> SyclDeviceDecls;
1258612586
// SYCL integration header instance for current compilation unit this Sema
1258712587
// is associated with.
1258812588
std::unique_ptr<SYCLIntegrationHeader> SyclIntHeader;
@@ -12593,8 +12593,8 @@ class Sema final {
1259312593
bool ConstructingOpenCLKernel = false;
1259412594

1259512595
public:
12596-
void addSyclDeviceDecl(Decl *d) { SyclDeviceDecls.push_back(d); }
12597-
SmallVectorImpl<Decl *> &syclDeviceDecls() { return SyclDeviceDecls; }
12596+
void addSyclDeviceDecl(Decl *d) { SyclDeviceDecls.insert(d); }
12597+
llvm::SetVector<Decl *> &syclDeviceDecls() { return SyclDeviceDecls; }
1259812598

1259912599
/// Lazily creates and returns SYCL integration header instance.
1260012600
SYCLIntegrationHeader &getSyclIntegrationHeader() {

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,15 @@ void Sema::MarkDevice(void) {
16171617
// it is recursive.
16181618
MarkDeviceFunction Marker(*this);
16191619
Marker.SYCLCG.addToCallGraph(getASTContext().getTranslationUnitDecl());
1620+
1621+
// Iterate through SYCL_EXTERNAL functions and add them to the device decls.
1622+
for (const auto &entry : *Marker.SYCLCG.getRoot()) {
1623+
if (auto *FD = dyn_cast<FunctionDecl>(entry.Callee->getDecl())) {
1624+
if (FD->hasAttr<SYCLDeviceAttr>() && !FD->hasAttr<SYCLKernelAttr>())
1625+
addSyclDeviceDecl(FD);
1626+
}
1627+
}
1628+
16201629
for (Decl *D : syclDeviceDecls()) {
16211630
if (auto SYCLKernel = dyn_cast<FunctionDecl>(D)) {
16221631
llvm::SmallPtrSet<FunctionDecl *, 10> VisitedSet;

clang/test/SemaSYCL/reqd-sub-group-size-device.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ void bar() {
4848
kernel<class kernel_name5>([]() [[cl::intel_reqd_sub_group_size(2)]] { });
4949
}
5050

51+
#ifdef TRIGGER_ERROR
52+
// expected-note@+1 {{conflicting attribute is here}}
53+
[[cl::intel_reqd_sub_group_size(2)]] void sg_size2() {}
54+
55+
// expected-note@+2 {{conflicting attribute is here}}
56+
// expected-error@+1 {{conflicting attributes applied to a SYCL kernel}}
57+
[[cl::intel_reqd_sub_group_size(4)]] __attribute__((sycl_device)) void sg_size4() {
58+
sg_size2();
59+
}
60+
#endif
61+
5162
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1
5263
// CHECK: IntelReqdSubGroupSizeAttr {{.*}}
5364
// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}}

0 commit comments

Comments
 (0)