1; RUN: llc -o - %s -mtriple=aarch64-windows | FileCheck %s
2; Check that we allocate the unwind help stack object in a fixed location from fp
3; so that the runtime can find it when handling an exception
4target datalayout = "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128"
5target triple = "aarch64-pc-windows-msvc19.25.28611"
6
7; Check that the store to the unwind help object for func2 is via FP
8; CHECK-LABEL: ?func2@@YAXXZ
9; CHECK: mov x[[#SCRATCH_REG:]], #-2
10; CHECK: stur x[[#SCRATCH_REG:]], [x29, #[[#]]]
11;
12; // struct that requires greater than stack alignment
13; struct alignas(32) A
14; {
15;     // data that would be invalid for unwind help (> 0)
16;     int _x[4]{42, 42, 42, 42};
17;     ~A() {}
18; };
19;
20; // cause us to run the funclet in func2
21; void func3()
22; {
23;     throw 1;
24; }
25;
26; // the funclet that ensures we have the unwind help correct
27; void func2()
28; {
29;     A a;
30;     func3();
31; }
32;
33; // function to ensure we are misaligned in func2
34; void func1()
35; {
36;     func2();
37; }
38;
39; // set things up and ensure alignment for func1
40; void test()
41; {
42;     try {
43;         A a;
44;         func1();
45;     } catch(...) {}
46; }
47
48%struct.A = type { [4 x i32], [16 x i8] }
49declare dso_local %struct.A* @"??0A@@QEAA@XZ"(%struct.A* returned %0)
50declare dso_local void @"??1A@@QEAA@XZ"(%struct.A* %0)
51declare dso_local i32 @__CxxFrameHandler3(...)
52declare dso_local void @"?func3@@YAXXZ"()
53
54; Function Attrs: noinline optnone uwtable
55define dso_local void @"?func2@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
56  %1 = alloca %struct.A, align 32
57  %2 = call %struct.A* @"??0A@@QEAA@XZ"(%struct.A* %1) #3
58  invoke void @"?func3@@YAXXZ"()
59          to label %3 unwind label %4
60
613:                                                ; preds = %0
62  call void @"??1A@@QEAA@XZ"(%struct.A* %1) #3
63  ret void
64
654:                                                ; preds = %0
66  %5 = cleanuppad within none []
67  call void @"??1A@@QEAA@XZ"(%struct.A* %1) #3 [ "funclet"(token %5) ]
68  cleanupret from %5 unwind to caller
69}
70