1 // RUN: %clang_cc1 -no-opaque-pointers -triple aarch64-linux-gnu -emit-llvm < %s | FileCheck -check-prefixes=LINUX,COMMON %s
2 // RUN: %clang_cc1 -no-opaque-pointers -triple aarch64-pc-win32 -emit-llvm < %s | FileCheck -check-prefixes=WIN64,COMMON %s
12 void __attribute__((ms_abi
)) f1(void);
15 // LINUX-LABEL: define{{.*}} void @f3()
16 // WIN64-LABEL: define dso_local void @f3()
18 // LINUX: call win64cc void @f1()
19 // WIN64: call void @f1()
21 // COMMON: call void @f2()
23 // LINUX: declare win64cc void @f1()
24 // LINUX: declare void @f2()
25 // WIN64: declare dso_local void @f1()
26 // WIN64: declare dso_local void @f2()
29 void __attribute__((ms_abi
)) f4(int a
, ...) {
30 // LINUX-LABEL: define{{.*}} win64cc void @f4
31 // WIN64-LABEL: define dso_local void @f4
32 __builtin_ms_va_list ap
;
33 __builtin_ms_va_start(ap
, a
);
34 // COMMON: %[[AP:.*]] = alloca i8*
35 // COMMON: call void @llvm.va_start
36 int b
= __builtin_va_arg(ap
, int);
37 // COMMON: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
38 // COMMON-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
39 // COMMON-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
40 // COMMON-NEXT: bitcast i8* %[[AP_CUR]] to i32*
41 __builtin_ms_va_list ap2
;
42 __builtin_ms_va_copy(ap2
, ap
);
43 // COMMON: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
44 // COMMON-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
45 __builtin_ms_va_end(ap
);
46 // COMMON: call void @llvm.va_end
49 void __attribute__((ms_abi
)) f4_2(int a
, ...) {
50 // LINUX-LABEL: define{{.*}} win64cc void @f4_2
51 // WIN64-LABEL: define dso_local void @f4_2
52 __builtin_ms_va_list ap
;
53 __builtin_ms_va_start(ap
, a
);
54 // COMMON: %[[AP:.*]] = alloca i8*
55 // COMMON: call void @llvm.va_start
56 struct small_odd s1
= __builtin_va_arg(ap
, struct small_odd
);
57 // COMMON: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
58 // COMMON-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
59 // COMMON-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
60 // COMMON-NEXT: bitcast i8* %[[AP_CUR]] to %struct.small_odd*
61 struct larger s2
= __builtin_va_arg(ap
, struct larger
);
62 // COMMON: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
63 // COMMON-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
64 // COMMON-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
65 // COMMON-NEXT: bitcast i8* %[[AP_CUR2]] to %struct.larger**
66 __builtin_ms_va_end(ap
);
69 // Let's verify that normal va_lists work right on Win64, too.
71 // WIN64-LABEL: define dso_local void @f5
73 __builtin_va_start(ap
, a
);
74 // WIN64: %[[AP:.*]] = alloca i8*
75 // WIN64: call void @llvm.va_start
76 int b
= __builtin_va_arg(ap
, int);
77 // WIN64: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
78 // WIN64-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
79 // WIN64-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
80 // WIN64-NEXT: bitcast i8* %[[AP_CUR]] to i32*
81 __builtin_va_list ap2
;
82 __builtin_va_copy(ap2
, ap
);
83 // WIN64: call void @llvm.va_copy
85 // WIN64: call void @llvm.va_end
92 __attribute__((ms_abi
)) void msabi_hfa(struct HFA a
);
93 __attribute__((ms_abi
)) void msabi_hfa_vararg(struct HFA a
, int b
, ...);
95 void call_msabi_hfa(void) {
96 // COMMON-LABEL: define{{.*}} void @call_msabi_hfa()
97 // WIN64: call void @msabi_hfa([3 x float] {{.*}})
98 // LINUX: call win64cc void @msabi_hfa([3 x float] {{.*}})
99 msabi_hfa((struct HFA
){1.0f
, 2.0f
, 3.0f
});
102 void call_msabi_hfa_vararg(void) {
103 // COMMON-LABEL: define{{.*}} void @call_msabi_hfa_vararg()
104 // WIN64: call void ([2 x i64], i32, ...) @msabi_hfa_vararg([2 x i64] {{.*}}, i32 noundef 4, [2 x i64] {{.*}})
105 // LINUX: call win64cc void ([2 x i64], i32, ...) @msabi_hfa_vararg([2 x i64] {{.*}}, i32 noundef 4, [2 x i64] {{.*}})
106 msabi_hfa_vararg((struct HFA
){1.0f
, 2.0f
, 3.0f
}, 4,
107 (struct HFA
){5.0f
, 6.0f
, 7.0f
});
110 __attribute__((ms_abi
)) void get_msabi_hfa_vararg(int a
, ...) {
111 // COMMON-LABEL: define{{.*}} void @get_msabi_hfa_vararg
112 __builtin_ms_va_list ap
;
113 __builtin_ms_va_start(ap
, a
);
114 // COMMON: %[[AP:.*]] = alloca i8*
115 // COMMON: call void @llvm.va_start
116 struct HFA b
= __builtin_va_arg(ap
, struct HFA
);
117 // COMMON: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
118 // COMMON-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 16
119 // COMMON-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
120 // COMMON-NEXT: bitcast i8* %[[AP_CUR]] to %struct.HFA*
121 __builtin_ms_va_end(ap
);