Skip to content

Commit d2e625b

Browse files
committed
[SYCL] Fix FE attribute handling in SYCL_EXTERNAL functions.
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 <[email protected]>
1 parent 0681a36 commit d2e625b

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12556,7 +12556,7 @@ class Sema final {
1255612556
private:
1255712557
// We store SYCL Kernels here and handle separately -- which is a hack.
1255812558
// FIXME: It would be best to refactor this.
12559-
SmallVector<Decl*, 4> SyclDeviceDecls;
12559+
llvm::SetVector<Decl *> SyclDeviceDecls;
1256012560
// SYCL integration header instance for current compilation unit this Sema
1256112561
// is associated with.
1256212562
std::unique_ptr<SYCLIntegrationHeader> SyclIntHeader;
@@ -12567,8 +12567,8 @@ class Sema final {
1256712567
bool ConstructingOpenCLKernel = false;
1256812568

1256912569
public:
12570-
void addSyclDeviceDecl(Decl *d) { SyclDeviceDecls.push_back(d); }
12571-
SmallVectorImpl<Decl *> &syclDeviceDecls() { return SyclDeviceDecls; }
12570+
void addSyclDeviceDecl(Decl *d) { SyclDeviceDecls.insert(d); }
12571+
llvm::SetVector<Decl *> &syclDeviceDecls() { return SyclDeviceDecls; }
1257212572

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

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,15 @@ void Sema::MarkDevice(void) {
14601460
// it is recursive.
14611461
MarkDeviceFunction Marker(*this);
14621462
Marker.SYCLCG.addToCallGraph(getASTContext().getTranslationUnitDecl());
1463+
1464+
// Iterate through SYCL_EXTERNAL functions and add them to the device decls.
1465+
for (const auto &entry : *Marker.SYCLCG.getRoot()) {
1466+
if (auto *FD = dyn_cast<FunctionDecl>(entry.Callee->getDecl())) {
1467+
if (FD->hasAttr<SYCLDeviceAttr>() && !FD->hasAttr<SYCLKernelAttr>())
1468+
addSyclDeviceDecl(FD);
1469+
}
1470+
}
1471+
14631472
for (Decl *D : syclDeviceDecls()) {
14641473
if (auto SYCLKernel = dyn_cast<FunctionDecl>(D)) {
14651474
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 {{.*}} 16
5364
// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2

0 commit comments

Comments
 (0)