diff options
-rw-r--r-- | llvm/lib/LTO/LTOCodeGenerator.cpp | 4 | ||||
-rw-r--r-- | llvm/test/LTO/X86/unnamed.ll | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp index 01304641598..1aa836780c0 100644 --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -381,6 +381,10 @@ void LTOCodeGenerator::applyScopeRestrictions() { // candidate GlobalValue if it can be internalized or not. SmallString<64> MangledName; auto mustPreserveGV = [&](const GlobalValue &GV) -> bool { + // Unnamed globals can't be mangled, but they can't be preserved either. + if (!GV.hasName()) + return false; + // Need to mangle the GV as the "MustPreserveSymbols" StringSet is filled // with the linker supplied name, which on Darwin includes a leading // underscore. diff --git a/llvm/test/LTO/X86/unnamed.ll b/llvm/test/LTO/X86/unnamed.ll new file mode 100644 index 00000000000..ad410f58eb6 --- /dev/null +++ b/llvm/test/LTO/X86/unnamed.ll @@ -0,0 +1,10 @@ +; RUN: llvm-as -o %t.bc %s +; RUN: llvm-lto -save-merged-module -o %t2 %t.bc +; RUN: llvm-dis -o - %t2.merged.bc | FileCheck %s + +; CHECK-NOT: global i32 + +target triple = "x86_64-unknown-linux-gnu" + +@0 = private global i32 42 +@foo = constant i32* @0 |