From 3820506960e058b04078e8301404474164fb2628 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Fri, 26 Apr 2019 19:31:48 +0000 Subject: [PATCH] [HIP] Fix visibility of `__constant__` variables. Summary: - `__constant__` variables should not be `hidden` as the linker may turn them into `LOCAL` symbols. Reviewers: yaxunl Subscribers: jvesely, nhaehnle, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61194 llvm-svn: 359344 --- clang/lib/CodeGen/TargetInfo.cpp | 3 ++- clang/test/CodeGenCUDA/amdgpu-visibility.cu | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenCUDA/amdgpu-visibility.cu diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 5c2b3ff353e7..432e55da411d 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -7847,7 +7847,8 @@ static bool requiresAMDGPUProtectedVisibility(const Decl *D, return D->hasAttr() || (isa(D) && D->hasAttr()) || - (isa(D) && D->hasAttr()); + (isa(D) && + (D->hasAttr() || D->hasAttr())); } void AMDGPUTargetCodeGenInfo::setTargetAttributes( diff --git a/clang/test/CodeGenCUDA/amdgpu-visibility.cu b/clang/test/CodeGenCUDA/amdgpu-visibility.cu new file mode 100644 index 000000000000..9f44eb047f82 --- /dev/null +++ b/clang/test/CodeGenCUDA/amdgpu-visibility.cu @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -fapply-global-visibility-to-externs -fvisibility default -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-DEFAULT %s +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -fapply-global-visibility-to-externs -fvisibility protected -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-PROTECTED %s +// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -fapply-global-visibility-to-externs -fvisibility hidden -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-HIDDEN %s + +#include "Inputs/cuda.h" + +// CHECK-DEFAULT: @c = addrspace(4) externally_initialized global +// CHECK-DEFAULT: @g = addrspace(1) externally_initialized global +// CHECK-PROTECTED: @c = protected addrspace(4) externally_initialized global +// CHECK-PROTECTED: @g = protected addrspace(1) externally_initialized global +// CHECK-HIDDEN: @c = protected addrspace(4) externally_initialized global +// CHECK-HIDDEN: @g = protected addrspace(1) externally_initialized global +__constant__ int c; +__device__ int g; + +// CHECK-DEFAULT: define amdgpu_kernel void @_Z3foov() +// CHECK-PROTECTED: define protected amdgpu_kernel void @_Z3foov() +// CHECK-HIDDEN: define protected amdgpu_kernel void @_Z3foov() +__global__ void foo() { + g = c; +}