[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
Wed Jul 23 10:26:38 PDT 2025


================
@@ -12937,6 +12937,10 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
   if (D->hasAttr<WeakRefAttr>())
     return false;
 
+  if (LangOpts.SYCLIsDevice && !D->hasAttr<SYCLKernelEntryPointAttr>() &&
+      !D->hasAttr<SYCLExternalAttr>())
----------------
tahonermann wrote:

That is intentional and consistent with what DPC++ does for its `sycl_device` attribute; see https://github.com/intel/llvm/blob/a70552b59fd4f91b2d80d755aedcd9e93ae61ee1/clang/lib/AST/ASTContext.cpp#L13068-L13070. For example, global variables shouldn't be emitted in device code.

It might be worth adding a comment that explains this though.

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


More information about the cfe-commits mailing list