r359344 - [HIP] Fix visibility of `__constant__` variables.

Michael Liao via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 26 12:31:48 PDT 2019


Author: hliao
Date: Fri Apr 26 12:31:48 2019
New Revision: 359344

URL: http://llvm.org/viewvc/llvm-project?rev=359344&view=rev
Log:
[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

Added:
    cfe/trunk/test/CodeGenCUDA/amdgpu-visibility.cu
Modified:
    cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=359344&r1=359343&r2=359344&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Fri Apr 26 12:31:48 2019
@@ -7847,7 +7847,8 @@ static bool requiresAMDGPUProtectedVisib
 
   return D->hasAttr<OpenCLKernelAttr>() ||
          (isa<FunctionDecl>(D) && D->hasAttr<CUDAGlobalAttr>()) ||
-         (isa<VarDecl>(D) && D->hasAttr<CUDADeviceAttr>());
+         (isa<VarDecl>(D) &&
+          (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>()));
 }
 
 void AMDGPUTargetCodeGenInfo::setTargetAttributes(

Added: cfe/trunk/test/CodeGenCUDA/amdgpu-visibility.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/amdgpu-visibility.cu?rev=359344&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCUDA/amdgpu-visibility.cu (added)
+++ cfe/trunk/test/CodeGenCUDA/amdgpu-visibility.cu Fri Apr 26 12:31:48 2019
@@ -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;
+}




More information about the cfe-commits mailing list