<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - assert in BitcodeWriter running llvm-as with partial LTO summaries"
   href="https://bugs.llvm.org/show_bug.cgi?id=44942">44942</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>assert in BitcodeWriter running llvm-as with partial LTO summaries
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Bitcode Writer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sbc@chromium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I'm seeing this assert fire if ThinLTO summaries are missing for any symbol:

```
llvm-as test.o.ll
llvm-as:
/usr/local/google/home/sbc/dev/wasm/llvm-project/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:3854:
void (anonymous
namespace)::ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary():
Assertion `F.isDeclaration()' failed.
Stack dump:
0.      Program arguments: ../llvm-build/bin/llvm-as test.o.ll 
 #0 0x00007f6e6aa0ed64 PrintStackTraceSignalHandler(void*)
(/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMSupport.so.11git+0x191d64)
 #1 0x00007f6e6aa0c8ce llvm::sys::RunSignalHandlers()
(/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMSupport.so.11git+0x18f8ce)
 #2 0x00007f6e6aa0f01c SignalHandler(int)
(/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMSupport.so.11git+0x19201c)
 #3 0x00007f6e6a839520 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x13520)
 #4 0x00007f6e6a366081 raise
/build/glibc-G5rUEF/glibc-2.29/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f6e6a351535 abort /build/glibc-G5rUEF/glibc-2.29/stdlib/abort.c:81:7
 #6 0x00007f6e6a35140f _nl_load_domain
/build/glibc-G5rUEF/glibc-2.29/intl/loadmsgcat.c:1177:9
 #7 0x00007f6e6a35eb92 (/lib/x86_64-linux-gnu/libc.so.6+0x32b92)
 #8 0x00007f6e6aede1d6 (anonymous
namespace)::ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary()
(/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMBitWriter.so.11git+0x1f1d6)
 #9 0x00007f6e6aece1ee (anonymous namespace)::ModuleBitcodeWriter::write()
(/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMBitWriter.so.11git+0xf1ee)
#10 0x00007f6e6aec9aff llvm::BitcodeWriter::writeModule(llvm::Module const&,
bool, llvm::ModuleSummaryIndex const*, bool, std::array<unsigned int, 5ul>*)
(/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMBitWriter.so.11git+0xaaff)
#11 0x00007f6e6aed0995 llvm::WriteBitcodeToFile(llvm::Module const&,
llvm::raw_ostream&, bool, llvm::ModuleSummaryIndex const*, bool,
std::array<unsigned int, 5ul>*)
(/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMBitWriter.so.11git+0x11995)
#12 0x00000000004048b5 main (../llvm-build/bin/llvm-as+0x4048b5)
#13 0x00007f6e6a352bbb __libc_start_main
/build/glibc-G5rUEF/glibc-2.29/csu/../csu/libc-start.c:342:3
#14 0x000000000040402a _start (../llvm-build/bin/llvm-as+0x40402a)
Aborted
```

Reproduction steps:

```
$ cat test.c 
int foo() {
  return 1;
}

int bar() {
  return 1;
}
$ clang -flto=thin -c -O2 test.c 
$ llvm-dis test.o
# Edit test.o.ll removing the final line which is the LTO summary for bar
$ llvm-as test.o.ll
```

Now, clearly the issue here is that LTO summaries are incomplete but I would
expect an error message telling me that rather than an assert.

I'm not sure what the implications having partial thing LTO summaries is but
its possible the fix might just be to remove this assertion?  My use case is
that I want to peform some manual editing on the bitcode text produced by clang
with LTO, but I won't want to have to generate summaries for symbols that I
add.  My current workaround is to remove LTO summaries completely when I
perform such additions (its not a huge deal since this is a debug feature
anyway).</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>