================
@@ -7984,6 +7984,18 @@ void Sema::ProcessDeclAttributeList(
}
}
+ // CUDA/HIP: disallow explicit CUDA target attributes on deduction guides.
+ // Deduction guides are not callable functions and never participate in
+ // codegen; they are always treated as host+device for CUDA/HIP semantic
+ // checks, so explicit target attributes on them would be misleading noise.
+ if (getLangOpts().CUDA)
+ if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D))
+ if (Guide->hasAttr<CUDAHostAttr>() || Guide->hasAttr<CUDADeviceAttr>() ||
+ Guide->hasAttr<CUDAGlobalAttr>()) {
+ Diag(Guide->getLocation(), diag::err_deduction_guide_target_attr);
+ Guide->setInvalidDecl();
+ }
----------------
cor3ntin wrote:
Can you have a `CUDAHostAttr` if getLangOpts().CUDA` is not set? I think we can
simplify this code a bit. also :
```suggestion
if (getLangOpts().CUDA)
if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D);
Guide && Guide->hasAttr<CUDAHostAttr>() ||
Guide->hasAttr<CUDADeviceAttr>() ||
Guide->hasAttr<CUDAGlobalAttr>()) {
Diag(Guide->getLocation(), diag::err_deduction_guide_target_attr);
Guide->setInvalidDecl();
}
```
https://github.com/llvm/llvm-project/pull/168711
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits