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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 23 12:48:29 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>())
----------------
erichkeane wrote:

An additional thought after clicking 'start-review':  Perhaps something like:

```
// Comment explaining that on a sycl device, the ONLY thing we emit is functions (not variables), and ONLY those that have one of these two attributes.
if (LangOpts.SYCLIsDevice)
return isa<FunctionDecl>(D) && (D->hasAttr<...>() || D->hasAttr<....>());
```

I'm realizing as I look through this more, part of my problem is the vascus relationship between this section, the fact that these two attributes are only legal on a function decl, and the part on line 12948.  So there are three sizable parts of logic scattered around the program that makes this REALLY awful to figure out.

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


More information about the cfe-commits mailing list