[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:55:43 PDT 2025


================
@@ -12251,6 +12264,9 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
   if (NewFD->hasAttr<SYCLKernelEntryPointAttr>())
     SYCL().CheckSYCLEntryPointFunctionDecl(NewFD);
 
+  if (NewFD->hasAttr<SYCLExternalAttr>())
+    SYCL().CheckSYCLExternalFunctionDecl(NewFD);
----------------
erichkeane wrote:

> Linkage, or rather, external visibility, which is what we actually check, can depend on other attributes like `VisibilityAttr`. Checking here ensures that all attributes have been processed and therefore avoids visitation ordering issues.
> 
> The attribute is allowed on function templates and is automatically inherited by (implicit and explicit) instantiations (and explicit specializations which is incorrect according to the C++ standard). I don't think there is anything to do to handle instantiation.
> 
> We do have a testing gap to address yet though. We have good tests for diagnostics, but are missing a test to validate which symbols are actually emitted. We'll ensure that test exercises function templates.

Ah, I see, the visibility attribute makes sense here, thank you for looking into that.

>I don't think there is anything to do to handle instantiation.

We've had to do some work in the past for attribute instantiation, though simple ones might be automatic.  Can you make sure that specializations/partial specializations are properly tested?  And diagnose if linkage isn't right?





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


More information about the cfe-commits mailing list