<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 - wasm: __cxa_atexit called with wrong signature function for global reference temporaries"
   href="https://bugs.llvm.org/show_bug.cgi?id=45876">45876</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>wasm: __cxa_atexit called with wrong signature function for global reference temporaries
          </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>All
          </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>Backend: WebAssembly
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>vladimir@pobox.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dan433584@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following snippet (from Dan Gohman):

struct B { B(); ~B(); };
namespace test {
  const B b1 = B();
  const B &b2 = B();
}

shows the problem -- the global_var_init that's generated to initialize the b2
reference is created with a call to __cxa_atexit that directly passes the
destructor.  A dtor's function signature doesn't match what __cxa_atexit needs,
so there's a signature mismatch at execution time (at app exit).

For normal global destructors, there's a path that explicitly checks for
whether cxa_atexit can be called directly with a destructor, and if not,
generates a helper:
<a href="https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGDeclCXX.cpp#L106">https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGDeclCXX.cpp#L106</a>

But the reference temporary destructor goes through here (I think), which
doesn't check if the platform allows destructors to be passed to cxa_atexit:
<a href="https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGExpr.cpp#L347">https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGExpr.cpp#L347</a>

Long-form discussion here:
<a href="https://bytecodealliance.zulipchat.com/#narrow/stream/206238-general/topic/__funcs_on_exit.20indirect.20call.20type.20mismatch.20with.20wasi-sdk">https://bytecodealliance.zulipchat.com/#narrow/stream/206238-general/topic/__funcs_on_exit.20indirect.20call.20type.20mismatch.20with.20wasi-sdk</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>