diff --git a/llvm/include/llvm/LTO/Config.h b/llvm/include/llvm/LTO/Config.h --- a/llvm/include/llvm/LTO/Config.h +++ b/llvm/include/llvm/LTO/Config.h @@ -288,6 +288,12 @@ enableDebugTypeODRUniquing(); setDiagnosticHandler( std::make_unique(&DiagHandler), true); + // Don't leave the decision to use opaque pointers to the BitcodeReader + // as we may be mixing bitcode using opaque and typed pointers and we can + // only upgrade typed pointers to opaque pointers. + if (!hasSetOpaquePointersValue()) { + setOpaquePointers(true); + } } DiagnosticHandlerFunction DiagHandler; }; diff --git a/llvm/test/LTO/X86/Inputs/opaque-pointers.ll b/llvm/test/LTO/X86/Inputs/opaque-pointers.ll new file mode 100644 --- /dev/null +++ b/llvm/test/LTO/X86/Inputs/opaque-pointers.ll @@ -0,0 +1,7 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define i64 @foo(ptr %p) { + %t = load i64, ptr %p + ret i64 %t +} diff --git a/llvm/test/LTO/X86/mix-opaque-typed.ll b/llvm/test/LTO/X86/mix-opaque-typed.ll new file mode 100644 --- /dev/null +++ b/llvm/test/LTO/X86/mix-opaque-typed.ll @@ -0,0 +1,19 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: llvm-as -opaque-pointers=0 %s -o %t-typed.bc +; RUN: llvm-as -opaque-pointers=1 %S/Inputs/opaque-pointers.ll -o %t-opaque.bc +; RUN: llvm-lto2 run -o %t-lto.bc %t-typed.bc %t-opaque.bc -save-temps \ +; RUN: -r %t-typed.bc,call_foo,px -r %t-typed.bc,foo,l \ +; RUN: -r %t-opaque.bc,foo,px +; RUN: opt -S -o - %t-lto.bc.0.4.opt.bc | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare i64 @foo(i64* %p); + +define i64 @call_foo(i64* %p) { + ; CHECK-LABEL: define i64 @call_foo(ptr nocapture readonly %p) local_unnamed_addr #0 { + ; CHECK-NEXT: %t.i = load i64, ptr %p, align 8 + %t = call i64 @foo(i64* %p) + ret i64 %t +}