[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
Fri Jul 11 11:53:35 PDT 2025


================
@@ -4084,6 +4084,19 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
            diag::note_carries_dependency_missing_first_decl) << 0/*Function*/;
     }
 
+    // SYCL spec 2020
+    //   The first declaration of a function with external linkage must
+    //   specify sycl_external attribute.
+    //   Subsequent declarations may optionally specify this attribute.
+    if (LangOpts.SYCLIsDevice) {
+      const SYCLExternalAttr *SEA = New->getAttr<SYCLExternalAttr>();
+      if (SEA && !Old->hasAttr<SYCLExternalAttr>()) {
+        Diag(SEA->getLocation(), diag::err_sycl_attribute_missing_on_first_decl)
+            << SEA;
----------------
tahonermann wrote:

Inline with my other comment regarding using the existing first-decl diagnostic:
```suggestion
        Diag(SEA->getLocation(), diag::err_attribute_missing_on_first_decl)
            << SEA;
```

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


More information about the cfe-commits mailing list