Index: llvm/lib/Linker/IRMover.cpp =================================================================== --- llvm/lib/Linker/IRMover.cpp +++ llvm/lib/Linker/IRMover.cpp @@ -897,6 +897,10 @@ if (DstGV->getSection() != SrcGV->getSection()) return stringErr( "Appending variables with different section name need to be linked!"); + + if (DstGV->getAddressSpace() != SrcGV->getAddressSpace()) + return stringErr("Appending variables with different address spaces need " + "to be linked!"); } // Do not need to do anything if source is a declaration. Index: llvm/test/Linker/appending-global-err6.ll =================================================================== --- /dev/null +++ llvm/test/Linker/appending-global-err6.ll @@ -0,0 +1,9 @@ +; RUN: not llvm-link %s %p/Inputs/appending-global.ll -S -o - 2>&1 | FileCheck %s +; RUN: not llvm-link %p/Inputs/appending-global.ll %s -S -o - 2>&1 | FileCheck %s + +; Negative test to check that global variables with appending linkage +; and different address spaces cannot be linked. + +; CHECK: error: Appending variables with different address spaces need to be linked! + +@var = appending addrspace(1) global [ 1 x ptr ] undef