1; RUN: llc < %s --mtriple=wasm32-unknown-unknown -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling | FileCheck %s -check-prefixes=CHECK,NOPIC -DPTR=32 2; RUN: llc < %s --mtriple=wasm64-unknown-unknown -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling | FileCheck %s -check-prefixes=CHECK,NOPIC -DPTR=64 3; RUN: llc < %s --mtriple=wasm32-unknown-emscripten -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling | FileCheck %s -check-prefixes=CHECK,NOPIC -DPTR=32 4; RUN: llc < %s --mtriple=wasm64-unknown-emscripten -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling | FileCheck %s -check-prefixes=CHECK,NOPIC -DPTR=64 5; RUN: llc < %s --mtriple=wasm32-unknown-emscripten -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling -relocation-model=pic | FileCheck %s -check-prefixes=CHECK,PIC -DPTR=32 6; RUN: llc < %s --mtriple=wasm64-unknown-emscripten -wasm-disable-explicit-locals -wasm-keep-registers -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling -relocation-model=pic | FileCheck %s -check-prefixes=CHECK,PIC -DPTR=64 7 8@_ZTIi = external constant ptr 9@_ZTIf = external constant ptr 10@_ZTId = external constant ptr 11 12; Single catch (...) does not need an exception table. 13; 14; try { 15; may_throw(); 16; } catch (...) { 17; } 18; CHECK-LABEL: test0: 19; CHECK-NOT: GCC_except_table 20define void @test0() personality ptr @__gxx_wasm_personality_v0 { 21entry: 22 invoke void @may_throw() 23 to label %try.cont unwind label %catch.dispatch 24 25catch.dispatch: ; preds = %entry 26 %0 = catchswitch within none [label %catch.start] unwind to caller 27 28catch.start: ; preds = %catch.dispatch 29 %1 = catchpad within %0 [ptr null] 30 %2 = call ptr @llvm.wasm.get.exception(token %1) 31 %3 = call i32 @llvm.wasm.get.ehselector(token %1) 32 %4 = call ptr @__cxa_begin_catch(ptr %2) [ "funclet"(token %1) ] 33 call void @__cxa_end_catch() [ "funclet"(token %1) ] 34 catchret from %1 to label %try.cont 35 36try.cont: ; preds = %entry, %catch.start 37 ret void 38} 39 40; Exception table generation + shared action test. 41; 42; try { 43; may_throw(); 44; } catch (int) { 45; } catch (float) { 46; } catch (double) { 47; } catch (...) { 48; } 49; 50; try { 51; may_throw(); 52; } catch (double) { 53; } catch (...) { 54; } 55; 56; try { 57; may_throw(); 58; } catch (int) { 59; } catch (float) { 60; } 61; 62; There are three landing pads. The second landing pad should share action table 63; entries with the first landing pad because they end with the same sequence 64; (double -> ...). But the third landing table cannot share action table entries 65; with others, so it should create its own entries. 66 67; CHECK-LABEL: test1: 68; In static linking, we load GCC_except_table as a constant directly. 69; NOPIC: i[[PTR]].const $push[[CONTEXT:.*]]=, __wasm_lpad_context 70; NOPIC-NEXT: i[[PTR]].const $push[[EXCEPT_TABLE:.*]]=, GCC_except_table1 71; NOPIC-NEXT: i[[PTR]].store {{[48]}}($pop[[CONTEXT]]), $pop[[EXCEPT_TABLE]] 72 73; In case of PIC, we make GCC_except_table symbols a relative on based on 74; __memory_base. 75; PIC: global.get $push[[CONTEXT:.*]]=, __wasm_lpad_context@GOT 76; PIC-NEXT: local.tee $push{{.*}}=, $[[CONTEXT_LOCAL:.*]]=, $pop[[CONTEXT]] 77; PIC: global.get $push[[MEMORY_BASE:.*]]=, __memory_base 78; PIC-NEXT: i[[PTR]].const $push[[EXCEPT_TABLE_REL:.*]]=, GCC_except_table1@MBREL 79; PIC-NEXT: i[[PTR]].add $push[[EXCEPT_TABLE:.*]]=, $pop[[MEMORY_BASE]], $pop[[EXCEPT_TABLE_REL]] 80; PIC-NEXT: i[[PTR]].store {{[48]}}($[[CONTEXT_LOCAL]]), $pop[[EXCEPT_TABLE]] 81 82; CHECK: .section .rodata.gcc_except_table,"",@ 83; CHECK-NEXT: .p2align 2 84; CHECK-NEXT: GCC_except_table[[START:[0-9]+]]: 85; CHECK-NEXT: .Lexception0: 86; CHECK-NEXT: .int8 255 # @LPStart Encoding = omit 87; CHECK-NEXT: .int8 0 # @TType Encoding = absptr 88; CHECK-NEXT: .uleb128 .Lttbase0-.Lttbaseref0 89; CHECK-NEXT: .Lttbaseref0: 90; CHECK-NEXT: .int8 1 # Call site Encoding = uleb128 91; CHECK-NEXT: .uleb128 .Lcst_end0-.Lcst_begin0 92; CHECK-NEXT: .Lcst_begin0: 93; CHECK-NEXT: .int8 0 # >> Call Site 0 << 94; CHECK-NEXT: # On exception at call site 0 95; CHECK-NEXT: .int8 7 # Action: 4 96; CHECK-NEXT: .int8 1 # >> Call Site 1 << 97; CHECK-NEXT: # On exception at call site 1 98; CHECK-NEXT: .int8 3 # Action: 2 99; CHECK-NEXT: .int8 2 # >> Call Site 2 << 100; CHECK-NEXT: # On exception at call site 2 101; CHECK-NEXT: .int8 11 # Action: 6 102; CHECK-NEXT: .Lcst_end0: 103; CHECK-NEXT: .int8 1 # >> Action Record 1 << 104; CHECK-NEXT: # Catch TypeInfo 1 105; CHECK-NEXT: .int8 0 # No further actions 106; CHECK-NEXT: .int8 2 # >> Action Record 2 << 107; CHECK-NEXT: # Catch TypeInfo 2 108; CHECK-NEXT: .int8 125 # Continue to action 1 109; CHECK-NEXT: .int8 3 # >> Action Record 3 << 110; CHECK-NEXT: # Catch TypeInfo 3 111; CHECK-NEXT: .int8 125 # Continue to action 2 112; CHECK-NEXT: .int8 4 # >> Action Record 4 << 113; CHECK-NEXT: # Catch TypeInfo 4 114; CHECK-NEXT: .int8 125 # Continue to action 3 115; CHECK-NEXT: .int8 3 # >> Action Record 5 << 116; CHECK-NEXT: # Catch TypeInfo 3 117; CHECK-NEXT: .int8 0 # No further actions 118; CHECK-NEXT: .int8 4 # >> Action Record 6 << 119; CHECK-NEXT: # Catch TypeInfo 4 120; CHECK-NEXT: .int8 125 # Continue to action 5 121; CHECK-NEXT: .p2align 2 122; CHECK-NEXT: # >> Catch TypeInfos << 123; CHECK-NEXT: .int[[PTR]] _ZTIi # TypeInfo 4 124; CHECK-NEXT: .int[[PTR]] _ZTIf # TypeInfo 3 125; CHECK-NEXT: .int[[PTR]] _ZTId # TypeInfo 2 126; CHECK-NEXT: .int[[PTR]] 0 # TypeInfo 1 127; CHECK-NEXT: .Lttbase0: 128; CHECK-NEXT: .p2align 2 129; CHECK-NEXT: .LGCC_except_table_end[[END:[0-9]+]]: 130; CHECK-NEXT: .size GCC_except_table[[START]], .LGCC_except_table_end[[END]]-GCC_except_table[[START]] 131define void @test1() personality ptr @__gxx_wasm_personality_v0 { 132entry: 133 invoke void @may_throw() 134 to label %try.cont unwind label %catch.dispatch 135 136catch.dispatch: ; preds = %entry 137 %0 = catchswitch within none [label %catch.start] unwind to caller 138 139catch.start: ; preds = %catch.dispatch 140 %1 = catchpad within %0 [ptr @_ZTIi, ptr @_ZTIf, ptr @_ZTId, ptr null] 141 %2 = call ptr @llvm.wasm.get.exception(token %1) 142 %3 = call i32 @llvm.wasm.get.ehselector(token %1) 143 %4 = call i32 @llvm.eh.typeid.for(ptr @_ZTIi) 144 %matches = icmp eq i32 %3, %4 145 br i1 %matches, label %catch10, label %catch.fallthrough 146 147catch10: ; preds = %catch.start 148 %5 = call ptr @__cxa_begin_catch(ptr %2) [ "funclet"(token %1) ] 149 %6 = load i32, ptr %5, align 4 150 call void @__cxa_end_catch() [ "funclet"(token %1) ] 151 catchret from %1 to label %try.cont 152 153try.cont: ; preds = %entry, %catch, %catch4, %catch7, %catch10 154 invoke void @may_throw() 155 to label %try.cont23 unwind label %catch.dispatch14 156 157catch.dispatch14: ; preds = %try.cont 158 %7 = catchswitch within none [label %catch.start15] unwind to caller 159 160catch.start15: ; preds = %catch.dispatch14 161 %8 = catchpad within %7 [ptr @_ZTId, ptr null] 162 %9 = call ptr @llvm.wasm.get.exception(token %8) 163 %10 = call i32 @llvm.wasm.get.ehselector(token %8) 164 %11 = call i32 @llvm.eh.typeid.for(ptr @_ZTId) 165 %matches16 = icmp eq i32 %10, %11 166 %12 = call ptr @__cxa_begin_catch(ptr %9) [ "funclet"(token %8) ] 167 br i1 %matches16, label %catch20, label %catch17 168 169catch20: ; preds = %catch.start15 170 %13 = load double, ptr %12, align 8 171 call void @__cxa_end_catch() [ "funclet"(token %8) ] 172 catchret from %8 to label %try.cont23 173 174try.cont23: ; preds = %try.cont, %catch17, %catch20 175 invoke void @may_throw() 176 to label %try.cont36 unwind label %catch.dispatch25 177 178catch.dispatch25: ; preds = %try.cont23 179 %14 = catchswitch within none [label %catch.start26] unwind to caller 180 181catch.start26: ; preds = %catch.dispatch25 182 %15 = catchpad within %14 [ptr @_ZTIi, ptr @_ZTIf] 183 %16 = call ptr @llvm.wasm.get.exception(token %15) 184 %17 = call i32 @llvm.wasm.get.ehselector(token %15) 185 %18 = call i32 @llvm.eh.typeid.for(ptr @_ZTIi) 186 %matches27 = icmp eq i32 %17, %18 187 br i1 %matches27, label %catch33, label %catch.fallthrough28 188 189catch33: ; preds = %catch.start26 190 %19 = call ptr @__cxa_begin_catch(ptr %16) [ "funclet"(token %15) ] 191 %20 = load i32, ptr %19, align 4 192 call void @__cxa_end_catch() [ "funclet"(token %15) ] 193 catchret from %15 to label %try.cont36 194 195catch.fallthrough28: ; preds = %catch.start26 196 %21 = call i32 @llvm.eh.typeid.for(ptr @_ZTIf) 197 %matches29 = icmp eq i32 %17, %21 198 br i1 %matches29, label %catch30, label %rethrow 199 200catch30: ; preds = %catch.fallthrough28 201 %22 = call ptr @__cxa_begin_catch(ptr %16) [ "funclet"(token %15) ] 202 %23 = load float, ptr %22, align 4 203 call void @__cxa_end_catch() [ "funclet"(token %15) ] 204 catchret from %15 to label %try.cont36 205 206rethrow: ; preds = %catch.fallthrough28 207 call void @__cxa_rethrow() [ "funclet"(token %15) ] 208 unreachable 209 210try.cont36: ; preds = %try.cont23, %catch30, %catch33 211 ret void 212 213catch17: ; preds = %catch.start15 214 call void @__cxa_end_catch() [ "funclet"(token %8) ] 215 catchret from %8 to label %try.cont23 216 217catch.fallthrough: ; preds = %catch.start 218 %24 = call i32 @llvm.eh.typeid.for(ptr @_ZTIf) 219 %matches1 = icmp eq i32 %3, %24 220 br i1 %matches1, label %catch7, label %catch.fallthrough2 221 222catch7: ; preds = %catch.fallthrough 223 %25 = call ptr @__cxa_begin_catch(ptr %2) [ "funclet"(token %1) ] 224 %26 = load float, ptr %25, align 4 225 call void @__cxa_end_catch() [ "funclet"(token %1) ] 226 catchret from %1 to label %try.cont 227 228catch.fallthrough2: ; preds = %catch.fallthrough 229 %27 = call i32 @llvm.eh.typeid.for(ptr @_ZTId) 230 %matches3 = icmp eq i32 %3, %27 231 %28 = call ptr @__cxa_begin_catch(ptr %2) [ "funclet"(token %1) ] 232 br i1 %matches3, label %catch4, label %catch 233 234catch4: ; preds = %catch.fallthrough2 235 %29 = load double, ptr %28, align 8 236 call void @__cxa_end_catch() [ "funclet"(token %1) ] 237 catchret from %1 to label %try.cont 238 239catch: ; preds = %catch.fallthrough2 240 call void @__cxa_end_catch() [ "funclet"(token %1) ] 241 catchret from %1 to label %try.cont 242} 243 244declare void @may_throw() 245; Function Attrs: nounwind 246declare i32 @llvm.eh.typeid.for(ptr) #0 247; Function Attrs: nounwind 248declare ptr @llvm.wasm.get.exception(token) #0 249; Function Attrs: nounwind 250declare i32 @llvm.wasm.get.ehselector(token) #0 251declare void @__cxa_rethrow() 252declare ptr @__cxa_begin_catch(ptr) 253declare void @__cxa_end_catch() 254declare i32 @__gxx_wasm_personality_v0(...) 255 256attributes #0 = { nounwind } 257