diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp --- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -183,6 +183,8 @@ for (GlobalValue *GV : V) if (!convertToDeclaration(*GV)) GV->eraseFromParent(); + else if (!GV->isImplicitDSOLocal()) + GV->setDSOLocal(false); } void forEachVirtualFunction(Constant *C, function_ref Fn) { diff --git a/llvm/test/Transforms/ThinLTOBitcodeWriter/split-dsolocal.ll b/llvm/test/Transforms/ThinLTOBitcodeWriter/split-dsolocal.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/ThinLTOBitcodeWriter/split-dsolocal.ll @@ -0,0 +1,18 @@ +; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s +; RUN: llvm-modextract -b -n 0 -o %t0.bc %t +; RUN: llvm-modextract -b -n 1 -o %t1.bc %t +; RUN: not llvm-modextract -b -n 2 -o - %t 2>&1 | FileCheck --check-prefix=ERROR %s +; RUN: llvm-dis -o - %t0.bc | FileCheck --check-prefix=M0 %s +; RUN: llvm-dis -o - %t1.bc | FileCheck --check-prefix=M1 %s + +; ERROR: llvm-modextract: error: module index out of range; bitcode file contains 2 module(s) + +; M0: @g = external constant [1 x i8] +; M1: @g = dso_local constant [1 x i8] c"0", !type !0 +@g = dso_local constant [1 x i8] c"0", !type !0 + +define [1 x i8]* @f() { + ret [1 x i8]* @g +} + +!0 = !{i32 0, !"typeid"}