[llvm-commits] CVS: llvm/lib/VMCore/Linker.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Oct 4 19:28:22 PDT 2004



Changes in directory llvm/lib/VMCore:

Linker.cpp updated: 1.85 -> 1.86
---
Log message:

Make sure the const bit gets inherited correctly when linking declarations
of disagreeing constness.  This fixes 
test/Regression/Linker/ConstantGlobals[123].ll


---
Diffs of the changes:  (+15 -1)

Index: llvm/lib/VMCore/Linker.cpp
diff -u llvm/lib/VMCore/Linker.cpp:1.85 llvm/lib/VMCore/Linker.cpp:1.86
--- llvm/lib/VMCore/Linker.cpp:1.85	Fri Sep 10 23:25:17 2004
+++ llvm/lib/VMCore/Linker.cpp	Mon Oct  4 21:28:11 2004
@@ -457,15 +457,26 @@
       // external globals, we aren't adding anything.
       ValueMap.insert(std::make_pair(SGV, DGV));
 
+      // Inherit 'const' information.
+      if (SGV->isConstant()) DGV->setConstant(true);
+
     } else if (DGV->isExternal()) {   // If DGV is external but SGV is not...
       ValueMap.insert(std::make_pair(SGV, DGV));
       DGV->setLinkage(SGV->getLinkage());    // Inherit linkage!
+
+      if (DGV->isConstant() && !SGV->isConstant())
+        return Error(Err, "Linking globals named '" + SGV->getName() +
+                     "': declaration is const but definition is not!");
+
+      // Inherit 'const' information.
+      if (SGV->isConstant()) DGV->setConstant(true);
+
     } else if (SGV->hasWeakLinkage() || SGV->hasLinkOnceLinkage()) {
       // At this point we know that DGV has LinkOnce, Appending, Weak, or
       // External linkage.  If DGV is Appending, this is an error.
       if (DGV->hasAppendingLinkage())
         return Error(Err, "Linking globals named '" + SGV->getName() +
-                     " ' with 'weak' and 'appending' linkage is not allowed!");
+                     "' with 'weak' and 'appending' linkage is not allowed!");
 
       if (SGV->isConstant() != DGV->isConstant())
         return Error(Err, "Global Variable Collision on '" + 
@@ -498,6 +509,9 @@
     } else if (SGV->getLinkage() != DGV->getLinkage()) {
       return Error(Err, "Global variables named '" + SGV->getName() +
                    "' have different linkage specifiers!");
+      // Inherit 'const' information.
+      if (SGV->isConstant()) DGV->setConstant(true);
+
     } else if (SGV->hasExternalLinkage()) {
       // Allow linking two exactly identical external global variables...
       if (SGV->isConstant() != DGV->isConstant())






More information about the llvm-commits mailing list