<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 - Clang++ segfault with -O2 -flto=thin"
   href="https://bugs.llvm.org/show_bug.cgi?id=49192">49192</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang++ segfault with -O2 -flto=thin
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++17
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ext-llvm@burakarslan.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24528" name="attach_24528" title="Crash report">attachment 24528</a> <a href="attachment.cgi?id=24528&action=edit" title="Crash report">[details]</a></span>
Crash report

First, apologies if this is the wrong place to report this bug, clang is a huge
project and it's a bit difficult to navigate for a newbie.

Here's the clang that segfaults:

Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Host is a macOS 10.15.4 (19E287) from <a href="http://dosdude1.com/catalina/">http://dosdude1.com/catalina/</a> running on
an old intel MBP

According to [1] this is a backend bug. Additionally, I can confirm it doesn't
occur with -O1 instead of -O2, or with the -flto=thin argument absent. In other
words, both -O2 -flto=thin must be passed for the segfault to occur.

It occurs only on one of the compilation units, and when I work around it by
passing -O1, it also occurs during the linking stage at the end.

I generated the foo.bc file and unlike what the guide says, the segfault
doesn't happen when the compiler is given the .bc file directly but fails with
an invalid forward reference error instead. Apple doesn't provide the llc
binary but I ran the following:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
foo.bc  -Wl,-flto=thin -Wl,-O2
foo.bc:41290:15: error: invalid forward reference to function '<some mangled
name>' with wrong type

It's the same result with -Wl,-relocation-model=static or
-Wl,-relocation-model=pic

I downloaded the clang-11 darwin binaries from [2] and the result is the same
using the llc command from the archive.

I also have the preprocessed source code and the full command line from the
crash report, as well as the foo.bc file but I can't say I'm comfortable with
posting them on a public forum. Is there another channel (eg. someone's email)
I can use to post additional data?

I also have clang 11.0.0 running on Linux on another machine compiling the same
code with similar flags. The relevant compilation operation runs just fine but
the linking stage still fails with a segfault. I have
/usr/x86_64-pc-linux-gnu/binutils-bin/lib/bfd-plugins/LLVMgold.so file present
though nothing in the command line seems to indicate that it's using the gold
linker. I'm not sure whether -flto=thin implies gold linker. Should I report
that in another bug report?

I'll be happy to help if you need additional info.

[1]: <a href="https://www.llvm.org/docs/HowToSubmitABug.html#crashing-bugs">https://www.llvm.org/docs/HowToSubmitABug.html#crashing-bugs</a>
[2]: <a href="https://releases.llvm.org/download.html">https://releases.llvm.org/download.html</a></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>