MatzeB created this revision. MatzeB added reviewers: weiwang, aeubanks, nikic, MaskRay. Herald added subscribers: ormris, StephenFan, modimo, wenlei, arphaman, steven_wu, hiraditya, inglorion, mcrosier. Herald added a project: All. MatzeB requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Explicitly call `LLVMContext::setOpaquePointers` before loading any bitcode files when `-fthinlto-index` is used. Without this we can run into problematic situations when bitcode files with typed and opaque pointers are mixed. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D137475 Files: clang/lib/CodeGen/CodeGenAction.cpp clang/test/CodeGen/Inputs/thinlto-opaque.ll clang/test/CodeGen/thinlto-opaque-typed-mix.ll Index: clang/test/CodeGen/thinlto-opaque-typed-mix.ll =================================================================== --- /dev/null +++ clang/test/CodeGen/thinlto-opaque-typed-mix.ll @@ -0,0 +1,24 @@ +; REQUIRES: x86-registered-target +; Test that mixing bitcode file with opaque and typed pointers works. + +; RUN: mkdir -p %t +; RUN: opt -module-summary -o %t/typed.bc %s +; RUN: opt -module-summary -o %t/opaque.bc %S/Inputs/thinlto-opaque.ll +; RUN: llvm-lto2 run -thinlto-distributed-indexes %t/typed.bc %t/opaque.bc \ +; RUN: -o %t/native.o -r %t/typed.bc,main,plx -r %t/typed.bc,f2, \ +; RUN: -r %t/opaque.bc,f2,p + +; RUN: %clang_cc1 -triple x86_64-- -emit-obj -o %t/native.o %t/typed.bc \ +; RUN: -Wno-override-module \ +; RUN: -fthinlto-index=%t/typed.bc.thinlto.bc +; RUN: false + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64--" + +declare i8* @f2() + +define i32 @main() { + call i8* @f2() + ret i32 0 +} Index: clang/test/CodeGen/Inputs/thinlto-opaque.ll =================================================================== --- /dev/null +++ clang/test/CodeGen/Inputs/thinlto-opaque.ll @@ -0,0 +1,6 @@ +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64--" + +define ptr @f2() { + ret ptr null +} Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -1106,6 +1106,11 @@ M->setTargetTriple(CI.getTargetOpts().Triple); return M; } + + // For ThinLTO explicitely set opaque pointer mode to avoid problems when + // mixing opaque pointers and typed pointers bitcode files. + VMContext->setOpaquePointers(CI.getCodeGenOpts().OpaquePointers); + Expected<std::unique_ptr<llvm::Module>> MOrErr = Bm->parseModule(*VMContext); if (!MOrErr)
Index: clang/test/CodeGen/thinlto-opaque-typed-mix.ll =================================================================== --- /dev/null +++ clang/test/CodeGen/thinlto-opaque-typed-mix.ll @@ -0,0 +1,24 @@ +; REQUIRES: x86-registered-target +; Test that mixing bitcode file with opaque and typed pointers works. + +; RUN: mkdir -p %t +; RUN: opt -module-summary -o %t/typed.bc %s +; RUN: opt -module-summary -o %t/opaque.bc %S/Inputs/thinlto-opaque.ll +; RUN: llvm-lto2 run -thinlto-distributed-indexes %t/typed.bc %t/opaque.bc \ +; RUN: -o %t/native.o -r %t/typed.bc,main,plx -r %t/typed.bc,f2, \ +; RUN: -r %t/opaque.bc,f2,p + +; RUN: %clang_cc1 -triple x86_64-- -emit-obj -o %t/native.o %t/typed.bc \ +; RUN: -Wno-override-module \ +; RUN: -fthinlto-index=%t/typed.bc.thinlto.bc +; RUN: false + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64--" + +declare i8* @f2() + +define i32 @main() { + call i8* @f2() + ret i32 0 +} Index: clang/test/CodeGen/Inputs/thinlto-opaque.ll =================================================================== --- /dev/null +++ clang/test/CodeGen/Inputs/thinlto-opaque.ll @@ -0,0 +1,6 @@ +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64--" + +define ptr @f2() { + ret ptr null +} Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -1106,6 +1106,11 @@ M->setTargetTriple(CI.getTargetOpts().Triple); return M; } + + // For ThinLTO explicitely set opaque pointer mode to avoid problems when + // mixing opaque pointers and typed pointers bitcode files. + VMContext->setOpaquePointers(CI.getCodeGenOpts().OpaquePointers); + Expected<std::unique_ptr<llvm::Module>> MOrErr = Bm->parseModule(*VMContext); if (!MOrErr)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits