|
| 1 | +; REQUIRES: system-darwin && host-unwind-supports-jit |
| 2 | +; RUN: lli -jit-kind=orc %s |
| 3 | +; |
| 4 | +; Check that we can throw exceptions from no-fp functions. On systems that |
| 5 | +; support compact-unwind this implicitly tests that we correctly handle |
| 6 | +; unwind-info records that depend on DWARF FDEs. |
| 7 | + |
| 8 | +@_ZTIi = external constant ptr |
| 9 | + |
| 10 | +declare ptr @__cxa_allocate_exception(i64) |
| 11 | +declare void @__cxa_throw(ptr, ptr, ptr) |
| 12 | +declare ptr @__cxa_begin_catch(ptr) |
| 13 | +declare void @__cxa_end_catch() |
| 14 | +declare i32 @__gxx_personality_v0(...) |
| 15 | +declare i32 @llvm.eh.typeid.for.p0(ptr) |
| 16 | + |
| 17 | +define void @_Z3foov() "frame-pointer"="none" { |
| 18 | +entry: |
| 19 | + %exception = tail call ptr @__cxa_allocate_exception(i64 4) |
| 20 | + store i32 42, ptr %exception |
| 21 | + tail call void @__cxa_throw(ptr %exception, ptr nonnull @_ZTIi, ptr null) |
| 22 | + unreachable |
| 23 | +} |
| 24 | + |
| 25 | +define i32 @main(i32 %argc, ptr %argv) "frame-pointer"="all" personality ptr @__gxx_personality_v0 { |
| 26 | +entry: |
| 27 | + invoke void @_Z3foov() |
| 28 | + to label %return.unreachable unwind label %lpad |
| 29 | + |
| 30 | +lpad: |
| 31 | + %0 = landingpad { ptr, i32 } |
| 32 | + catch ptr @_ZTIi |
| 33 | + %1 = extractvalue { ptr, i32 } %0, 1 |
| 34 | + %2 = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTIi) |
| 35 | + %matches = icmp eq i32 %1, %2 |
| 36 | + br i1 %matches, label %catch, label %eh.resume |
| 37 | + |
| 38 | +catch: |
| 39 | + %3 = extractvalue { ptr, i32 } %0, 0 |
| 40 | + %4 = tail call ptr @__cxa_begin_catch(ptr %3) |
| 41 | + %5 = load i32, ptr %4 |
| 42 | + %sub = sub nsw i32 42, %5 |
| 43 | + tail call void @__cxa_end_catch() |
| 44 | + ret i32 %sub |
| 45 | + |
| 46 | +return.unreachable: |
| 47 | + unreachable |
| 48 | + |
| 49 | +eh.resume: |
| 50 | + resume { ptr, i32 } %0 |
| 51 | +} |
0 commit comments