[llvm] [ConstantMerge] Check local linkage while merging (PR #124220)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 18:58:15 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: None (gulfemsavrun)

<details>
<summary>Changes</summary>

Avoid merging a constant with a local linkage into a constant with a non-local linkage because it might be used in pointer arithmetics like in relative lookup tables, where it uses pointer arithmetics that is only valid with local linkage.

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


1 Files Affected:

- (modified) llvm/lib/Transforms/IPO/ConstantMerge.cpp (+2) 


``````````diff
diff --git a/llvm/lib/Transforms/IPO/ConstantMerge.cpp b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
index a1face0a6a9c3a..85686f8f62874a 100644
--- a/llvm/lib/Transforms/IPO/ConstantMerge.cpp
+++ b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
@@ -109,6 +109,8 @@ static CanMerge makeMergeable(GlobalVariable *Old, GlobalVariable *New) {
   assert(!hasMetadataOtherThanDebugLoc(New));
   if (!Old->hasGlobalUnnamedAddr())
     New->setUnnamedAddr(GlobalValue::UnnamedAddr::None);
+  if (Old->hasLocalLinkage() && !New->hasLocalLinkage())
+    return CanMerge::No;
   return CanMerge::Yes;
 }
 

``````````

</details>


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


More information about the llvm-commits mailing list