[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 07:22:06 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: AtariDreams (AtariDreams)

<details>
<summary>Changes</summary>

It makes sense to set the visibility of the IvarOffsetGV when a new value for it is made in the heap.

---
Full diff: https://github.com/llvm/llvm-project/pull/83726.diff


1 Files Affected:

- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+12-8) 


``````````diff
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..cf472707d1794d 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -6826,10 +6826,9 @@ 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());
     if (CGM.getTriple().isOSBinFormatCOFF()) {
       bool IsPrivateOrPackage =
           Ivar->getAccessControl() == ObjCIvarDecl::Private ||
@@ -6838,11 +6837,16 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const ObjCInterfaceDecl *ID,
       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);
+
+      if (IsPrivateOrPackage || ID->getVisibility() == HiddenVisibility)
+        IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+      else
+        IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility);
     }
   }
   return IvarOffsetGV;

``````````

</details>


https://github.com/llvm/llvm-project/pull/83726


More information about the cfe-commits mailing list