257 lines · plain
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=322; 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=643; 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=324; 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=645; 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=326; 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=647 8@_ZTIi = external constant ptr9@_ZTIf = external constant ptr10@_ZTId = external constant ptr11 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_table20define void @test0() personality ptr @__gxx_wasm_personality_v0 {21entry:22 invoke void @may_throw()23 to label %try.cont unwind label %catch.dispatch24 25catch.dispatch: ; preds = %entry26 %0 = catchswitch within none [label %catch.start] unwind to caller27 28catch.start: ; preds = %catch.dispatch29 %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.cont35 36try.cont: ; preds = %entry, %catch.start37 ret void38}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 table63; entries with the first landing pad because they end with the same sequence64; (double -> ...). But the third landing table cannot share action table entries65; 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:.*]]=, {{[48]}}70; NOPIC-NEXT: i[[PTR]].const $push[[EXCEPT_TABLE:.*]]=, GCC_except_table171; NOPIC-NEXT: i[[PTR]].store __wasm_lpad_context($pop[[CONTEXT]]), $pop[[EXCEPT_TABLE]]72 73; In case of PIC, we make GCC_except_table symbols a relative on based on74; __memory_base.75; PIC: global.get $push[[CONTEXT:.*]]=, __wasm_lpad_context@GOT76; PIC-NEXT: local.tee $push{{.*}}=, $[[CONTEXT_LOCAL:.*]]=, $pop[[CONTEXT]]77; PIC: global.get $push[[MEMORY_BASE:.*]]=, __memory_base78; PIC-NEXT: i[[PTR]].const $push[[EXCEPT_TABLE_REL:.*]]=, GCC_except_table1@MBREL79; 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 284; CHECK-NEXT: GCC_except_table[[START:[0-9]+]]:85; CHECK-NEXT: .Lexception0:86; CHECK-NEXT: .int8 255 # @LPStart Encoding = omit87; CHECK-NEXT: .int8 0 # @TType Encoding = absptr88; CHECK-NEXT: .uleb128 .Lttbase0-.Lttbaseref089; CHECK-NEXT: .Lttbaseref0:90; CHECK-NEXT: .int8 1 # Call site Encoding = uleb12891; CHECK-NEXT: .uleb128 .Lcst_end0-.Lcst_begin092; CHECK-NEXT: .Lcst_begin0:93; CHECK-NEXT: .int8 0 # >> Call Site 0 <<94; CHECK-NEXT: # On exception at call site 095; CHECK-NEXT: .int8 7 # Action: 496; CHECK-NEXT: .int8 1 # >> Call Site 1 <<97; CHECK-NEXT: # On exception at call site 198; CHECK-NEXT: .int8 3 # Action: 299; CHECK-NEXT: .int8 2 # >> Call Site 2 <<100; CHECK-NEXT: # On exception at call site 2101; CHECK-NEXT: .int8 11 # Action: 6102; CHECK-NEXT: .Lcst_end0:103; CHECK-NEXT: .int8 1 # >> Action Record 1 <<104; CHECK-NEXT: # Catch TypeInfo 1105; CHECK-NEXT: .int8 0 # No further actions106; CHECK-NEXT: .int8 2 # >> Action Record 2 <<107; CHECK-NEXT: # Catch TypeInfo 2108; CHECK-NEXT: .int8 125 # Continue to action 1109; CHECK-NEXT: .int8 3 # >> Action Record 3 <<110; CHECK-NEXT: # Catch TypeInfo 3111; CHECK-NEXT: .int8 125 # Continue to action 2112; CHECK-NEXT: .int8 4 # >> Action Record 4 <<113; CHECK-NEXT: # Catch TypeInfo 4114; CHECK-NEXT: .int8 125 # Continue to action 3115; CHECK-NEXT: .int8 3 # >> Action Record 5 <<116; CHECK-NEXT: # Catch TypeInfo 3117; CHECK-NEXT: .int8 0 # No further actions118; CHECK-NEXT: .int8 4 # >> Action Record 6 <<119; CHECK-NEXT: # Catch TypeInfo 4120; CHECK-NEXT: .int8 125 # Continue to action 5121; CHECK-NEXT: .p2align 2122; CHECK-NEXT: # >> Catch TypeInfos <<123; CHECK-NEXT: .int[[PTR]] _ZTIi # TypeInfo 4124; CHECK-NEXT: .int[[PTR]] _ZTIf # TypeInfo 3125; CHECK-NEXT: .int[[PTR]] _ZTId # TypeInfo 2126; CHECK-NEXT: .int[[PTR]] 0 # TypeInfo 1127; CHECK-NEXT: .Lttbase0:128; CHECK-NEXT: .p2align 2129; 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.dispatch135 136catch.dispatch: ; preds = %entry137 %0 = catchswitch within none [label %catch.start] unwind to caller138 139catch.start: ; preds = %catch.dispatch140 %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, %4145 br i1 %matches, label %catch10, label %catch.fallthrough146 147catch10: ; preds = %catch.start148 %5 = call ptr @__cxa_begin_catch(ptr %2) [ "funclet"(token %1) ]149 %6 = load i32, ptr %5, align 4150 call void @__cxa_end_catch() [ "funclet"(token %1) ]151 catchret from %1 to label %try.cont152 153try.cont: ; preds = %entry, %catch, %catch4, %catch7, %catch10154 invoke void @may_throw()155 to label %try.cont23 unwind label %catch.dispatch14156 157catch.dispatch14: ; preds = %try.cont158 %7 = catchswitch within none [label %catch.start15] unwind to caller159 160catch.start15: ; preds = %catch.dispatch14161 %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, %11166 %12 = call ptr @__cxa_begin_catch(ptr %9) [ "funclet"(token %8) ]167 br i1 %matches16, label %catch20, label %catch17168 169catch20: ; preds = %catch.start15170 %13 = load double, ptr %12, align 8171 call void @__cxa_end_catch() [ "funclet"(token %8) ]172 catchret from %8 to label %try.cont23173 174try.cont23: ; preds = %try.cont, %catch17, %catch20175 invoke void @may_throw()176 to label %try.cont36 unwind label %catch.dispatch25177 178catch.dispatch25: ; preds = %try.cont23179 %14 = catchswitch within none [label %catch.start26] unwind to caller180 181catch.start26: ; preds = %catch.dispatch25182 %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, %18187 br i1 %matches27, label %catch33, label %catch.fallthrough28188 189catch33: ; preds = %catch.start26190 %19 = call ptr @__cxa_begin_catch(ptr %16) [ "funclet"(token %15) ]191 %20 = load i32, ptr %19, align 4192 call void @__cxa_end_catch() [ "funclet"(token %15) ]193 catchret from %15 to label %try.cont36194 195catch.fallthrough28: ; preds = %catch.start26196 %21 = call i32 @llvm.eh.typeid.for(ptr @_ZTIf)197 %matches29 = icmp eq i32 %17, %21198 br i1 %matches29, label %catch30, label %rethrow199 200catch30: ; preds = %catch.fallthrough28201 %22 = call ptr @__cxa_begin_catch(ptr %16) [ "funclet"(token %15) ]202 %23 = load float, ptr %22, align 4203 call void @__cxa_end_catch() [ "funclet"(token %15) ]204 catchret from %15 to label %try.cont36205 206rethrow: ; preds = %catch.fallthrough28207 call void @__cxa_rethrow() [ "funclet"(token %15) ]208 unreachable209 210try.cont36: ; preds = %try.cont23, %catch30, %catch33211 ret void212 213catch17: ; preds = %catch.start15214 call void @__cxa_end_catch() [ "funclet"(token %8) ]215 catchret from %8 to label %try.cont23216 217catch.fallthrough: ; preds = %catch.start218 %24 = call i32 @llvm.eh.typeid.for(ptr @_ZTIf)219 %matches1 = icmp eq i32 %3, %24220 br i1 %matches1, label %catch7, label %catch.fallthrough2221 222catch7: ; preds = %catch.fallthrough223 %25 = call ptr @__cxa_begin_catch(ptr %2) [ "funclet"(token %1) ]224 %26 = load float, ptr %25, align 4225 call void @__cxa_end_catch() [ "funclet"(token %1) ]226 catchret from %1 to label %try.cont227 228catch.fallthrough2: ; preds = %catch.fallthrough229 %27 = call i32 @llvm.eh.typeid.for(ptr @_ZTId)230 %matches3 = icmp eq i32 %3, %27231 %28 = call ptr @__cxa_begin_catch(ptr %2) [ "funclet"(token %1) ]232 br i1 %matches3, label %catch4, label %catch233 234catch4: ; preds = %catch.fallthrough2235 %29 = load double, ptr %28, align 8236 call void @__cxa_end_catch() [ "funclet"(token %1) ]237 catchret from %1 to label %try.cont238 239catch: ; preds = %catch.fallthrough2240 call void @__cxa_end_catch() [ "funclet"(token %1) ]241 catchret from %1 to label %try.cont242}243 244declare void @may_throw()245; Function Attrs: nounwind246declare i32 @llvm.eh.typeid.for(ptr) #0247; Function Attrs: nounwind248declare ptr @llvm.wasm.get.exception(token) #0249; Function Attrs: nounwind250declare i32 @llvm.wasm.get.ehselector(token) #0251declare 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