[PATCH] D112297: [LTO] Fix assertion failed when flushing bitcode incrementally for LTO output.

Xu Mingjie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 22 07:35:47 PDT 2021


Enna1 added a comment.

On default, command line option `FlushThreshold` is 512(M) defined in llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

  static cl::opt<uint32_t> FlushThreshold(
      "bitcode-flush-threshold", cl::Hidden, cl::init(512),
      cl::desc("The threshold (unit M) for flushing LLVM bitcode."));

and AFAIK, there is no command line option for lld to modify `FlushThreshold` value.
So to reproduce this assertion failed in a tiny testcase, we need modify `FlushThreshold` to 0 manually in BitcodeWriter constructor:

  BitcodeWriter::BitcodeWriter(SmallVectorImpl<char> &Buffer, raw_fd_stream *FS)
      : Buffer(Buffer), Stream(new BitstreamWriter(Buffer, FS, /*FlushThreshold*/0)) {
    writeBitcodeHeader(*Stream);
  }

Then we can trigger this assertion failed:

  $ clang -c -flto tu1.cpp -o tu1.o
  $ clang -c -flto tu2.cpp -o tu2.o
  $ clang -fuse-ld=lld -flto -Wl,--plugin-opt=emit-llvm tu1.o tu2.o -o /dev/null

The content of tu1.cpp and tu2.cpp:

  // tu1.cpp
  int unused(int a);
  int probably_inlined(int a);
  int main(int argc, const char *argv[]) {
    return probably_inlined(argc);
  }

  // tu2.cpp
  int unused(int a) {
    return a + 1;
  }
  int probably_inlined(int a) {
    return a + 2;
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112297/new/

https://reviews.llvm.org/D112297



More information about the llvm-commits mailing list