https://github.com/pjmc-oliveira updated https://github.com/llvm/llvm-project/pull/236605
>From 65528e592b7374a461cc57dfeeae976c78b0a410 Mon Sep 17 00:00:00 2001 From: Pedro Oliveira <[email protected]> Date: Thu, 29 Oct 2026 00:04:53 +0000 Subject: [PATCH 1/2] [CUDA][NFCI] Use getEnclosingFunction() for DeclContext casts in SemaCUDA Expansion statements added CXXExpansionStmtDecl, so a local variable's parent DeclContext is not always the enclosing function. getEnclosingFunction skips these contexts. Assisted-by: Claude Opus 5 --- clang/lib/Sema/SemaCUDA.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index fbdd7b0a40ae72..0c4e357bbb683b 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -266,7 +266,7 @@ SemaCUDA::CUDAVariableTarget SemaCUDA::IdentifyTarget(const VarDecl *Var) { // attribute are emitted // - on both sides in host device functions // - on device side in device or global functions - if (auto *FD = dyn_cast<FunctionDecl>(Var->getDeclContext())) { + if (auto *FD = Var->getDeclContext()->getEnclosingFunction()) { switch (IdentifyTarget(FD)) { case CUDAFunctionTarget::HostDevice: return CVT_Both; @@ -745,8 +745,7 @@ bool HasAllowedCUDADeviceStaticInitializer(SemaCUDA &S, VarDecl *VD, void SemaCUDA::checkAllowedInitializer(VarDecl *VD) { // Return early if VD is inside a non-instantiated template function since // the implicit constructor is not defined yet. - if (const FunctionDecl *FD = - dyn_cast_or_null<FunctionDecl>(VD->getDeclContext()); + if (const FunctionDecl *FD = VD->getDeclContext()->getEnclosingFunction(); FD && FD->isDependentContext()) return; >From 7b769af58455a4b648003b0b7440bfe11ae83e4f Mon Sep 17 00:00:00 2001 From: Pedro Oliveira <[email protected]> Date: Thu, 29 Oct 2026 21:51:07 +0000 Subject: [PATCH 2/2] Changed 'auto' to 'const FunctionDecl' --- clang/lib/Sema/SemaCUDA.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index 0c4e357bbb683b..f05a60a49b1af6 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -266,7 +266,7 @@ SemaCUDA::CUDAVariableTarget SemaCUDA::IdentifyTarget(const VarDecl *Var) { // attribute are emitted // - on both sides in host device functions // - on device side in device or global functions - if (auto *FD = Var->getDeclContext()->getEnclosingFunction()) { + if (const FunctionDecl *FD = Var->getDeclContext()->getEnclosingFunction()) { switch (IdentifyTarget(FD)) { case CUDAFunctionTarget::HostDevice: return CVT_Both; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
