[llvm-bugs] [Bug 49948] New: [WebAssembly] Cannot handle irreducible CFGs caused by unwind edges

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 13 02:53:25 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=49948

            Bug ID: 49948
           Summary: [WebAssembly] Cannot handle irreducible CFGs caused by
                    unwind edges
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: WebAssembly
          Assignee: unassignedbugs at nondot.org
          Reporter: aheejin at gmail.com
                CC: llvm-bugs at lists.llvm.org

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.
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210413/1ec0c3ff/attachment-0001.html>


More information about the llvm-bugs mailing list