1 ## This test reproduces the case where C++ exception handling is used and split
2 ## function optimization is enabled. In particular, function foo is splitted
4 ## foo: contains 2 try blocks, which invokes bar to throw exception
5 ## foo.cold.1: contains 2 corresponding catch blocks (landing pad)
7 ## Similar to split jump table, split landing pad target to different fragment.
8 ## This test is written to ensure BOLT safely handle these targets, e.g., by
9 ## marking them as non-simple.
11 ## Steps to write this test:
12 ## - Create a copy of Inputs/src/unreachable.cpp
13 ## - Simplify bar(), focus on throw an exception
14 ## - Create the second switch case in foo() to have multiple landing pads
15 ## - Compile with clang++ to .s
16 ## - Move landing pad code from foo to foo.cold.1
17 ## - Ensure that all landing pads can be reached normally
19 ## Additional details:
20 ## .gcc_except_table specify the landing pads for try blocks
21 ## LPStart = 255 (omit), which means LPStart = foo start
22 ## Landing pads .Ltmp2 and .Ltmp5 in call site record are offset to foo start.
25 # REQUIRES: system-linux
26 # RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
27 # RUN: %clang++ %cxxflags %t.o -o %t.exe -Wl,-q
28 # RUN: llvm-bolt -v=3 %t.exe -o %t.out 2>&1 | FileCheck %s
30 # CHECK: BOLT-WARNING: Ignoring foo
31 # CHECK: BOLT-WARNING: Ignoring foo.cold.1
32 # CHECK: BOLT-WARNING: skipped 2 functions due to cold fragments
35 .globl bar # -- Begin function bar
42 .cfi_def_cfa_offset 16
45 .cfi_def_cfa_register %rbp
52 callq __cxa_allocate_exception@PLT
55 movq _ZTIi@GOTPCREL
(%rip
), %rsi
61 callq __cxa_allocate_exception@PLT
64 movq _ZTIDn@GOTPCREL
(%rip
), %rsi
69 .size bar, .Lfunc_end0-bar
72 .globl foo # -- Begin function foo
78 .cfi_personality 155, DW.ref.__gxx_personality_v0
79 .cfi_lsda 27, .Lexception0
82 .cfi_def_cfa_offset 16
85 .cfi_def_cfa_register %rbp
93 .LBB1_1: # %invoke.cont
102 .LBB1_6: # %invoke.cont2
104 .LBB1_10: # %try.cont8
112 .LBB1_12: # %eh.resume
113 .cfi_def_cfa %rbp, 16
115 callq _Unwind_Resume@PLT
117 .size foo, .Lfunc_end1-foo
119 .section .gcc_except_table,"a",@progbits
123 .byte 255 # @LPStart Encoding = omit
124 .byte 155 # @TType Encoding = indirect pcrel sdata4
125 .uleb128 .Lttbase0-.Lttbaseref0
127 .byte 1 # Call site Encoding = uleb128
128 .uleb128 .Lcst_end0-.Lcst_begin0
130 .uleb128 .Ltmp0-.Lfunc_begin0 # >> Call Site 1 <<
131 .uleb128 .Ltmp1-.Ltmp0 # Call between .Ltmp0 and .Ltmp1
132 .uleb128 .Ltmp2-.Lfunc_begin0 # jumps to .Ltmp2
133 .byte 1 # On action: 1
134 .uleb128 .Ltmp1-.Lfunc_begin0 # >> Call Site 2 <<
135 .uleb128 .Ltmp3-.Ltmp1 # Call between .Ltmp1 and .Ltmp3
136 .byte 0 # has no landing pad
137 .byte 0 # On action: cleanup
138 .uleb128 .Ltmp3-.Lfunc_begin0 # >> Call Site 3 <<
139 .uleb128 .Ltmp4-.Ltmp3 # Call between .Ltmp3 and .Ltmp4
140 .uleb128 .Ltmp5-.Lfunc_begin0 # jumps to .Ltmp5
141 .byte 1 # On action: 1
142 .uleb128 .Ltmp4-.Lfunc_begin0 # >> Call Site 4 <<
143 .uleb128 .Lfunc_end1-.Ltmp4 # Call between .Ltmp4 and .Lfunc_end1
144 .byte 0 # has no landing pad
145 .byte 0 # On action: cleanup
147 .byte 1 # >> Action Record 1 <<
149 .byte 0 # No further actions
151 # >> Catch TypeInfos <<
153 .long .L_ZTIi.DW.stub-.Ltmp6
160 .globl foo.cold.1 # -- Begin function foo.cold.1
162 .type foo.cold.1,@function
163 foo.cold.1
: # @foo.cold.1
171 # %bb.3: # %catch.dispatch
178 callq __cxa_begin_catch@PLT
182 callq __cxa_end_catch@PLT
189 # %bb.8: # %catch.dispatch3
196 callq __cxa_begin_catch@PLT
200 callq __cxa_end_catch@PLT
203 .size foo.cold.1, .Lfunc_end3-foo.cold.1
208 .globl main # -- Begin function main
215 .cfi_def_cfa_offset 16
216 .cfi_offset %rbp, -16
218 .cfi_def_cfa_register %rbp
226 # kill: def $eax killed $eax killed $rax
232 .size main, .Lfunc_end2-main
239 .hidden DW.ref.__gxx_personality_v0
240 .weak DW.ref.__gxx_personality_v0
241 .section .data.DW.ref.__gxx_personality_v0,"aGw",@progbits,DW.ref.__gxx_personality_v0,comdat
243 .type DW.ref.__gxx_personality_v0,@object
244 .size DW.ref.__gxx_personality_v0, 8
245 DW.ref.__gxx_personality_v0
:
246 .quad __gxx_personality_v0
247 .section ".note.GNU-stack","",@progbits
250 .addrsig_sym __cxa_allocate_exception
251 .addrsig_sym __cxa_throw
253 .addrsig_sym __gxx_personality_v0
254 .addrsig_sym __cxa_begin_catch
255 .addrsig_sym __cxa_end_catch
256 .addrsig_sym _Unwind_Resume
259 .addrsig_sym foo.cold.1
260 .addrsig_sym __cxa_begin_catch
261 .addrsig_sym __cxa_end_catch