llvm.org GIT mirror llvm / 3c16840
Merge from mainline. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_24@57713 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 10 years ago
1 changed file(s) with 39 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
661661 if (DGVar->isDeclaration() && SGV->isConstant() && !DGVar->isConstant())
662662 DGVar->setConstant(true);
663663
664 // SGV is global, but DGV is alias. The only valid mapping is when SGV is
665 // external declaration, which is effectively a no-op. Also make sure
666 // linkage calculation was correct.
667 if (isa(DGV) && !SGV->isDeclaration())
668 return Error(Err, "Global-Alias Collision on '" + SGV->getName() +
669 "': symbol multiple defined");
664 // SGV is global, but DGV is alias.
665 if (isa(DGV)) {
666 // The only valid mappings are:
667 // - SGV is external declaration, which is effectively a no-op.
668 // - SGV is weak, when we just need to throw SGV out.
669 if (!SGV->isDeclaration() && !SGV->mayBeOverridden())
670 return Error(Err, "Global-Alias Collision on '" + SGV->getName() +
671 "': symbol multiple defined");
672 }
670673
671674 // Set calculated linkage
672675 DGV->setLinkage(NewLinkage);
853856 // Figure out what the initializer looks like in the dest module...
854857 Constant *SInit =
855858 cast(RemapOperand(SGV->getInitializer(), ValueMap));
856
857 GlobalVariable *DGV =
858 cast(ValueMap[SGV]->stripPointerCasts());
859 if (DGV->hasInitializer()) {
860 if (SGV->hasExternalLinkage()) {
861 if (DGV->getInitializer() != SInit)
862 return Error(Err, "Global Variable Collision on '" + SGV->getName() +
863 "': global variables have different initializers");
864 } else if (DGV->mayBeOverridden()) {
865 // Nothing is required, mapped values will take the new global
866 // automatically.
867 } else if (SGV->mayBeOverridden()) {
868 // Nothing is required, mapped values will take the new global
869 // automatically.
870 } else if (DGV->hasAppendingLinkage()) {
871 assert(0 && "Appending linkage unimplemented!");
859 // Grab destination global variable or alias.
860 GlobalValue *DGV = cast(ValueMap[SGV]->stripPointerCasts());
861
862 // If dest if global variable, check that initializers match.
863 if (GlobalVariable *DGVar = dyn_cast(DGV)) {
864 if (DGVar->hasInitializer()) {
865 if (SGV->hasExternalLinkage()) {
866 if (DGVar->getInitializer() != SInit)
867 return Error(Err, "Global Variable Collision on '" +
868 SGV->getName() +
869 "': global variables have different initializers");
870 } else if (DGVar->mayBeOverridden()) {
871 // Nothing is required, mapped values will take the new global
872 // automatically.
873 } else if (SGV->mayBeOverridden()) {
874 // Nothing is required, mapped values will take the new global
875 // automatically.
876 } else if (DGVar->hasAppendingLinkage()) {
877 assert(0 && "Appending linkage unimplemented!");
878 } else {
879 assert(0 && "Unknown linkage!");
880 }
872881 } else {
873 assert(0 && "Unknown linkage!");
882 // Copy the initializer over now...
883 DGVar->setInitializer(SInit);
874884 }
875885 } else {
876 // Copy the initializer over now...
877 DGV->setInitializer(SInit);
886 // Destination is alias, the only valid situation is when source is
887 // weak. Also, note, that we already checked linkage in LinkGlobals(),
888 // thus we assert here.
889 // FIXME: Should we weaken this assumption, 'dereference' alias and
890 // check for initializer of aliasee?
891 assert(SGV->mayBeOverridden());
878892 }
879893 }
880894 }