mirror-llvm-project/llvm/test/Transforms/SimpleLoopUnswitch/catchswitch.ll
Demetrius Kanios 1d4e04f7a7
[WebAssembly] Call EH personality function instead of Unwind_CallPersonality (#209282)
On Wasm, it's not currently possibly to change which `personality` is
attached to a given IR function. This is primarily because no matter
what `personality` is attached, codegen creates a call to a
`Unwind_CallPersonality` wrapper hard-coded to call c++abi's
personality.

In order to allow alternative personalities without introducing bloat at
each personality call site, this PR adjusts the ABI of the personality
on Wasm. `Unwind_CallPersonality` is moved to `libcxxabi` under the name
`__gxx_wasm_personality_v0`, with the "real" personality code renamed
`__gxx_personality_imp` and called by `__gxx_wasm_personality_v0` (after
resetting the landing pad context).

The signature of EH personalities on Wasm is now `int personality(void*
exception_object)` (where the int return is `_Unwind_Reason_Code` and
the `void*` is `_Unwind_Exception*`), and personalities are expected to
`__wasm_lpad_context.selector = 0;`.

Based on #175202
2026-07-28 20:05:45 -07:00

32 lines
1 KiB
LLVM

; RUN: opt -passes='simple-loop-unswitch<nontrivial>' < %s -S | FileCheck %s
; CHECK: if.end{{.*}}:
; CHECK-NOT: if.end{{.*}}:
declare i32 @__gxx_wasm_personality_v0(ptr)
declare void @foo()
define void @test(i1 %arg) personality ptr @__gxx_wasm_personality_v0 {
entry:
br label %while.body
while.body: ; preds = %cleanup, %entry
br i1 %arg, label %if.end, label %if.then
if.then: ; preds = %while.body
br label %if.end
if.end: ; preds = %if.then, %while.body
invoke void @foo()
to label %cleanup unwind label %catch.dispatch
catch.dispatch: ; preds = %invoke.cont, %if.end
%0 = catchswitch within none [label %catch] unwind to caller
catch: ; preds = %catch.dispatch
%1 = catchpad within %0 [ptr null]
unreachable
cleanup: ; preds = %invoke.cont
br label %while.body
}