<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61837>61837</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect exception handling tables with AArch64 outliner
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AArch64,
c++,
miscompilation
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ostannard
</td>
</tr>
</table>
<pre>
When using the machine outliner (`-moutline`) for AArch64, we can generate incorrect C++ exception handling tables for this code:
```
extern "C" __attribute__((nothrow)) void __aeabi_assert(const char *,
const char *, int);
#define assert(e) ((e) ? (void)0 : __aeabi_assert(#e, __FILE__, __LINE__))
#include <arm_neon.h>
struct S11 {
uint16x4_t M0;
};
void F5(S11 P0) {
assert(vget_lane_u16(P0.M0, 0) == 51593);
throw 42;
}
// Dead code
void F4() {
S11 P0 = (S11){vld1_u16(((const uint16_t[4]){51593, 12396, 49417, 16216}))};
F5(P0);
}
int main() {
try {
S11 P0 = (S11){vld1_u16(((const uint16_t[4]){51593, 12396, 49417, 16216}))};
F5(P0);
} catch (int exc) {
}
return 0;
}
```
With `-mno-outline`, we generate two call site records for `main`, one of which covers the call to `F5`, and catches the `int` type exception:
```
$ /work/llvm/build/bin/clang --target=aarch64-none-eabi -march=armv8-a -c test.cpp -o - -S -Oz -mno-outline
...
main: // @main
.Lfunc_begin0:
.cfi_startproc
.cfi_personality 156, DW.ref.__gxx_personality_v0
.cfi_lsda 28, .Lexception0
// %bb.0: // %entry
stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
.cfi_def_cfa_offset 16
mov x29, sp
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
adrp x8, _PromotedConst
ldr d0, [x8, :lo12:_PromotedConst]
.Ltmp0:
bl _Z2F53S11
.Ltmp1:
// %bb.1: // %try.cont.unreachable
.LBB2_2: // %lpad
.Ltmp2:
cmp w1, #1
b.ne .LBB2_4
// %bb.3: // %catch
bl __cxa_begin_catch
bl __cxa_end_catch
mov w0, wzr
ldp x29, x30, [sp], #16 // 16-byte Folded Reload
ret
.LBB2_4: // %eh.resume
bl _Unwind_Resume
.Lfunc_end2:
.size main, .Lfunc_end2-main
.cfi_endproc
.section .gcc_except_table,"a",@progbits
.p2align 2, 0x0
GCC_except_table2:
.Lexception0:
.byte 255 // @LPStart Encoding = omit
.byte 156 // @TType Encoding = indirect pcrel sdata8
.uleb128 .Lttbase0-.Lttbaseref0
.Lttbaseref0:
.byte 1 // Call site Encoding = uleb128
.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
.uleb128 .Ltmp0-.Lfunc_begin0 // >> Call Site 1 <<
.uleb128 .Ltmp1-.Ltmp0 // Call between .Ltmp0 and .Ltmp1
.uleb128 .Ltmp2-.Lfunc_begin0 // jumps to .Ltmp2
.byte 3 // On action: 2
.uleb128 .Ltmp1-.Lfunc_begin0 // >> Call Site 2 <<
.uleb128 .Lfunc_end2-.Ltmp1 // Call between .Ltmp1 and .Lfunc_end2
.byte 0 // has no landing pad
.byte 0 // On action: cleanup
.Lcst_end0:
.byte 0 // >> Action Record 1 <<
// Cleanup
.byte 0 // No further actions
.byte 1 // >> Action Record 2 <<
// Catch TypeInfo 1
.byte 125 // Continue to action 1
.p2align 2, 0x0
// >> Catch TypeInfos <<
.Ltmp3: // TypeInfo 1
.xword .L_ZTIi.DW.stub-.Ltmp3
.Lttbase0:
.p2align 2, 0x0
// -- End function
...
```
However, with `-moutline` (on by default at -Oz), we only generate one call site record, covering the whole function, and it does not catch the exception:
```
main: // @main
.Lfunc_begin0:
.cfi_startproc
.cfi_personality 156, DW.ref.__gxx_personality_v0
.cfi_lsda 28, .Lexception0
// %bb.0: // %entry
stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
.cfi_def_cfa_offset 16
mov x29, sp
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
bl OUTLINED_FUNCTION_0
.Ltmp1:
// %bb.1: // %try.cont.unreachable
.LBB2_2: // %lpad
.Ltmp2:
cmp w1, #1
b.ne .LBB2_4
// %bb.3: // %catch
bl __cxa_begin_catch
bl __cxa_end_catch
mov w0, wzr
ldp x29, x30, [sp], #16 // 16-byte Folded Reload
ret
.LBB2_4: // %eh.resume
bl _Unwind_Resume
.Lfunc_end2:
.size main, .Lfunc_end2-main
.cfi_endproc
.section .gcc_except_table,"a",@progbits
.p2align 2, 0x0
GCC_except_table2:
.Lexception0:
.byte 255 // @LPStart Encoding = omit
.byte 156 // @TType Encoding = indirect pcrel sdata8
.uleb128 .Lttbase0-.Lttbaseref0
.Lttbaseref0:
.byte 1 // Call site Encoding = uleb128
.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
.uleb128 .Lfunc_begin0-.Lfunc_begin0 // >> Call Site 1 <<
.uleb128 .Lfunc_end2-.Lfunc_begin0 // Call between .Lfunc_begin0 and .Lfunc_end2
.byte 0 // has no landing pad
.byte 0 // On action: cleanup
.Lcst_end0:
.byte 0 // >> Action Record 1 <<
// Cleanup
.byte 0 // No further actions
.byte 1 // >> Action Record 2 <<
// Catch TypeInfo 1
.byte 125 // Continue to action 1
.p2align 2, 0x0
// >> Catch TypeInfos <<
.Ltmp3: // TypeInfo 1
.xword .L_ZTIi.DW.stub-.Ltmp3
.Lttbase0:
.p2align 2, 0x0
// -- End function
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWd1u47gOfhr1hrBhy7GTXOSiTZpzCnRnBvODAfbGkGUm9q4tGbLcpPP0B5KcxPmbtrOzwNnFBEWiOBT5kSI_kzVr23ItEGckviPx4oZ1upBqJlvNhGAqv8lk_jz7WqCAri3FGnSBUDNelAJBdroqBSogdEKSwKv7CyQJCJ3CSiq4vVW8SEaEzmGDwJmANQpUTCOUgkulkGuYE3pH6B3glmOjSymgYCKvrDmWVdhaVbooW-AyRxLdkmBBgt17EvR_9ituNSoBhNI5oRTSlGmtyq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