From: Michael Liao Date: Fri, 26 Apr 2019 19:31:48 +0000 (+0000) Subject: [HIP] Fix visibility of `__constant__` variables. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3bbed5ed96fe98ec1c57a7455c8e56378c29cbd6;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359344 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 5c2b3ff353..432e55da41 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/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/test/CodeGenCUDA/amdgpu-visibility.cu b/test/CodeGenCUDA/amdgpu-visibility.cu new file mode 100644 index 0000000000..9f44eb047f --- /dev/null +++ b/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; +}