Re-fix the issue Bill fixed in r147899 in a slightly different way, which doesn't...
authorEli Friedman <eli.friedman@gmail.com>
Wed, 11 Jan 2012 22:06:46 +0000 (22:06 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 11 Jan 2012 22:06:46 +0000 (22:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147971 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/GlobalValue.h
lib/Transforms/IPO/ConstantMerge.cpp

index d43a2fa227c65c08e1e7f4cfba70224fc13be54c..81a11a4c9258c7e832ebe31e7431d5f0e12a43d4 100644 (file)
@@ -192,14 +192,6 @@ public:
            Linkage == LinkerPrivateWeakDefAutoLinkage;
   }
 
-  /// mayBeRemovedByLinker - Whether the definition of this global may be
-  /// removed at link time.
-  static bool mayBeRemovedByLinker(LinkageTypes Linkage) {
-    return isLinkerPrivateLinkage(Linkage) ||
-      isLinkerPrivateWeakLinkage(Linkage) ||
-      isLinkerPrivateWeakDefAutoLinkage(Linkage);
-  }
-
   bool hasExternalLinkage() const { return isExternalLinkage(Linkage); }
   bool hasAvailableExternallyLinkage() const {
     return isAvailableExternallyLinkage(Linkage);
@@ -233,8 +225,6 @@ public:
 
   bool isWeakForLinker() const { return isWeakForLinker(Linkage); }
 
-  bool mayBeRemovedByLinker() const { return mayBeRemovedByLinker(Linkage); }
-
   /// copyAttributesFrom - copy all additional attributes (those not needed to
   /// create a GlobalValue) from the GlobalValue Src to this one.
   virtual void copyAttributesFrom(const GlobalValue *Src);
index 268a281aae4a79b8c33b7795d9feff946c3b9c89..d8fae8a4b2b906fbf2cfe0faadeac533a59ce66d 100644 (file)
@@ -140,8 +140,11 @@ bool ConstantMerge::runOnModule(Module &M) {
           UsedGlobals.count(GV))
         continue;
 
-      // Ignore any constants which may be removed by the linker.
-      if (GV->mayBeRemovedByLinker())
+      // This transformation is legal for weak ODR globals in the sense it
+      // doesn't change semantics, but we really don't want to perform it
+      // anyway; it's likely to pessimize code generation, and some tools
+      // (like the Darwin linker in cases involving CFString) don't expect it.
+      if (GV->isWeakForLinker())
         continue;
 
       Constant *Init = GV->getInitializer();
@@ -172,9 +175,8 @@ bool ConstantMerge::runOnModule(Module &M) {
           UsedGlobals.count(GV))
         continue;
 
-      // We can only replace constants with local linkage and which aren't
-      // removed by the linker.
-      if (!GV->hasLocalLinkage() || GV->mayBeRemovedByLinker())
+      // We can only replace constant with local linkage.
+      if (!GV->hasLocalLinkage())
         continue;
 
       Constant *Init = GV->getInitializer();