[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
Thu Aug 7 15:21:42 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);
----------------
tahonermann wrote:

I debugged a bit. It looks like `getSpecializationKind()` is always returning `TSK_ImplicitInstantiation` at the point where we are checking it. I added a dump of the function declaration at the time of diagnosis and compared that to what is generated by `-Xclang -ast-dump`. Note the same addresses below, but the different specialization information.

Dumped decl:
```
FunctionDecl 0xdf89eb0 <.../sycl-external-attr.cpp:25:26, col:40> col:31 func6 'void ()' implicit_instantiation
|-TemplateArgument type '(anonymous namespace)::S6'
| `-RecordType 0xdf67730 '(anonymous namespace)::S6'
|   `-CXXRecord 0xdf67698 'S6'
`-SYCLExternalAttr 0xdf89fa8 <col:3, col:10>
```
Output from `-Xclang -ast-dump`:
```
| `-FunctionDecl 0xdf89eb0 <col:26, col:40> col:31 func6 'void ()' explicit_instantiation_definition
|   |-TemplateArgument type '(anonymous namespace)::S6'
|   | `-RecordType 0xdf67730 '(anonymous namespace)::S6'
|   |   `-CXXRecord 0xdf67698 'S6'
|   |-CompoundStmt 0xdf67b10 <col:39, col:40>
|   `-SYCLExternalAttr 0xdf89fa8 <col:3, col:10>
```

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


More information about the cfe-commits mailing list