<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 - WebAssembly hangs on switch with __builtin_unreachable in default."
   href="https://bugs.llvm.org/show_bug.cgi?id=46363">46363</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>WebAssembly hangs on switch with __builtin_unreachable in default.
          </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>-New Bugs
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>With

$ emsdk/upstream/bin/clang-11 --version
clang version 11.0.0
(/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project
613c4a87ba9bb39d1927402f4dd4c1ef1f9a02f7)

$cat > repro.cpp <<EOF
int CToI(char c) {
    switch (c) {
        case 'r': return 0;
        case 'g': return 1;
        case 'b': return 2;
        case 'a': return 3;
        case '0': return 4;
        case '1': return 5;
        default:
            __builtin_unreachable();
    }
}
EOF

$ emsdk/upstream/bin/clang-11 -cc1 -triple wasm32-unknown-emscripten -emit-obj
-disable-free -main-file-name repro.cpp -mrelocation-model static
-mframe-pointer=none -fno-rounding-math -mconstructor-aliases -target-cpu
generic -fvisibility hidden -dwarf-column-info -debugger-tuning=gdb -O3
-std=c++17 -nostdsysteminc -mllvm -combiner-global-alias-analysis=false -mllvm
-enable-emscripten-sjlj -mllvm -disable-lsr -o repro.o -x c++ repro.cpp

the clang-11 invocation will hang at any optimization level other than -O0.
This can also currently be reproduced on CompilerExplorer with the above code
with the "WebAssembly clang (trunk)" compiler and any optimization level over
-O0.

This seems to be a fairly recent regression as this was known to work at some
point in the not too distant past (will attempt to bisect). Removing any of the
'case' statements seems to make it work, this seems to require at least six
cases to reproduce.</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>