[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 12:35:24 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:
Your suggested change would not be correct because it would result in declarations with `AliasAttr` or `UsedAttr` being emitted during device compilation. We could special case that check of course, but I don't think adding additional checks or special cases makes the code easier to reason about.
However, I think I have convinced myself that the existing check for `SYCLKernelEntryPointAttr` and the new check for `SYCLExternalAttr` should be done before the "Forward declarations aren't required" check since extern inline functions shouldn't be emitted for device compilation unless used.
https://github.com/llvm/llvm-project/pull/140282
More information about the cfe-commits
mailing list