Author: Mariya Podchishchaeva Date: 2026-09-01T11:50:04+02:00 New Revision: 9139bff12d78cc4e4b0c34bf0a240316a70a5aa4
URL: https://github.com/llvm/llvm-project/commit/9139bff12d78cc4e4b0c34bf0a240316a70a5aa4 DIFF: https://github.com/llvm/llvm-project/commit/9139bff12d78cc4e4b0c34bf0a240316a70a5aa4.diff LOG: [CIR][CUDA/HIP] Fix template static member filtering (#219536) Check host/device attributes before emitting static member of template instantiation. This is basically a CIR version of 77fd30f7ce0795b4bbc22e65b3ff42856839d708 . Added: clang/test/CIR/CodeGenCUDA/template-class-static-member.cu Modified: clang/lib/CIR/CodeGen/CIRGenModule.cpp Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 6d62befbc2223..6564c00e4dd3a 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -733,7 +733,8 @@ void CIRGenModule::addGlobalDtor(cir::FuncOp dtor, void CIRGenModule::handleCXXStaticMemberVarInstantiation(VarDecl *vd) { VarDecl::DefinitionKind dk = vd->isThisDeclarationADefinition(); - if (dk == VarDecl::Definition && vd->hasAttr<DLLImportAttr>()) + if ((dk == VarDecl::Definition && vd->hasAttr<DLLImportAttr>()) || + (langOpts.CUDA && !shouldEmitCUDAGlobalVar(vd))) return; TemplateSpecializationKind tsk = vd->getTemplateSpecializationKind(); diff --git a/clang/test/CIR/CodeGenCUDA/template-class-static-member.cu b/clang/test/CIR/CodeGenCUDA/template-class-static-member.cu new file mode 100644 index 0000000000000..fccfddc2b8018 --- /dev/null +++ b/clang/test/CIR/CodeGenCUDA/template-class-static-member.cu @@ -0,0 +1,79 @@ +// Based on clang/test/CodeGenCUDA/template-class-static-member.cu. + +// CIR tests + +// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -fcuda-is-device \ +// RUN: -emit-cir -o - -x hip %s | FileCheck -check-prefix=CIR-DEV %s + +// RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \ +// RUN: -emit-cir -o - -x hip %s | FileCheck -check-prefix=CIR-HOST %s + +// Negative tests. + +// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -fcuda-is-device \ +// RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefix=CIR-DEV-NEG %s + +// LLVM-IR tests + +// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -fcuda-is-device \ +// RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefix=DEV %s + +// RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \ +// RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefix=HOST %s + +// Negative tests. + +// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -fcuda-is-device \ +// RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefix=DEV-NEG %s + +#include "Inputs/cuda.h" + +template <class T> +class A { + static int h_member; + __device__ static int d_member; + __constant__ static int c_member; + __managed__ static int m_member; + const static int const_member = 0; +}; + +template <class T> +int A<T>::h_member; + +template <class T> +__device__ int A<T>::d_member; + +template <class T> +__constant__ int A<T>::c_member; + +template <class T> +__managed__ int A<T>::m_member; + +template <class T> +const int A<T>::const_member; + +template class A<int>; + +// CIR-DEV-DAG: cir.global "private" internal comdat dso_local target_address_space(1) @_ZN1AIiE8d_memberE = #cir.int<0> +// CIR-DEV-DAG: cir.global "private" constant internal comdat dso_local target_address_space(4) @_ZN1AIiE8c_memberE = #cir.int<0> +// CIR-DEV-DAG: cir.global "private" internal comdat dso_local target_address_space(1) @_ZN1AIiE8m_memberE = #cir.int<0> +// CIR-DEV-DAG: cir.global "private" constant internal comdat dso_local target_address_space(4) @_ZN1AIiE12const_memberE = #cir.int<0> +// CIR-DEV-NEG-NOT: @_ZN1AIiE8h_memberE + +// DEV-DAG: @_ZN1AIiE8d_memberE = internal addrspace(1) global i32 0, comdat, align 4 +// DEV-DAG: @_ZN1AIiE8c_memberE = internal addrspace(4) constant i32 0, comdat, align 4 +// DEV-DAG: @_ZN1AIiE8m_memberE = internal addrspace(1) externally_initialized global ptr addrspace(1) null +// DEV-DAG: @_ZN1AIiE12const_memberE = internal addrspace(4) constant i32 0, comdat, align 4 +// DEV-NEG-NOT: @_ZN1AIiE8h_memberE + +// CIR-HOST-DAG: cir.global weak_odr comdat @_ZN1AIiE8h_memberE = #cir.int<0> +// CIR-HOST-DAG: cir.global "private" internal comdat dso_local @_ZN1AIiE8d_memberE = #cir.undef +// CIR-HOST-DAG: cir.global "private" internal comdat dso_local @_ZN1AIiE8c_memberE = #cir.undef +// CIR-HOST-DAG: cir.global "private" internal comdat dso_local @_ZN1AIiE8m_memberE = #cir.int<0> +// CIR-HOST-DAG: cir.global constant weak_odr comdat @_ZN1AIiE12const_memberE = #cir.int<0> + +// HOST-DAG: @_ZN1AIiE8h_memberE = weak_odr global i32 0, comdat, align 4 +// HOST-DAG: @_ZN1AIiE8d_memberE = internal global i32 undef, comdat, align 4 +// HOST-DAG: @_ZN1AIiE8c_memberE = internal global i32 undef, comdat, align 4 +// HOST-DAG: @_ZN1AIiE8m_memberE = internal externally_initialized global ptr null +// HOST-DAG: @_ZN1AIiE12const_memberE = weak_odr constant i32 0, comdat, align 4 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
