160 lines · c
1// RUN: %clang_cc1 -fms-extensions -w -triple i386-pc-win32 -emit-llvm -o - %s | FileCheck %s2 3// CHECK-LABEL: define dso_local i64 @f1_1()4// CHECK-LABEL: define dso_local void @f1_2(i32 %a0.0, i32 %a0.1)5struct s1 {6 int a;7 int b;8};9struct s1 f1_1(void) { while (1) {} }10void f1_2(struct s1 a0) {}11 12// CHECK-LABEL: define dso_local i32 @f2_1()13struct s2 {14 short a;15 short b;16};17struct s2 f2_1(void) { while (1) {} }18 19// CHECK-LABEL: define dso_local i16 @f3_1()20struct s3 {21 char a;22 char b;23};24struct s3 f3_1(void) { while (1) {} }25 26// CHECK-LABEL: define dso_local i8 @f4_1()27struct s4 {28 char a:4;29 char b:4;30};31struct s4 f4_1(void) { while (1) {} }32 33// CHECK-LABEL: define dso_local i64 @f5_1()34// CHECK-LABEL: define dso_local void @f5_2(double %a0.0)35struct s5 {36 double a;37};38struct s5 f5_1(void) { while (1) {} }39void f5_2(struct s5 a0) {}40 41// CHECK-LABEL: define dso_local i32 @f6_1()42// CHECK-LABEL: define dso_local void @f6_2(float %a0.0)43struct s6 {44 float a;45};46struct s6 f6_1(void) { while (1) {} }47void f6_2(struct s6 a0) {}48 49 50// MSVC passes up to three vectors in registers, and the rest indirectly. We51// (arbitrarily) pass oversized vectors indirectly, since that is the safest way52// to do it.53typedef float __m128 __attribute__((__vector_size__(16), __aligned__(16)));54typedef float __m256 __attribute__((__vector_size__(32), __aligned__(32)));55typedef float __m512 __attribute__((__vector_size__(64), __aligned__(64)));56typedef float __m1024 __attribute__((__vector_size__(128), __aligned__(128)));57 58__m128 gv128;59__m256 gv256;60__m512 gv512;61__m1024 gv1024;62 63void receive_vec_128(__m128 x, __m128 y, __m128 z, __m128 w, __m128 q) {64 gv128 = x + y + z + w + q;65}66void receive_vec_256(__m256 x, __m256 y, __m256 z, __m256 w, __m256 q) {67 gv256 = x + y + z + w + q;68}69void receive_vec_512(__m512 x, __m512 y, __m512 z, __m512 w, __m512 q) {70 gv512 = x + y + z + w + q;71}72void receive_vec_1024(__m1024 x, __m1024 y, __m1024 z, __m1024 w, __m1024 q) {73 gv1024 = x + y + z + w + q;74}75// CHECK-LABEL: define dso_local void @receive_vec_128(<4 x float> inreg noundef %x, <4 x float> inreg noundef %y, <4 x float> inreg noundef %z, ptr dead_on_return noundef %0, ptr dead_on_return noundef %1)76// CHECK-LABEL: define dso_local void @receive_vec_256(<8 x float> inreg noundef %x, <8 x float> inreg noundef %y, <8 x float> inreg noundef %z, ptr dead_on_return noundef %0, ptr dead_on_return noundef %1)77// CHECK-LABEL: define dso_local void @receive_vec_512(<16 x float> inreg noundef %x, <16 x float> inreg noundef %y, <16 x float> inreg noundef %z, ptr dead_on_return noundef %0, ptr dead_on_return noundef %1)78// CHECK-LABEL: define dso_local void @receive_vec_1024(ptr dead_on_return noundef %0, ptr dead_on_return noundef %1, ptr dead_on_return noundef %2, ptr dead_on_return noundef %3, ptr dead_on_return noundef %4)79 80void pass_vec_128(void) {81 __m128 z = {0};82 receive_vec_128(z, z, z, z, z);83}84 85// CHECK-LABEL: define dso_local void @pass_vec_128()86// CHECK: call void @receive_vec_128(<4 x float> inreg noundef %{{[^,)]*}}, <4 x float> inreg noundef %{{[^,)]*}}, <4 x float> inreg noundef %{{[^,)]*}}, ptr dead_on_return noundef %{{[^,)]*}}, ptr dead_on_return noundef %{{[^,)]*}})87 88 89void __fastcall fastcall_indirect_vec(__m128 x, __m128 y, __m128 z, __m128 w, int edx, __m128 q) {90 gv128 = x + y + z + w + q;91}92// CHECK-LABEL: define dso_local x86_fastcallcc void @"\01@fastcall_indirect_vec@84"(<4 x float> inreg noundef %x, <4 x float> inreg noundef %y, <4 x float> inreg noundef %z, ptr dead_on_return inreg noundef %0, i32 inreg noundef %edx, ptr dead_on_return noundef %1)93 94struct __declspec(align(1)) Align1 { unsigned long long x; };95struct __declspec(align(4)) Align4 { unsigned long long x; };96struct __declspec(align(8)) Align8 { unsigned long long x; };97void receive_align1(struct Align1 o);98void receive_align4(struct Align4 o);99void receive_align8(struct Align8 o);100void pass_underaligned_record() {101 struct Align1 a1;102 receive_align1(a1);103 struct Align4 a4;104 receive_align4(a4);105 struct Align8 a8;106 receive_align8(a8);107}108// CHECK-LABEL: define dso_local void @pass_underaligned_record()109// CHECK: call void @receive_align1(i64 {{[^,)]*}})110// CHECK: call void @receive_align4(i64 {{[^,)]*}})111// CHECK: call void @receive_align8(ptr {{[^,)]*}})112 113struct FieldAlign1 { unsigned long long __declspec(align(1)) x; };114struct FieldAlign4 { unsigned long long __declspec(align(4)) x; };115struct FieldAlign8 { unsigned long long __declspec(align(8)) x; };116void receive_falign1(struct FieldAlign1 o);117void receive_falign4(struct FieldAlign4 o);118void receive_falign8(struct FieldAlign8 o);119void pass_underaligned_record_field() {120 struct FieldAlign1 a1;121 receive_falign1(a1);122 struct FieldAlign4 a4;123 receive_falign4(a4);124 struct FieldAlign8 a8;125 receive_falign8(a8);126}127// CHECK-LABEL: define dso_local void @pass_underaligned_record_field()128// CHECK: call void @receive_falign1(i64 {{[^,)]*}})129// CHECK: call void @receive_falign4(i64 {{[^,)]*}})130// CHECK: call void @receive_falign8(ptr {{[^,)]*}})131 132struct __declspec(align(8)) BigAligned {133 int big[5];134};135 136void receive_aligned_variadic(int f, ...);137void pass_aligned_variadic() {138 struct Align8 a8 = {42};139 struct FieldAlign8 f8 = {42};140 struct BigAligned big;141 receive_aligned_variadic(1, a8, f8, big);142}143// MSVC doesn't pass aligned objects to variadic functions indirectly.144// CHECK-LABEL: define dso_local void @pass_aligned_variadic()145// CHECK: call void (i32, ...) @receive_aligned_variadic(i32 noundef 1, i64 %{{[^,]*}}, i64 %{{[^,]*}}, ptr noundef byval(%struct.BigAligned) align 4 %{{[^)]*}})146 147 148void receive_fixed_align_variadic(struct BigAligned big, ...);149void pass_fixed_align_variadic() {150 struct BigAligned big;151 receive_fixed_align_variadic(big, 42);152}153// MSVC emits error C2719 and C3916 when receiving and passing arguments with154// required alignment greater than 4 to the fixed part of a variadic function155// prototype, but it's actually easier to just implement this functionality156// correctly in Clang than it is to be bug for bug compatible, so we pass such157// arguments indirectly.158// CHECK-LABEL: define dso_local void @pass_fixed_align_variadic()159// CHECK: call void (ptr, ...) @receive_fixed_align_variadic(ptr dead_on_return noundef %{{[^)]*}}, i32 noundef 42)160