<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 - Error with ThinLTO: Invalid function metadata: outgoing forward refs"
   href="https://bugs.llvm.org/show_bug.cgi?id=35472">35472</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Error with ThinLTO: Invalid function metadata: outgoing forward refs
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>sunil_srivastava@playstation.sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>As shown below, a ThinLTO run fails with an assertion failure on two simple
files, trimmed from a larger code.

The attribute nodebug on ~Echo() is needed for this crash to occur. In this
trimmed example the ~Echo() default declaration has been added to be able to
put that attribute.

-------------------------------------------------------------------------------

$ clang++ --version
clang version 6.0.0 (trunk 319376)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: ....
$ clang++ -c a.cpp -o a.bc --std=c++11 -O0 -g -flto=thin
$ clang++ -c b.cpp -o b.bc --std=c++11 -O0 -g -flto=thin
$ llvm-lto -thinlto-action=run a.bc b.bc
ThinLTO: b.bc: error: Invalid function metadata: outgoing forward refs
(Producer: 'LLVM6.0.0svn' Reader: 'LLVM 6.0.0svn')
LLVM ERROR: importFunctions failed
$ cat a.cpp
struct Charlie {
    __attribute__((__always_inline__)) ~Charlie() { Golf = 0; }
    int Golf;
};

struct Delta {
    Charlie Foxtrot;
};

struct Echo {
    Charlie Foxtrot;
    __attribute__((nodebug)) ~Echo() = default;
};

extern void Bravo();

void Bravo() {
    Delta Hotel;
    Echo India;
}
$ cat b.cpp
extern void Bravo();
extern void Alpha();
void Alpha() { Bravo(); }
$
--------------------------------------------------------------------------
The crash occurs in BitcodeReader.cpp at a point where it expects all Metadata
forward-refs to be resolved, but they are not. Around line 4615:

  // Unexpected unresolved metadata about to be dropped.
  if (MDLoader->hasFwdRefs())
    return error("Invalid function metadata: outgoing forward refs");

I am filing this bug under clang/CodeGen under the assumption that the incoming
IR at this point is defective. If not, please go ahead and assign it to another
component.</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>