Skip to content

Commit 0a220de

Browse files
committed
[HIP] Fix visibility for 'extern' device variables.
Summary: - Fix a bug which misses the change for a variable to be set with target-specific attributes. Reviewers: yaxunl Subscribers: jvesely, nhaehnle, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63020
1 parent 6cd47f9 commit 0a220de

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,6 +3575,9 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
35753575
}
35763576
}
35773577

3578+
if (GV->isDeclaration())
3579+
getTargetCodeGenInfo().setTargetAttributes(D, GV, *this);
3580+
35783581
LangAS ExpectedAS =
35793582
D ? D->getType().getAddressSpace()
35803583
: (LangOpts.OpenCL ? LangAS::opencl_global : LangAS::Default);
@@ -3584,9 +3587,6 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
35843587
return getTargetCodeGenInfo().performAddrSpaceCast(*this, GV, AddrSpace,
35853588
ExpectedAS, Ty);
35863589

3587-
if (GV->isDeclaration())
3588-
getTargetCodeGenInfo().setTargetAttributes(D, GV, *this);
3589-
35903590
return GV;
35913591
}
35923592

clang/test/CodeGenCUDA/amdgpu-visibility.cu

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
__constant__ int c;
1414
__device__ int g;
1515

16+
// CHECK-DEFAULT: @e = external addrspace(1) global
17+
// CHECK-PROTECTED: @e = external protected addrspace(1) global
18+
// CHECK-HIDDEN: @e = external protected addrspace(1) global
19+
extern __device__ int e;
20+
21+
// dummy one to hold reference to `e`.
22+
__device__ int f() {
23+
return e;
24+
}
25+
1626
// CHECK-DEFAULT: define amdgpu_kernel void @_Z3foov()
1727
// CHECK-PROTECTED: define protected amdgpu_kernel void @_Z3foov()
1828
// CHECK-HIDDEN: define protected amdgpu_kernel void @_Z3foov()

0 commit comments

Comments
 (0)