[AAArch64][Windows] Fix the crash when running ninja check-asan

The crash comes from mismatch between load count in epilogue and seh instruction count.
Still because of the pass AArch64LoadStoreOpt. It remove some load in the epilogue but haven't remove the corresponding seh instruction.
This patch don't optimize the load in the epilogue to fix the issue.

Fix: #58516

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D136430
This commit is contained in:
chenglin.bi 2022-10-21 22:11:22 +08:00
parent fcd545863d
commit ec4db1d0dc
2 changed files with 116 additions and 0 deletions

View File

@ -2067,6 +2067,9 @@ bool AArch64LoadStoreOpt::tryToPromoteLoadFromStore(
if (MI.hasOrderedMemoryRef())
return false;
if (needsWinCFI(MI.getMF()) && MI.getFlag(MachineInstr::FrameDestroy))
return false;
// Make sure this is a reg+imm.
// FIXME: It is possible to extend it to handle reg+reg cases.
if (!AArch64InstrInfo::getLdStOffsetOp(MI).isImm())

View File

@ -0,0 +1,113 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=aarch64-pc-windows-msvc %s -o - | FileCheck %s
$osfx = comdat any
declare dso_local i32 @__CxxFrameHandler3(...)
define void @osfx(ptr %this) comdat personality ptr @__CxxFrameHandler3 {
; CHECK-LABEL: osfx:
; CHECK: .Lfunc_begin0:
; CHECK-NEXT: .seh_proc osfx
; CHECK-NEXT: .seh_handler __CxxFrameHandler3, @unwind, @except
; CHECK-NEXT: // %bb.0: // %invoke.cont
; CHECK-NEXT: stp x19, x20, [sp, #-64]! // 16-byte Folded Spill
; CHECK-NEXT: .seh_save_regp_x x19, 64
; CHECK-NEXT: str x21, [sp, #16] // 8-byte Folded Spill
; CHECK-NEXT: .seh_save_reg x21, 16
; CHECK-NEXT: stp x29, x30, [sp, #24] // 16-byte Folded Spill
; CHECK-NEXT: .seh_save_fplr 24
; CHECK-NEXT: add x29, sp, #24
; CHECK-NEXT: .seh_add_fp 24
; CHECK-NEXT: .seh_endprologue
; CHECK-NEXT: sub x9, sp, #32
; CHECK-NEXT: and sp, x9, #0xffffffffffffffe0
; CHECK-NEXT: mov x19, sp
; CHECK-NEXT: mov x1, #-2
; CHECK-NEXT: add x8, x19, #0
; CHECK-NEXT: mov x20, x0
; CHECK-NEXT: lsr x21, x8, #3
; CHECK-NEXT: adrp x8, osfx
; CHECK-NEXT: add x8, x8, :lo12:osfx
; CHECK-NEXT: stur x1, [x29, #24]
; CHECK-NEXT: str x8, [x0]
; CHECK-NEXT: str wzr, [x21]
; CHECK-NEXT: ldr x0, [x0]
; CHECK-NEXT: .Ltmp0:
; CHECK-NEXT: blr x0
; CHECK-NEXT: .Ltmp1:
; CHECK-NEXT: // %bb.1: // %invoke.cont12
; CHECK-NEXT: str wzr, [x20]
; CHECK-NEXT: str wzr, [x21]
; CHECK-NEXT: .LBB0_2: // %try.cont
; CHECK-NEXT: $ehgcr_0_2:
; CHECK-NEXT: .seh_startepilogue
; CHECK-NEXT: sub sp, x29, #24
; CHECK-NEXT: .seh_add_fp 24
; CHECK-NEXT: ldp x29, x30, [sp, #24] // 16-byte Folded Reload
; CHECK-NEXT: .seh_save_fplr 24
; CHECK-NEXT: ldr x21, [sp, #16] // 8-byte Folded Reload
; CHECK-NEXT: .seh_save_reg x21, 16
; CHECK-NEXT: ldp x19, x20, [sp], #64 // 16-byte Folded Reload
; CHECK-NEXT: .seh_save_regp_x x19, 64
; CHECK-NEXT: .seh_endepilogue
; CHECK-NEXT: ret
; CHECK-NEXT: .seh_endfunclet
; CHECK-NEXT: .seh_handlerdata
; CHECK-NEXT: .word ($cppxdata$osfx)@IMGREL
; CHECK-NEXT: .section .text,"xr",discard,osfx
; CHECK-NEXT: .seh_endproc
; CHECK-NEXT: .def "?catch$3@?0?osfx@4HA";
; CHECK-NEXT: .scl 3;
; CHECK-NEXT: .type 32;
; CHECK-NEXT: .endef
; CHECK-NEXT: .p2align 2
; CHECK-NEXT: "?catch$3@?0?osfx@4HA":
; CHECK-NEXT: .seh_proc "?catch$3@?0?osfx@4HA"
; CHECK-NEXT: .seh_handler __CxxFrameHandler3, @unwind, @except
; CHECK-NEXT: .LBB0_3: // %catch
; CHECK-NEXT: stp x19, x20, [sp, #-48]! // 16-byte Folded Spill
; CHECK-NEXT: .seh_save_regp_x x19, 48
; CHECK-NEXT: str x21, [sp, #16] // 8-byte Folded Spill
; CHECK-NEXT: .seh_save_reg x21, 16
; CHECK-NEXT: stp x29, x30, [sp, #24] // 16-byte Folded Spill
; CHECK-NEXT: .seh_save_fplr 24
; CHECK-NEXT: .seh_endprologue
; CHECK-NEXT: adrp x0, .LBB0_2
; CHECK-NEXT: add x0, x0, .LBB0_2
; CHECK-NEXT: .seh_startepilogue
; CHECK-NEXT: ldp x29, x30, [sp, #24] // 16-byte Folded Reload
; CHECK-NEXT: .seh_save_fplr 24
; CHECK-NEXT: ldr x21, [sp, #16] // 8-byte Folded Reload
; CHECK-NEXT: .seh_save_reg x21, 16
; CHECK-NEXT: ldp x19, x20, [sp], #48 // 16-byte Folded Reload
; CHECK-NEXT: .seh_save_regp_x x19, 48
; CHECK-NEXT: .seh_endepilogue
; CHECK-NEXT: ret
invoke.cont:
%MyAlloca2 = alloca [32 x i8], align 32
%0 = ptrtoint ptr %MyAlloca2 to i64
store i64 ptrtoint (ptr @osfx to i64), ptr %this
%1 = lshr exact i64 %0, 3
%2 = inttoptr i64 %1 to ptr
store i32 0, ptr %2
%vbtable = load ptr, ptr %this
%call.i21 = invoke noundef i32 %vbtable(ptr %vbtable)
to label %invoke.cont12 unwind label %catch.dispatch
invoke.cont12: ; preds = %invoke.cont
store i32 0, ptr %this
store i32 0, ptr %2
br label %try.cont
catch.dispatch: ; preds = %invoke.cont
%3 = catchswitch within none [label %catch] unwind to caller
catch: ; preds = %catch.dispatch
%4 = catchpad within %3 [ptr null, i32 64, ptr null]
catchret from %4 to label %try.cont
try.cont: ; preds = %catch, %invoke.cont12
ret void
}