Skip to content

Commit 9de4e06

Browse files
authored
[SYCL] Restrict the sycl_kernel_entry_point attribute spelling to C++11 style. (#151405)
Previously, the `sycl_kernel_entry_point` attribute could be specified using either the GNU or C++11 spelling styles. Future SYCL attributes are expected to support only the C++11 spelling style, so support for the GNU style is being removed. In order to ensure consistent presentation of the attribute in diagnostic messages, diagnostics specific to this attribute now require the attribute to be provided as an argument. This delegates formatting of the attribute name to the diagnostic engine. As an additional nicety, "the" is added to some diagnostic messages so that they read more like proper sentences.
1 parent 49d89bc commit 9de4e06

10 files changed

+84
-78
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ def DeviceKernel : DeclOrTypeAttr {
16421642
}
16431643

16441644
def SYCLKernelEntryPoint : InheritableAttr {
1645-
let Spellings = [Clang<"sycl_kernel_entry_point">];
1645+
let Spellings = [CXX11<"clang", "sycl_kernel_entry_point">];
16461646
let Args = [
16471647
// KernelName is required and specifies the kernel name type.
16481648
TypeArgument<"KernelName">,

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12936,31 +12936,29 @@ def err_sycl_special_type_num_init_method : Error<
1293612936

1293712937
// SYCL kernel entry point diagnostics
1293812938
def err_sycl_entry_point_invalid : Error<
12939-
"'sycl_kernel_entry_point' attribute cannot be applied to a"
12939+
"the %0 attribute cannot be applied to a"
1294012940
" %select{non-static member function|variadic function|deleted function|"
1294112941
"defaulted function|constexpr function|consteval function|"
1294212942
"function declared with the 'noreturn' attribute|coroutine|"
12943-
"function defined with a function try block}0">;
12943+
"function defined with a function try block}1">;
1294412944
def err_sycl_entry_point_invalid_redeclaration : Error<
12945-
"'sycl_kernel_entry_point' kernel name argument does not match prior"
12946-
" declaration%diff{: $ vs $|}0,1">;
12945+
"the %0 kernel name argument does not match prior"
12946+
" declaration%diff{: $ vs $|}1,2">;
1294712947
def err_sycl_kernel_name_conflict : Error<
12948-
"'sycl_kernel_entry_point' kernel name argument conflicts with a previous"
12949-
" declaration">;
12948+
"the %0 kernel name argument conflicts with a previous declaration">;
1295012949
def warn_sycl_kernel_name_not_a_class_type : Warning<
1295112950
"%0 is not a valid SYCL kernel name type; a non-union class type is required">,
1295212951
InGroup<DiagGroup<"nonportable-sycl">>, DefaultError;
1295312952
def warn_sycl_entry_point_redundant_declaration : Warning<
12954-
"redundant 'sycl_kernel_entry_point' attribute">, InGroup<RedundantAttribute>;
12953+
"redundant %0 attribute">, InGroup<RedundantAttribute>;
1295512954
def err_sycl_entry_point_after_definition : Error<
12956-
"'sycl_kernel_entry_point' attribute cannot be added to a function after the"
12957-
" function is defined">;
12955+
"the %0 attribute cannot be added to a function after the function is"
12956+
" defined">;
1295812957
def err_sycl_entry_point_return_type : Error<
12959-
"'sycl_kernel_entry_point' attribute only applies to functions with a"
12960-
" 'void' return type">;
12958+
"the %0 attribute only applies to functions with a 'void' return type">;
1296112959
def err_sycl_entry_point_deduced_return_type : Error<
12962-
"'sycl_kernel_entry_point' attribute only applies to functions with a"
12963-
" non-deduced 'void' return type">;
12960+
"the %0 attribute only applies to functions with a non-deduced 'void' return"
12961+
" type">;
1296412962

1296512963
def warn_cuda_maxclusterrank_sm_90 : Warning<
1296612964
"maxclusterrank requires sm_90 or higher, CUDA arch provided: %0, ignoring "

clang/lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,7 +3063,8 @@ static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old) {
30633063
// error since the definition will have already been created without
30643064
// the semantic effects of the attribute having been applied.
30653065
S.Diag(NewAttribute->getLocation(),
3066-
diag::err_sycl_entry_point_after_definition);
3066+
diag::err_sycl_entry_point_after_definition)
3067+
<< NewAttribute;
30673068
S.Diag(Def->getLocation(), diag::note_previous_definition);
30683069
cast<SYCLKernelEntryPointAttr>(NewAttribute)->setInvalidAttr();
30693070
++I;
@@ -16258,19 +16259,19 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1625816259
FD->getAttr<SYCLKernelEntryPointAttr>();
1625916260
if (FD->isDefaulted()) {
1626016261
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
16261-
<< /*defaulted function*/ 3;
16262+
<< SKEPAttr << /*defaulted function*/ 3;
1626216263
SKEPAttr->setInvalidAttr();
1626316264
} else if (FD->isDeleted()) {
1626416265
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
16265-
<< /*deleted function*/ 2;
16266+
<< SKEPAttr << /*deleted function*/ 2;
1626616267
SKEPAttr->setInvalidAttr();
1626716268
} else if (FSI->isCoroutine()) {
1626816269
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
16269-
<< /*coroutine*/ 7;
16270+
<< SKEPAttr << /*coroutine*/ 7;
1627016271
SKEPAttr->setInvalidAttr();
1627116272
} else if (Body && isa<CXXTryStmt>(Body)) {
1627216273
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
16273-
<< /*function defined with a function try block*/ 8;
16274+
<< SKEPAttr << /*function defined with a function try block*/ 8;
1627416275
SKEPAttr->setInvalidAttr();
1627516276
}
1627616277

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,13 @@ void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
262262
if (!getASTContext().hasSameType(SAI->getKernelName(),
263263
SKEPAttr->getKernelName())) {
264264
Diag(SAI->getLocation(), diag::err_sycl_entry_point_invalid_redeclaration)
265-
<< SAI->getKernelName() << SKEPAttr->getKernelName();
265+
<< SKEPAttr << SAI->getKernelName() << SKEPAttr->getKernelName();
266266
Diag(SKEPAttr->getLocation(), diag::note_previous_attribute);
267267
SAI->setInvalidAttr();
268268
} else {
269269
Diag(SAI->getLocation(),
270-
diag::warn_sycl_entry_point_redundant_declaration);
270+
diag::warn_sycl_entry_point_redundant_declaration)
271+
<< SAI;
271272
Diag(SKEPAttr->getLocation(), diag::note_previous_attribute);
272273
}
273274
}
@@ -289,7 +290,8 @@ void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
289290
PrevSKEPAttr->getKernelName())) {
290291
Diag(SKEPAttr->getLocation(),
291292
diag::err_sycl_entry_point_invalid_redeclaration)
292-
<< SKEPAttr->getKernelName() << PrevSKEPAttr->getKernelName();
293+
<< SKEPAttr << SKEPAttr->getKernelName()
294+
<< PrevSKEPAttr->getKernelName();
293295
Diag(PrevSKEPAttr->getLocation(), diag::note_previous_decl) << PrevFD;
294296
SKEPAttr->setInvalidAttr();
295297
}
@@ -299,50 +301,52 @@ void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
299301
if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
300302
if (!MD->isStatic()) {
301303
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
302-
<< /*non-static member function*/ 0;
304+
<< SKEPAttr << /*non-static member function*/ 0;
303305
SKEPAttr->setInvalidAttr();
304306
}
305307
}
306308

307309
if (FD->isVariadic()) {
308310
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
309-
<< /*variadic function*/ 1;
311+
<< SKEPAttr << /*variadic function*/ 1;
310312
SKEPAttr->setInvalidAttr();
311313
}
312314

313315
if (FD->isDefaulted()) {
314316
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
315-
<< /*defaulted function*/ 3;
317+
<< SKEPAttr << /*defaulted function*/ 3;
316318
SKEPAttr->setInvalidAttr();
317319
} else if (FD->isDeleted()) {
318320
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
319-
<< /*deleted function*/ 2;
321+
<< SKEPAttr << /*deleted function*/ 2;
320322
SKEPAttr->setInvalidAttr();
321323
}
322324

323325
if (FD->isConsteval()) {
324326
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
325-
<< /*consteval function*/ 5;
327+
<< SKEPAttr << /*consteval function*/ 5;
326328
SKEPAttr->setInvalidAttr();
327329
} else if (FD->isConstexpr()) {
328330
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
329-
<< /*constexpr function*/ 4;
331+
<< SKEPAttr << /*constexpr function*/ 4;
330332
SKEPAttr->setInvalidAttr();
331333
}
332334

333335
if (FD->isNoReturn()) {
334336
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
335-
<< /*function declared with the 'noreturn' attribute*/ 6;
337+
<< SKEPAttr << /*function declared with the 'noreturn' attribute*/ 6;
336338
SKEPAttr->setInvalidAttr();
337339
}
338340

339341
if (FD->getReturnType()->isUndeducedType()) {
340342
Diag(SKEPAttr->getLocation(),
341-
diag::err_sycl_entry_point_deduced_return_type);
343+
diag::err_sycl_entry_point_deduced_return_type)
344+
<< SKEPAttr;
342345
SKEPAttr->setInvalidAttr();
343346
} else if (!FD->getReturnType()->isDependentType() &&
344347
!FD->getReturnType()->isVoidType()) {
345-
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_return_type);
348+
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_return_type)
349+
<< SKEPAttr;
346350
SKEPAttr->setInvalidAttr();
347351
}
348352

@@ -354,7 +358,8 @@ void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
354358
if (!declaresSameEntity(FD, SKI->getKernelEntryPointDecl())) {
355359
// FIXME: This diagnostic should include the origin of the kernel
356360
// FIXME: names; not just the locations of the conflicting declarations.
357-
Diag(FD->getLocation(), diag::err_sycl_kernel_name_conflict);
361+
Diag(FD->getLocation(), diag::err_sycl_kernel_name_conflict)
362+
<< SKEPAttr;
358363
Diag(SKI->getKernelEntryPointDecl()->getLocation(),
359364
diag::note_previous_declaration);
360365
SKEPAttr->setInvalidAttr();

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,8 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
11471147
const SYCLKernelInfo *SKI = C.findSYCLKernelInfo(SKEPAttr->getKernelName());
11481148
if (SKI) {
11491149
if (!declaresSameEntity(FD, SKI->getKernelEntryPointDecl())) {
1150-
Reader.Diag(FD->getLocation(), diag::err_sycl_kernel_name_conflict);
1150+
Reader.Diag(FD->getLocation(), diag::err_sycl_kernel_name_conflict)
1151+
<< SKEPAttr;
11511152
Reader.Diag(SKI->getKernelEntryPointDecl()->getLocation(),
11521153
diag::note_previous_declaration);
11531154
SKEPAttr->setInvalidAttr();

clang/test/ASTSYCL/ast-dump-sycl-kernel-entry-point.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@
2828
// A unique kernel name type is required for each declared kernel entry point.
2929
template<int, int=0> struct KN;
3030

31-
__attribute__((sycl_kernel_entry_point(KN<1>)))
31+
[[clang::sycl_kernel_entry_point(KN<1>)]]
3232
void skep1() {
3333
}
3434
// CHECK: |-FunctionDecl {{.*}} skep1 'void ()'
3535
// CHECK: | `-SYCLKernelEntryPointAttr {{.*}} KN<1>
3636

3737
using KN2 = KN<2>;
38-
__attribute__((sycl_kernel_entry_point(KN2)))
38+
[[clang::sycl_kernel_entry_point(KN2)]]
3939
void skep2() {
4040
}
4141
// CHECK: |-FunctionDecl {{.*}} skep2 'void ()'
4242
// CHECK: | `-SYCLKernelEntryPointAttr {{.*}} KN2
4343

4444
template<int I> using KNT = KN<I>;
45-
__attribute__((sycl_kernel_entry_point(KNT<3>)))
45+
[[clang::sycl_kernel_entry_point(KNT<3>)]]
4646
void skep3() {
4747
}
4848
// CHECK: |-FunctionDecl {{.*}} skep3 'void ()'

0 commit comments

Comments
 (0)