-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[Clang][SYCL] Modify err_sycl_entry_point_invalid to use %enum_select. #173122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Clang][SYCL] Modify err_sycl_entry_point_invalid to use %enum_select. #173122
Conversation
The `err_sycl_entry_point_invalid` diagnostic has a selection field for which there are already many options with more expected to be added. Use of %enum_select avoids the need for magic numbers with associated comments at source locations where the diagnostic is issued.
|
@llvm/pr-subscribers-clang Author: Tom Honermann (tahonermann) ChangesThe Full diff: https://github.com/llvm/llvm-project/pull/173122.diff 3 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 51b6eba965103..c9902a372e846 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -13170,11 +13170,17 @@ def warn_sycl_external_missing_on_first_decl : Warning<
// SYCL kernel entry point diagnostics
def err_sycl_entry_point_invalid : Error<
- "the %0 attribute cannot be applied to a"
- " %select{non-static member function|variadic function|deleted function|"
- "defaulted function|constexpr function|consteval function|"
- "function declared with the 'noreturn' attribute|coroutine|"
- "function defined with a function try block}1">;
+ "the %0 attribute cannot be applied to a %enum_select<InvalidSKEPReason>{"
+ "%NonStaticMemberFn{non-static member function}|"
+ "%VariadicFn{variadic function}|"
+ "%DeletedFn{deleted function}|"
+ "%DefaultedFn{defaulted function}|"
+ "%ConstexprFn{constexpr function}|"
+ "%ConstevalFn{consteval function}|"
+ "%NoreturnFn{function declared with the 'noreturn' attribute}|"
+ "%Coroutine{coroutine}|"
+ "%FunctionTryBlock{function defined with a function try block}"
+ "}1">;
def err_sycl_entry_point_invalid_redeclaration : Error<
"the %0 kernel name argument does not match prior"
" declaration%diff{: $ vs $|}1,2">;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 72039cc164d88..5da665a5acad2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16468,19 +16468,19 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, bool IsInstantiation,
FD->getAttr<SYCLKernelEntryPointAttr>();
if (FD->isDefaulted()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*defaulted function*/ 3;
+ << SKEPAttr << diag::InvalidSKEPReason::DefaultedFn;
SKEPAttr->setInvalidAttr();
} else if (FD->isDeleted()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*deleted function*/ 2;
+ << SKEPAttr << diag::InvalidSKEPReason::DeletedFn;
SKEPAttr->setInvalidAttr();
} else if (FSI->isCoroutine()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*coroutine*/ 7;
+ << SKEPAttr << diag::InvalidSKEPReason::Coroutine;
SKEPAttr->setInvalidAttr();
} else if (Body && isa<CXXTryStmt>(Body)) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*function defined with a function try block*/ 8;
+ << SKEPAttr << diag::InvalidSKEPReason::FunctionTryBlock;
SKEPAttr->setInvalidAttr();
}
diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp
index 67f3856c10615..280f9b1a4b42d 100644
--- a/clang/lib/Sema/SemaSYCL.cpp
+++ b/clang/lib/Sema/SemaSYCL.cpp
@@ -318,40 +318,40 @@ void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
if (!MD->isStatic()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*non-static member function*/ 0;
+ << SKEPAttr << diag::InvalidSKEPReason::NonStaticMemberFn;
SKEPAttr->setInvalidAttr();
}
}
if (FD->isVariadic()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*variadic function*/ 1;
+ << SKEPAttr << diag::InvalidSKEPReason::VariadicFn;
SKEPAttr->setInvalidAttr();
}
if (FD->isDefaulted()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*defaulted function*/ 3;
+ << SKEPAttr << diag::InvalidSKEPReason::DefaultedFn;
SKEPAttr->setInvalidAttr();
} else if (FD->isDeleted()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*deleted function*/ 2;
+ << SKEPAttr << diag::InvalidSKEPReason::DeletedFn;
SKEPAttr->setInvalidAttr();
}
if (FD->isConsteval()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*consteval function*/ 5;
+ << SKEPAttr << diag::InvalidSKEPReason::ConstevalFn;
SKEPAttr->setInvalidAttr();
} else if (FD->isConstexpr()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*constexpr function*/ 4;
+ << SKEPAttr << diag::InvalidSKEPReason::ConstexprFn;
SKEPAttr->setInvalidAttr();
}
if (FD->isNoReturn()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*function declared with the 'noreturn' attribute*/ 6;
+ << SKEPAttr << diag::InvalidSKEPReason::NoreturnFn;
SKEPAttr->setInvalidAttr();
}
|
The
err_sycl_entry_point_invaliddiagnostic has a selection field for which there are already many options with more expected to be added. Use of%enum_selectavoids the need for magic numbers with associated comments at source locations where the diagnostic is issued.