llvm-project/llvm/test/CodeGen/WebAssembly/lower-em-exceptions-allowed.ll

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.0 KiB
LLVM
Raw Normal View History

; RUN: opt < %s -wasm-lower-em-ehsjlj -emscripten-cxx-exceptions-allowed=do_catch -S | FileCheck %s
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown"
define void @dont_catch() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK-LABEL: @dont_catch(
entry:
invoke void @foo()
to label %invoke.cont unwind label %lpad
; CHECK: entry:
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: br label %invoke.cont
invoke.cont: ; preds = %entry
br label %try.cont
lpad: ; preds = %entry
%0 = landingpad { i8*, i32 }
catch i8* null
%1 = extractvalue { i8*, i32 } %0, 0
%2 = extractvalue { i8*, i32 } %0, 1
br label %catch
catch: ; preds = %lpad
%3 = call i8* @__cxa_begin_catch(i8* %1)
call void @__cxa_end_catch()
br label %try.cont
try.cont: ; preds = %catch, %invoke.cont
ret void
}
define void @do_catch() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK-LABEL: @do_catch(
entry:
invoke void @foo()
to label %invoke.cont unwind label %lpad
; CHECK: entry:
; CHECK-NEXT: store i32 0, i32*
[WebAssembly] Fix conflict between ret legalization and sjlj Summary: When the WebAssembly backend encounters a return type that doesn't fit within i32, SelectionDAG performs sret demotion, adding an additional argument to the start of the function that contains a pointer to an sret buffer to use instead. However, this conflicts with the emscripten sjlj lowering pass. There we translate calls like: ``` call {i32, i32} @foo() ``` into (in pseudo-llvm) ``` %addr = @foo call {i32, i32} @__invoke_{i32,i32}(%addr) ``` i.e. we perform an indirect call through an extra function. However, the sret transform now transforms this into the equivalent of ``` %addr = @foo %sret = alloca {i32, i32} call {i32, i32} @__invoke_{i32,i32}(%sret, %addr) ``` (while simultaneously translation the implementation of @foo as well). Unfortunately, this doesn't work out. The __invoke_ ABI expected the function address to be the first argument, causing crashes. There is several possible ways to fix this: 1. Implementing the sret rewrite at the IR level as well and performing it as part of lowering to __invoke 2. Fixing the wasm backend to recognize that __invoke has a special ABI 3. A change to the binaryen/emscripten ABI to recognize this situation This revision implements the middle option, teaching the backend to treat __invoke_ functions specially in sret lowering. This is achieved by 1) Introducing a new CallingConv ID for invoke functions 2) When this CallingConv ID is seen in the backend and the first argument is marked as sret (a function pointer would never be marked as sret), swapping the first two arguments. Reviewed By: tlively, aheejin Differential Revision: https://reviews.llvm.org/D65463 llvm-svn: 367935
2019-08-06 05:36:09 +08:00
; CHECK-NEXT: call cc{{.*}} void @__invoke_void(void ()* @foo)
invoke.cont: ; preds = %entry
br label %try.cont
lpad: ; preds = %entry
%0 = landingpad { i8*, i32 }
catch i8* null
%1 = extractvalue { i8*, i32 } %0, 0
%2 = extractvalue { i8*, i32 } %0, 1
br label %catch
catch: ; preds = %lpad
%3 = call i8* @__cxa_begin_catch(i8* %1)
call void @__cxa_end_catch()
br label %try.cont
try.cont: ; preds = %catch, %invoke.cont
ret void
}
declare void @foo()
declare i32 @__gxx_personality_v0(...)
declare i8* @__cxa_begin_catch(i8*)
declare void @__cxa_end_catch()