<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 - Invalid wasm with -fwasm-exceptions"
   href="https://bugs.llvm.org/show_bug.cgi?id=47413">47413</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Invalid wasm with -fwasm-exceptions
          </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>Backend: WebAssembly
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>alonzakai@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23924" name="attach_23924" title="wasm file from LLVM">attachment 23924</a> <a href="attachment.cgi?id=23924&action=edit" title="wasm file from LLVM">[details]</a></span>
wasm file from LLVM

Testcase (from wasm0.test_exceptions_3):

===
#include <iostream>

int main(int argc, char **argv)
{
  int arg = argv[1][0] - '0';
  try {
    if (arg == 2) throw std::runtime_error("Hello");
  } catch(const char * ex) {
    std::cout << "Caught C string: " << ex << std::endl;
  } catch(...) {
  }

  std::cout << "Done.\n";
}
===

The output from LLVM is incorrect, but after binaryen processing it becomes
valid somehow (I think this is why this wasn't noticed earlier - removing the
binaryen processing locally uncovered it). To see the LLVM output, can build
with

EMCC_DEBUG=1 emcc test.cpp -fwasm-exceptions

and then look at /tmp/emscripten_temp/emcc-0-base.wasm (also attached). That
file looks invalid, v8 says

Compiling function #420 failed: not enough arguments on the stack for catch,
expected 1 more @+62235

and wabt says

emcc-0-base.wasm:000f0b7: error: type mismatch in try block, expected [i32] but
got []
[..]</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>