Skip to content

Commit 85feb93

Browse files
committed
[OpenMP] Fix setting visibility on declare target variables
Summary: A previous patch changed the logic to force external visibliity on declare target variables. This is because they need to be exported in the dynamic symbol table to be usable as the standard depicts. However, the logic was always setting the visibility to `protected`, which would override some symbols. For example, when calling `libc` functions for CPU offloading. This patch changes the logic to only fire if the variable has hidden visibliity to start with.
1 parent bcf172e commit 85feb93

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,21 +1391,23 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
13911391
if (!D)
13921392
return;
13931393

1394+
// Set visibility for definitions, and for declarations if requested globally
1395+
// or set explicitly.
1396+
LinkageInfo LV = D->getLinkageAndVisibility();
1397+
13941398
// OpenMP declare target variables must be visible to the host so they can
13951399
// be registered. We require protected visibility unless the variable has
13961400
// the DT_nohost modifier and does not need to be registered.
13971401
if (Context.getLangOpts().OpenMP &&
13981402
Context.getLangOpts().OpenMPIsTargetDevice && isa<VarDecl>(D) &&
13991403
D->hasAttr<OMPDeclareTargetDeclAttr>() &&
14001404
D->getAttr<OMPDeclareTargetDeclAttr>()->getDevType() !=
1401-
OMPDeclareTargetDeclAttr::DT_NoHost) {
1405+
OMPDeclareTargetDeclAttr::DT_NoHost &&
1406+
LV.getVisibility() == HiddenVisibility) {
14021407
GV->setVisibility(llvm::GlobalValue::ProtectedVisibility);
14031408
return;
14041409
}
14051410

1406-
// Set visibility for definitions, and for declarations if requested globally
1407-
// or set explicitly.
1408-
LinkageInfo LV = D->getLinkageAndVisibility();
14091411
if (GV->hasDLLExportStorageClass() || GV->hasDLLImportStorageClass()) {
14101412
// Reject incompatible dlllstorage and visibility annotations.
14111413
if (!LV.isVisibilityExplicit())

clang/test/OpenMP/declare_target_codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// CHECK-DAG: @dy = {{protected | }}global i32 0,
3232
// CHECK-DAG: @bbb = {{protected | }}global i32 0,
3333
// CHECK-DAG: weak constant %struct.__tgt_offload_entry { ptr @bbb,
34-
// CHECK-DAG: @ccc = external {{protected | }}global i32,
34+
// CHECK-DAG: @ccc = external global i32,
3535
// CHECK-DAG: @ddd = {{protected | }}global i32 0,
3636
// CHECK-DAG: @hhh_decl_tgt_ref_ptr = weak global ptr null
3737
// CHECK-DAG: @ggg_decl_tgt_ref_ptr = weak global ptr null

clang/test/OpenMP/declare_target_constexpr_codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class A {
1616
public:
1717
static constexpr double pi = 3.141592653589793116;
1818
//.
19-
// CHECK: @_ZN1A2piE = linkonce_odr protected constant double 0x400921FB54442D18, comdat, align 8
19+
// CHECK: @_ZN1A2piE = linkonce_odr constant double 0x400921FB54442D18, comdat, align 8
2020
// CHECK: @_ZL9anotherPi = internal constant double 3.140000e+00, align 8
2121
// CHECK: @llvm.compiler.used = appending global [2 x ptr] [ptr @"__ZN1A2piE$ref", ptr @"__ZL9anotherPi$ref"], section "llvm.metadata"
2222
//.

0 commit comments

Comments
 (0)