[clang] Reland [CUDA][HIP] Fix CTAD for host/device constructors (#168711) (PR #170481)
Artem Belevich via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 4 10:49:51 PST 2025
================
@@ -8056,6 +8056,30 @@ void Sema::ProcessDeclAttributeList(
}
}
+ // CUDA/HIP: restrict 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. We therefore allow either no CUDA target attributes or an explicit
+ // '__host__ __device__' annotation, but reject guides that are host-only,
+ // device-only, or marked '__global__'. The use of explicit CUDA/HIP target
+ // attributes on deduction guides is deprecated and will be rejected in a
+ // future Clang version.
+ if (getLangOpts().CUDA)
+ if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
+ bool HasHost = Guide->hasAttr<CUDAHostAttr>();
+ bool HasDevice = Guide->hasAttr<CUDADeviceAttr>();
+ bool HasGlobal = Guide->hasAttr<CUDAGlobalAttr>();
+
+ if (HasGlobal || HasHost != HasDevice) {
+ Diag(Guide->getLocation(), diag::err_deduction_guide_target_attr);
+ Guide->setInvalidDecl();
+ } else if (HasHost && HasDevice) {
+ Diag(Guide->getLocation(),
+ diag::warn_deduction_guide_target_attr_deprecated);
----------------
Artem-B wrote:
OK. no target attributes it is, then.
https://github.com/llvm/llvm-project/pull/170481
More information about the cfe-commits
mailing list