[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:49:32 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:

I mentioned global variables are just one example; we don't want to emit anything that follows the current point of check unless it is explicitly used. I understand the concern, but I think the code is right as is. I suggest we stay with the currently proposed change for now and revisit how to handle this better if a need for more fine-grained selections emerges. Note that DPC++ hasn't demonstrated such a need so far.

I do think adding a comment would be helpful though.

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


More information about the cfe-commits mailing list