<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] Cannot handle irreducible CFGs caused by unwind edges"
href="https://bugs.llvm.org/show_bug.cgi?id=49948">49948</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[WebAssembly] Cannot handle irreducible CFGs caused by unwind edges
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</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>aheejin@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Currently irreducible CFGs are fixed by WebAssemblyFixIrreducibleControlFlow
pass, but irreducible CFGs caused by unwind edges are not handled by that pass.
For example,
test.cpp:
```
void f_maythrow();
void test() {
int x = 1;
lab:
try {
if (x) {
f_maythrow();
}
f_maythrow();
} catch (...) {
x = 0;
goto lab;
}
}
```
$ clang++ --target=wasm32-unknown-unknown -fwasm-exceptions -O1 -c -S
-emit-llvm test.cpp -o test.ll
test.ll:
```
define void @_Z4testv() personality i8* bitcast (i32 (...)*
@__gxx_wasm_personality_v0 to i8*) {
entry:
invoke void @_Z10f_maythrowv()
to label %if.end unwind label %catch.dispatch
if.end: ; preds = %catch.start,
%entry
invoke void @_Z10f_maythrowv()
to label %try.cont unwind label %catch.dispatch
catch.dispatch: ; preds = %if.end, %entry
%0 = catchswitch within none [label %catch.start] unwind to caller
catch.start: ; preds = %catch.dispatch
%1 = catchpad within %0 [i8* null]
%2 = call i8* @llvm.wasm.get.exception(token %1)
%3 = call i32 @llvm.wasm.get.ehselector(token %1)
%4 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ]
call void @__cxa_end_catch() [ "funclet"(token %1) ]
br label %if.end
try.cont: ; preds = %if.end
ret void
}
```
This CFG cannot be handled by the wasm backend.
$ llc -exception-model=wasm -mattr=+exception-handling -verify-machineinstrs
test.ll
crashes with this error message:
```
*** Bad machine code: MBB has unexpected successors which are not branch
targets, fallthrough, EHPads, or inlineasm_br targets. ***
- function: _Z4testv
- basic block: %bb.0 entry (0x8e5df0)
*** Bad machine code: MBB has unexpected successors which are not branch
targets, fallthrough, EHPads, or inlineasm_br targets. ***
- function: _Z4testv
- basic block: %bb.2 if.end (0x8e5ed0)
LLVM ERROR: Found 2 machine code errors.
```</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>