[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

Tom Honermann via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 24 10:31:45 PDT 2025


================
@@ -208,6 +208,15 @@ void SemaSYCL::handleExternalAttr(Decl *D, const ParsedAttr &AL) {
     Diag(AL.getLoc(), diag::err_sycl_attribute_invalid_linkage);
     return;
   }
+  std::string FunctionName = StringRef(FD->getNameInfo().getAsString()).lower();
+  if (FunctionName.find("main") != std::string::npos) {
+    Diag(AL.getLoc(), diag::err_sycl_attribute_avoid_main);
+    return;
+  }
----------------
tahonermann wrote:

I think the check for application to `main()` is better done in `Sema::CheckMain()`. See the other diagnostics there that call `Diag` with a `diag::err*` argument. It looks like `FD->setInvalidDecl()` should also be called in that case.

https://github.com/llvm/llvm-project/pull/140282


More information about the cfe-commits mailing list