forked from OSchip/llvm-project
				
			Fix linking of unnamed_addr.
This was regression from r134829. When linking we have to be conservative. If one of the symbols has a significant address, then the result should have it too. llvm-svn: 189935
This commit is contained in:
		
							parent
							
								
									0a3b151fdf
								
							
						
					
					
						commit
						d4885daefa
					
				| 
						 | 
					@ -746,6 +746,7 @@ bool ModuleLinker::linkAppendingVarProto(GlobalVariable *DstGV,
 | 
				
			||||||
bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
 | 
					bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
 | 
				
			||||||
  GlobalValue *DGV = getLinkedToGlobal(SGV);
 | 
					  GlobalValue *DGV = getLinkedToGlobal(SGV);
 | 
				
			||||||
  llvm::Optional<GlobalValue::VisibilityTypes> NewVisibility;
 | 
					  llvm::Optional<GlobalValue::VisibilityTypes> NewVisibility;
 | 
				
			||||||
 | 
					  bool HasUnnamedAddr = SGV->hasUnnamedAddr();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (DGV) {
 | 
					  if (DGV) {
 | 
				
			||||||
    // Concatenation of appending linkage variables is magic and handled later.
 | 
					    // Concatenation of appending linkage variables is magic and handled later.
 | 
				
			||||||
| 
						 | 
					@ -755,6 +756,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
 | 
				
			||||||
    // Determine whether linkage of these two globals follows the source
 | 
					    // Determine whether linkage of these two globals follows the source
 | 
				
			||||||
    // module's definition or the destination module's definition.
 | 
					    // module's definition or the destination module's definition.
 | 
				
			||||||
    GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage;
 | 
					    GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage;
 | 
				
			||||||
 | 
					    HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr();
 | 
				
			||||||
    GlobalValue::VisibilityTypes NV;
 | 
					    GlobalValue::VisibilityTypes NV;
 | 
				
			||||||
    bool LinkFromSrc = false;
 | 
					    bool LinkFromSrc = false;
 | 
				
			||||||
    if (getLinkageResult(DGV, SGV, NewLinkage, NV, LinkFromSrc))
 | 
					    if (getLinkageResult(DGV, SGV, NewLinkage, NV, LinkFromSrc))
 | 
				
			||||||
| 
						 | 
					@ -769,9 +771,10 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
 | 
				
			||||||
        if (DGVar->isDeclaration() && SGV->isConstant() && !DGVar->isConstant())
 | 
					        if (DGVar->isDeclaration() && SGV->isConstant() && !DGVar->isConstant())
 | 
				
			||||||
          DGVar->setConstant(true);
 | 
					          DGVar->setConstant(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Set calculated linkage and visibility.
 | 
					      // Set calculated linkage, visibility and unnamed_addr.
 | 
				
			||||||
      DGV->setLinkage(NewLinkage);
 | 
					      DGV->setLinkage(NewLinkage);
 | 
				
			||||||
      DGV->setVisibility(*NewVisibility);
 | 
					      DGV->setVisibility(*NewVisibility);
 | 
				
			||||||
 | 
					      DGV->setUnnamedAddr(HasUnnamedAddr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Make sure to remember this mapping.
 | 
					      // Make sure to remember this mapping.
 | 
				
			||||||
      ValueMap[SGV] = ConstantExpr::getBitCast(DGV,TypeMap.get(SGV->getType()));
 | 
					      ValueMap[SGV] = ConstantExpr::getBitCast(DGV,TypeMap.get(SGV->getType()));
 | 
				
			||||||
| 
						 | 
					@ -797,6 +800,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
 | 
				
			||||||
  copyGVAttributes(NewDGV, SGV);
 | 
					  copyGVAttributes(NewDGV, SGV);
 | 
				
			||||||
  if (NewVisibility)
 | 
					  if (NewVisibility)
 | 
				
			||||||
    NewDGV->setVisibility(*NewVisibility);
 | 
					    NewDGV->setVisibility(*NewVisibility);
 | 
				
			||||||
 | 
					  NewDGV->setUnnamedAddr(HasUnnamedAddr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (DGV) {
 | 
					  if (DGV) {
 | 
				
			||||||
    DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV, DGV->getType()));
 | 
					    DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV, DGV->getType()));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,15 +10,15 @@
 | 
				
			||||||
@c = common unnamed_addr global i32 0
 | 
					@c = common unnamed_addr global i32 0
 | 
				
			||||||
; CHECK: @c = common unnamed_addr global i32 0
 | 
					; CHECK: @c = common unnamed_addr global i32 0
 | 
				
			||||||
@d = external global i32
 | 
					@d = external global i32
 | 
				
			||||||
; CHECK: @d = unnamed_addr global i32 42
 | 
					; CHECK: @d = global i32 42
 | 
				
			||||||
@e = external unnamed_addr global i32
 | 
					@e = external unnamed_addr global i32
 | 
				
			||||||
; CHECK: @e = unnamed_addr global i32 42
 | 
					; CHECK: @e = unnamed_addr global i32 42
 | 
				
			||||||
@f = weak global i32 42
 | 
					@f = weak global i32 42
 | 
				
			||||||
; CHECK: @f = unnamed_addr global i32 42
 | 
					; CHECK: @f = global i32 42
 | 
				
			||||||
 | 
					
 | 
				
			||||||
; Other file has non-unnamed_addr definition
 | 
					; Other file has non-unnamed_addr definition
 | 
				
			||||||
@g = common unnamed_addr global i32 0
 | 
					@g = common unnamed_addr global i32 0
 | 
				
			||||||
; CHECK: @g = common unnamed_addr global i32 0
 | 
					; CHECK: @g = common global i32 0
 | 
				
			||||||
@h = external global i32
 | 
					@h = external global i32
 | 
				
			||||||
; CHECK: @h = global i32 42
 | 
					; CHECK: @h = global i32 42
 | 
				
			||||||
@i = external unnamed_addr global i32
 | 
					@i = external unnamed_addr global i32
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue