[clang] [ObjC] Set visibility of IvarOffsetGV when it is created in ObjCIvarOffsetVariable (PR #83726)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 3 08:11:48 PST 2024
https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/83726
>From 07e6cc851a0855c8c3b1b1de4bceb6a90aa3774f Mon Sep 17 00:00:00 2001
From: Rose <83477269+AtariDreams at users.noreply.github.com>
Date: Fri, 1 Mar 2024 17:52:58 -0500
Subject: [PATCH] [ObjC] Set visibility of IvarOffsetGV when it is created in
ObjCIvarOffsetVariable
It makes sense to set the visibility of the IvarOffsetGV when a new value for it is made in the heap.
---
clang/lib/CodeGen/CGObjCMac.cpp | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..71e6a606848108 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -6826,24 +6826,24 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const ObjCInterfaceDecl *ID,
Name += Ivar->getName();
llvm::GlobalVariable *IvarOffsetGV = CGM.getModule().getGlobalVariable(Name);
if (!IvarOffsetGV) {
- IvarOffsetGV =
- new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.IvarOffsetVarTy,
- false, llvm::GlobalValue::ExternalLinkage,
- nullptr, Name.str());
+ IvarOffsetGV = new llvm::GlobalVariable(
+ CGM.getModule(), ObjCTypes.IvarOffsetVarTy, false,
+ llvm::GlobalValue::ExternalLinkage, nullptr, Name.str());
+ bool IsPrivateOrPackage =
+ Ivar->getAccessControl() == ObjCIvarDecl::Private ||
+ Ivar->getAccessControl() == ObjCIvarDecl::Package;
if (CGM.getTriple().isOSBinFormatCOFF()) {
- bool IsPrivateOrPackage =
- Ivar->getAccessControl() == ObjCIvarDecl::Private ||
- Ivar->getAccessControl() == ObjCIvarDecl::Package;
-
const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface();
-
if (ContainingID->hasAttr<DLLImportAttr>())
- IvarOffsetGV
- ->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+ IvarOffsetGV->setDLLStorageClass(
+ llvm::GlobalValue::DLLImportStorageClass);
else if (ContainingID->hasAttr<DLLExportAttr>() && !IsPrivateOrPackage)
- IvarOffsetGV
- ->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
- }
+ IvarOffsetGV->setDLLStorageClass(
+ llvm::GlobalValue::DLLExportStorageClass);
+ } else if (IsPrivateOrPackage || ID->getVisibility() == HiddenVisibility)
+ IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+ else
+ IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility);
}
return IvarOffsetGV;
}
@@ -6859,8 +6859,6 @@ CGObjCNonFragileABIMac::EmitIvarOffsetVar(const ObjCInterfaceDecl *ID,
CGM.getDataLayout().getABITypeAlign(ObjCTypes.IvarOffsetVarTy));
if (!CGM.getTriple().isOSBinFormatCOFF()) {
- // FIXME: This matches gcc, but shouldn't the visibility be set on the use
- // as well (i.e., in ObjCIvarOffsetVariable).
if (Ivar->getAccessControl() == ObjCIvarDecl::Private ||
Ivar->getAccessControl() == ObjCIvarDecl::Package ||
ID->getVisibility() == HiddenVisibility)
More information about the cfe-commits
mailing list