+ ValueMap.insert(std::make_pair(SGV, NewDGV));
+ } else if (SGV->isExternal()) {
+ // If SGV is external or if both SGV & DGV are external.. Just link the
+ // external globals, we aren't adding anything.
+ ValueMap.insert(std::make_pair(SGV, DGV));
+
+ } 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!
+ } else if (SGV->getLinkage() != DGV->getLinkage()) {
+ return Error(Err, "Global variables named '" + SGV->getName() +
+ "' have different linkage specifiers!");
+ } else if (SGV->hasExternalLinkage()) {
+ // Allow linking two exactly identical external global variables...
+ if (SGV->isConstant() != DGV->isConstant() ||
+ SGV->getInitializer() != DGV->getInitializer())
+ return Error(Err, "Global Variable Collision on '" +
+ SGV->getType()->getDescription() + " %" + SGV->getName() +
+ "' - Global variables differ in const'ness");