hmelder wrote:

```objc
extern void might_throw(void);

void test_simple_try_catch(void) {
  @try {
    might_throw();
  } @catch (id e) {
  } @catch (id e) {
  } 
}
```

I compiled your example with `-target wasm32-unknown-emscripten 
-fwasm-exceptions -mllvm -wasm-use-legacy-eh=false -fobjc-runtime=gnustep-2.2 
-S -emit-llvm` and the generated IR looks good.

<details>
  <summary>The generated IR</summary>
  
```llvm
; Function Attrs: noinline optnone
define hidden void @test_simple_try_catch() #0 personality ptr 
@__gxx_wasm_personality_v0 {
entry:
  %exn.slot = alloca ptr, align 4
  %e = alloca ptr, align 4
  %e5 = alloca ptr, align 4
  invoke void @might_throw()
          to label %invoke.cont unwind label %catch.dispatch

catch.dispatch:                                   ; preds = %entry
  %0 = catchswitch within none [label %catch.start] unwind to caller

catch.start:                                      ; preds = %catch.dispatch
  %1 = catchpad within %0 [ptr @0, ptr @0]
  %2 = call ptr @llvm.wasm.get.exception(token %1)
  store ptr %2, ptr %exn.slot, align 4
  %3 = call i32 @llvm.wasm.get.ehselector(token %1)
  %4 = call i32 @llvm.eh.typeid.for.p0(ptr @0) #5
  %matches = icmp eq i32 %3, %4
  br i1 %matches, label %catch, label %catch.fallthrough

catch.fallthrough:                                ; preds = %catch.start
  %5 = call i32 @llvm.eh.typeid.for.p0(ptr @0) #5
  %matches1 = icmp eq i32 %3, %5
  br i1 %matches1, label %catch2, label %rethrow

rethrow:                                          ; preds = %catch.fallthrough
  call void @llvm.wasm.rethrow() #4 [ "funclet"(token %1) ]
  unreachable

invoke.cont:                                      ; preds = %entry
  br label %eh.cont

eh.cont:                                          ; preds = %invoke.cont, 
%catchret.dest6, %catchret.dest
  ret void

catch:                                            ; preds = %catch.start
  %exn = load ptr, ptr %exn.slot, align 4
  %exn.adjusted = call ptr @objc_begin_catch(ptr %exn) #5 [ "funclet"(token %1) 
]
  store ptr %exn.adjusted, ptr %e, align 4
  call void @objc_end_catch() #5 [ "funclet"(token %1) ]
  catchret from %1 to label %catchret.dest

catchret.dest:                                    ; preds = %catch
  br label %eh.cont

catch2:                                           ; preds = %catch.fallthrough
  %exn3 = load ptr, ptr %exn.slot, align 4
  %exn.adjusted4 = call ptr @objc_begin_catch(ptr %exn3) #5 [ "funclet"(token 
%1) ]
  store ptr %exn.adjusted4, ptr %e5, align 4
  call void @objc_end_catch() #5 [ "funclet"(token %1) ]
  catchret from %1 to label %catchret.dest6

catchret.dest6:                                   ; preds = %catch2
  br label %eh.cont
}
```
</details>

https://github.com/llvm/llvm-project/pull/171038
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to