Skip to content

[CIR][CUDA] Fix CUDA CIR mangling bug #1396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,7 @@ static std::string getMangledNameImpl(CIRGenModule &CGM, GlobalDecl GD,
assert(0 && "NYI");
} else if (FD && FD->hasAttr<CUDAGlobalAttr>() &&
GD.getKernelReferenceKind() == KernelReferenceKind::Stub) {
Out << "__device_stub__";
Out << "__device_stub__" << II->getName();
} else {
Out << II->getName();
}
Expand Down
92 changes: 92 additions & 0 deletions clang/test/CIR/CodeGen/CUDA/mangling.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "../Inputs/cuda.h"

// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir \
// RUN: -x cuda -emit-cir -target-sdk-version=12.3 \
// RUN: %s -o %t.cir
// RUN: FileCheck --check-prefix=CIR-HOST --input-file=%t.cir %s

// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fclangir \
// RUN: -fcuda-is-device -emit-cir -target-sdk-version=12.3 \
// RUN: %s -o %t.cir
// RUN: FileCheck --check-prefix=CIR-DEVICE --input-file=%t.cir %s

namespace ns {
__global__ void cpp_global_function_1(int a, int* b, float c) {}
// CIR-HOST: cir.func @_ZN2ns36__device_stub__cpp_global_function_1EiPif
// CIR-DEVICE: cir.func @_ZN2ns21cpp_global_function_1EiPif

__global__ void cpp_global_function_2(int a, int* b, float c) {}

// CIR-HOST: cir.func @_ZN2ns36__device_stub__cpp_global_function_2EiPif
// CIR-DEVICE: cir.func @_ZN2ns21cpp_global_function_2EiPif

__host__ void cpp_host_function_1(int a, int* b, float c) {}

// CIR-HOST: cir.func @_ZN2ns19cpp_host_function_1EiPif

__host__ void cpp_host_function_2(int a, int* b, float c) {}

// CIR-HOST: cir.func @_ZN2ns19cpp_host_function_2EiPif

__device__ void cpp_device_function_1(int a, int* b, float c) {}

// CIR-DEVICE: cir.func @_ZN2ns21cpp_device_function_1EiPif

__device__ void cpp_device_function_2(int a, int* b, float c) {}

// CIR-DEVICE: cir.func @_ZN2ns21cpp_device_function_2EiPif
}

__global__ void cpp_global_function_1(int a, int* b, float c) {}

// CIR-HOST: cir.func @_Z36__device_stub__cpp_global_function_1iPif
// CIR-DEVICE: cir.func @_Z21cpp_global_function_1iPif

__global__ void cpp_global_function_2(int a, int* b, float c) {}

// CIR-HOST: cir.func @_Z36__device_stub__cpp_global_function_2iPif
// CIR-DEVICE: cir.func @_Z21cpp_global_function_2iPif

__host__ void cpp_host_function_1(int a, int* b, float c) {}

// CIR-HOST: cir.func @_Z19cpp_host_function_1iPif

__host__ void cpp_host_function_2(int a, int* b, float c) {}

// CIR-HOST: cir.func @_Z19cpp_host_function_2iPif

__device__ void cpp_device_function_1(int a, int* b, float c) {}

// CIR-DEVICE: cir.func @_Z21cpp_device_function_1iPif

__device__ void cpp_device_function_2(int a, int* b, float c) {}

// CIR-DEVICE: cir.func @_Z21cpp_device_function_2iPif

extern "C" {
__global__ void c_global_function_1(int a, int* b, float c) {}

// CIR-HOST: cir.func @__device_stub__c_global_function_1
// CIR-DEVICE: cir.func @c_global_function_1

__global__ void c_global_function_2(int a, int* b, float c) {}

// CIR-HOST: cir.func @__device_stub__c_global_function_2
// CIR-DEVICE: cir.func @c_global_function_2

__host__ void c_host_function_1(int a, int* b, float c) {}

// CIR-HOST: cir.func @c_host_function_1

__host__ void c_host_function_2(int a, int* b, float c) {}

// CIR-HOST: cir.func @c_host_function_2

__device__ void c_device_function_1(int a, int* b, float c) {}

// CIR-DEVICE: cir.func @c_device_function_1

__device__ void c_device_function_2(int a, int* b, float c) {}

// CIR-DEVICE: cir.func @c_device_function_2
}
Loading