Index: lib/AST/Decl.cpp =================================================================== --- lib/AST/Decl.cpp +++ lib/AST/Decl.cpp @@ -556,6 +556,13 @@ FD->hasBody(Def) && Def->isInlined() && !Def->hasAttr(); } +static bool useOpenCLVisibilityDefault(const NamedDecl *D) { + if (!D->getASTContext().getLangOpts().OpenCL) + return false; + const auto *FD = dyn_cast(D); + return FD && FD->hasAttr(); +} + template static bool isFirstInExternCContext(T *D) { const T *First = D->getFirstDecl(); return First->isInExternCContext(); @@ -713,6 +720,9 @@ } } + if (!LV.isVisibilityExplicit() && useOpenCLVisibilityDefault(D)) + LV.mergeVisibility(DefaultVisibility, true); + // Add in global settings if the above didn't give us direct visibility. if (!LV.isVisibilityExplicit()) { // Use global type/value visibility as appropriate. Index: test/CodeGenOpenCL/visibility.cl =================================================================== --- /dev/null +++ test/CodeGenOpenCL/visibility.cl @@ -0,0 +1,56 @@ +// RUN: %clang_cc1 -fvisibility default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s +// RUN: %clang_cc1 -fvisibility protected -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s +// RUN: %clang_cc1 -fvisibility hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-HIDDEN %s + +// REQUIRES: amdgpu-registered-target + +// FVIS-DEFAULT: @globl = local_unnamed_addr +// FVIS-PROTECTED: @globl = protected local_unnamed_addr +// FVIS-HIDDEN: @globl = hidden local_unnamed_addr +__constant int globl = 0; +// FVIS-DEFAULT: @default_globl = local_unnamed_addr +// FVIS-PROTECTED: @default_globl = local_unnamed_addr +// FVIS-HIDDEN: @default_globl = local_unnamed_addr +__attribute__((visibility("default"))) __constant int default_globl = 0; +// FVIS-DEFAULT: @protected_globl = protected local_unnamed_addr +// FVIS-PROTECTED: @protected_globl = protected local_unnamed_addr +// FVIS-HIDDEN: @protected_globl = protected local_unnamed_addr +__attribute__((visibility("protected"))) __constant int protected_globl = 0; +// FVIS-DEFAULT: @hidden_globl = hidden local_unnamed_addr +// FVIS-PROTECTED: @hidden_globl = hidden local_unnamed_addr +// FVIS-HIDDEN: @hidden_globl = hidden local_unnamed_addr +__attribute__((visibility("hidden"))) __constant int hidden_globl = 0; + +// FVIS-DEFAULT: define amdgpu_kernel void @kern() +// FVIS-PROTECTED: define amdgpu_kernel void @kern() +// FVIS-HIDDEN: define amdgpu_kernel void @kern() +kernel void kern() {} +// FVIS-DEFAULT: define amdgpu_kernel void @default_kern() +// FVIS-PROTECTED: define amdgpu_kernel void @default_kern() +// FVIS-HIDDEN: define amdgpu_kernel void @default_kern() +__attribute__((visibility("default"))) kernel void default_kern() {} +// FVIS-DEFAULT: define protected amdgpu_kernel void @protected_kern() +// FVIS-PROTECTED: define protected amdgpu_kernel void @protected_kern() +// FVIS-HIDDEN: define protected amdgpu_kernel void @protected_kern() +__attribute__((visibility("protected"))) kernel void protected_kern() {} +// FVIS-DEFAULT: define hidden amdgpu_kernel void @hidden_kern() +// FVIS-PROTECTED: define hidden amdgpu_kernel void @hidden_kern() +// FVIS-HIDDEN: define hidden amdgpu_kernel void @hidden_kern() +__attribute__((visibility("hidden"))) kernel void hidden_kern() {} + +// FVIS-DEFAULT: define void @func() +// FVIS-PROTECTED: define protected void @func() +// FVIS-HIDDEN: define hidden void @func() +void func() {} +// FVIS-DEFAULT: define void @default_func() +// FVIS-PROTECTED: define void @default_func() +// FVIS-HIDDEN: define void @default_func() +__attribute__((visibility("default"))) void default_func() {} +// FVIS-DEFAULT: define protected void @protected_func() +// FVIS-PROTECTED: define protected void @protected_func() +// FVIS-HIDDEN: define protected void @protected_func() +__attribute__((visibility("protected"))) void protected_func() {} +// FVIS-DEFAULT: define hidden void @hidden_func() +// FVIS-PROTECTED: define hidden void @hidden_func() +// FVIS-HIDDEN: define hidden void @hidden_func() +__attribute__((visibility("hidden"))) void hidden_func() {}