diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -739,15 +739,8 @@ ++I; } - if (RemoveDeadUsers) { - // If C is only used by metadata, it should not be preserved but should - // have its uses replaced. - if (C->isUsedByMetadata()) { - const_cast(C)->replaceAllUsesWith( - UndefValue::get(C->getType())); - } + if (RemoveDeadUsers) const_cast(C)->destroyConstant(); - } return true; } diff --git a/llvm/test/LTO/Resolution/X86/Inputs/no-undef-type-md.ll b/llvm/test/LTO/Resolution/X86/Inputs/no-undef-type-md.ll new file mode 100644 --- /dev/null +++ b/llvm/test/LTO/Resolution/X86/Inputs/no-undef-type-md.ll @@ -0,0 +1,13 @@ +; ModuleID = 'test.cpp.o' +source_filename = "test.cpp" +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @a() + +!llvm.module.flags = !{!9, !39} + +!9 = !{i32 1, !"EnableSplitLTOUnit", i32 1} +!39 = !{i32 5, !"CG Profile", !40} +!40 = !{!41} +!41 = distinct !{null, i32 ()* bitcast (void ()* @a to i32 ()*), i64 2594092} diff --git a/llvm/test/LTO/Resolution/X86/no-undef-type-md.ll b/llvm/test/LTO/Resolution/X86/no-undef-type-md.ll new file mode 100644 --- /dev/null +++ b/llvm/test/LTO/Resolution/X86/no-undef-type-md.ll @@ -0,0 +1,37 @@ +; RUN: opt <%s -o %t0.o -thinlto-bc -thinlto-split-lto-unit +; RUN: llvm-as -o %t1.o %S/Inputs/no-undef-type-md.ll +; RUN: llvm-lto2 run -o a.out \ +; RUN: %t0.o \ +; RUN: -r=%t0.o,a, \ +; RUN: -r=%t0.o,b,pl \ +; RUN: %t1.o \ +; RUN: -r=%t1.o,a,pl \ +; RUN: | FileCheck --allow-empty --check-prefix=ERROR %s +; RUN llvm-nm a.out.0 a.out.1 -S | FileCheck %s + +; ERROR-NOT: expected a Function or null +; ERROR-NOT: i32 (%0*, i32*)* undef + +; CHECK: a.out.0: +; CHECK: a.out.1: + +; ModuleID = 'test.cpp.o' +source_filename = "test.cpp" +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define i32 @a() { +entry: + ret i32 0 +} + +define i32 @b() { +entry: + ret i32 0 +} + +!llvm.module.flags = !{!39} + +!39 = !{i32 5, !"CG Profile", !40} +!40 = !{!41} +!41 = !{i32 ()* @b, i32 ()* @a, i64 2594092}