[PATCH] D125847: LTO: Enable opaque pointers by default.

Matthias Braun via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 17 20:39:29 PDT 2022


MatzeB created this revision.
MatzeB added reviewers: aeubanks, nikic.
Herald added subscribers: ormris, modimo, wenlei, steven_wu, hiraditya, inglorion, mcrosier.
Herald added a project: All.
MatzeB requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

LTO code may end up mixing bitcode files with typed pointers and opaque
pointers. However since we can only upgrade bitcode using typed pointers
to opaque pointer but not the other way can randomly fail when the first
file happens to use typed pointers and another opaque pointers.

This enables opaque pointers in LTO by default unless the
`-opaque-pointers` commandline option was specified.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125847

Files:
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp


Index: llvm/lib/LTO/LTOBackend.cpp
===================================================================
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -419,6 +419,14 @@
         CodegenThreadPool.async(
             [&](const SmallString<0> &BC, unsigned ThreadId) {
               LTOLLVMContext Ctx(C);
+
+              // Don't leave the decision to use opaque pointers to the reader
+              // as we may be mixing bitcode using opaque and typed pointers and
+              // we can only upgrade typed pointers to opaque pointers.
+              if (!Ctx.hasSetOpaquePointersValue()) {
+                Ctx.setOpaquePointers(true);
+              }
+
               Expected<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(
                   MemoryBufferRef(StringRef(BC.data(), BC.size()), "ld-temp.o"),
                   Ctx);
Index: llvm/lib/LTO/LTO.cpp
===================================================================
--- llvm/lib/LTO/LTO.cpp
+++ llvm/lib/LTO/LTO.cpp
@@ -1216,6 +1216,14 @@
       MapVector<StringRef, BitcodeModule> &ModuleMap) {
     auto RunThinBackend = [&](AddStreamFn AddStream) {
       LTOLLVMContext BackendContext(Conf);
+
+      // Don't leave the decision to use opaque pointers to the reader as we
+      // may be mixing bitcode using opaque and typed pointers and we can
+      // only upgrade typed pointers to opaque pointers.
+      if (!BackendContext.hasSetOpaquePointersValue()) {
+        BackendContext.setOpaquePointers(true);
+      }
+
       Expected<std::unique_ptr<Module>> MOrErr = BM.parseModule(BackendContext);
       if (!MOrErr)
         return MOrErr.takeError();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125847.430231.patch
Type: text/x-patch
Size: 1659 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220518/71921604/attachment.bin>


More information about the llvm-commits mailing list