xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/x86_64-arguments.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // Basic base class test.
4f4a2713aSLionel Sambuc struct f0_s0 { unsigned a; };
5f4a2713aSLionel Sambuc struct f0_s1 : public f0_s0 { void *b; };
6f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z2f05f0_s1(i32 %a0.coerce0, i8* %a0.coerce1)
f0(f0_s1 a0)7f4a2713aSLionel Sambuc void f0(f0_s1 a0) { }
8f4a2713aSLionel Sambuc 
9f4a2713aSLionel Sambuc // Check with two eight-bytes in base class.
10f4a2713aSLionel Sambuc struct f1_s0 { unsigned a; unsigned b; float c; };
11f4a2713aSLionel Sambuc struct f1_s1 : public f1_s0 { float d;};
12f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z2f15f1_s1(i64 %a0.coerce0, <2 x float> %a0.coerce1)
f1(f1_s1 a0)13f4a2713aSLionel Sambuc void f1(f1_s1 a0) { }
14f4a2713aSLionel Sambuc 
15f4a2713aSLionel Sambuc // Check with two eight-bytes in base class and merge.
16f4a2713aSLionel Sambuc struct f2_s0 { unsigned a; unsigned b; float c; };
17f4a2713aSLionel Sambuc struct f2_s1 : public f2_s0 { char d;};
18f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z2f25f2_s1(i64 %a0.coerce0, i64 %a0.coerce1)
f2(f2_s1 a0)19f4a2713aSLionel Sambuc void f2(f2_s1 a0) { }
20f4a2713aSLionel Sambuc 
21f4a2713aSLionel Sambuc // PR5831
22f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z2f34s3_1(i64 %x.coerce)
23f4a2713aSLionel Sambuc struct s3_0 {};
24f4a2713aSLionel Sambuc struct s3_1 { struct s3_0 a; long b; };
f3(struct s3_1 x)25f4a2713aSLionel Sambuc void f3(struct s3_1 x) {}
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc // CHECK-LABEL: define i64 @_Z4f4_0M2s4i(i64 %a)
28f4a2713aSLionel Sambuc // CHECK: define {{.*}} @_Z4f4_1M2s4FivE(i64 %a.coerce0, i64 %a.coerce1)
29f4a2713aSLionel Sambuc struct s4 {};
30f4a2713aSLionel Sambuc typedef int s4::* s4_mdp;
31f4a2713aSLionel Sambuc typedef int (s4::*s4_mfp)();
f4_0(s4_mdp a)32f4a2713aSLionel Sambuc s4_mdp f4_0(s4_mdp a) { return a; }
f4_1(s4_mfp a)33f4a2713aSLionel Sambuc s4_mfp f4_1(s4_mfp a) { return a; }
34f4a2713aSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc // A struct with <= one eightbyte before a member data pointer should still
36*0a6a1f1dSLionel Sambuc // be allowed in registers.
37*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @{{.*}}f_struct_with_mdp{{.*}}(i8* %a.coerce0, i64 %a.coerce1)
38*0a6a1f1dSLionel Sambuc struct struct_with_mdp { char *a; s4_mdp b; };
f_struct_with_mdp(struct_with_mdp a)39*0a6a1f1dSLionel Sambuc void f_struct_with_mdp(struct_with_mdp a) { (void)a; }
40*0a6a1f1dSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc // A struct with anything before a member function will be too big and
42*0a6a1f1dSLionel Sambuc // goes in memory.
43*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_0{{.*}}(%struct{{.*}} byval align 8 %a)
44*0a6a1f1dSLionel Sambuc struct struct_with_mfp_0 { char a; s4_mfp b; };
f_struct_with_mfp_0(struct_with_mfp_0 a)45*0a6a1f1dSLionel Sambuc void f_struct_with_mfp_0(struct_with_mfp_0 a) { (void)a; }
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_1{{.*}}(%struct{{.*}} byval align 8 %a)
48*0a6a1f1dSLionel Sambuc struct struct_with_mfp_1 { void *a; s4_mfp b; };
f_struct_with_mfp_1(struct_with_mfp_1 a)49*0a6a1f1dSLionel Sambuc void f_struct_with_mfp_1(struct_with_mfp_1 a) { (void)a; }
50f4a2713aSLionel Sambuc 
51f4a2713aSLionel Sambuc namespace PR7523 {
52f4a2713aSLionel Sambuc struct StringRef {
53f4a2713aSLionel Sambuc   char *a;
54f4a2713aSLionel Sambuc };
55f4a2713aSLionel Sambuc 
56f4a2713aSLionel Sambuc void AddKeyword(StringRef, int x);
57f4a2713aSLionel Sambuc 
foo()58f4a2713aSLionel Sambuc void foo() {
59f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN6PR75233fooEv()
60f4a2713aSLionel Sambuc   // CHECK: call void @_ZN6PR752310AddKeywordENS_9StringRefEi(i8* {{.*}}, i32 4)
61f4a2713aSLionel Sambuc   AddKeyword(StringRef(), 4);
62f4a2713aSLionel Sambuc }
63f4a2713aSLionel Sambuc }
64f4a2713aSLionel Sambuc 
65f4a2713aSLionel Sambuc namespace PR7742 { // Also rdar://8250764
66f4a2713aSLionel Sambuc   struct s2 {
67f4a2713aSLionel Sambuc     float a[2];
68f4a2713aSLionel Sambuc   };
69f4a2713aSLionel Sambuc 
70f4a2713aSLionel Sambuc   struct c2 : public s2 {};
71f4a2713aSLionel Sambuc 
72f4a2713aSLionel Sambuc   // CHECK-LABEL: define <2 x float> @_ZN6PR77423fooEPNS_2c2E(%"struct.PR7742::c2"* %P)
foo(c2 * P)73f4a2713aSLionel Sambuc   c2 foo(c2 *P) {
74f4a2713aSLionel Sambuc     return c2();
75f4a2713aSLionel Sambuc   }
76f4a2713aSLionel Sambuc 
77f4a2713aSLionel Sambuc }
78f4a2713aSLionel Sambuc 
79f4a2713aSLionel Sambuc namespace PR5179 {
80f4a2713aSLionel Sambuc   struct B {};
81f4a2713aSLionel Sambuc 
82f4a2713aSLionel Sambuc   struct B1 : B {
83f4a2713aSLionel Sambuc     int* pa;
84f4a2713aSLionel Sambuc   };
85f4a2713aSLionel Sambuc 
86f4a2713aSLionel Sambuc   struct B2 : B {
87f4a2713aSLionel Sambuc     B1 b1;
88f4a2713aSLionel Sambuc   };
89f4a2713aSLionel Sambuc 
90f4a2713aSLionel Sambuc   // CHECK-LABEL: define i8* @_ZN6PR51793barENS_2B2E(i32* %b2.coerce)
bar(B2 b2)91f4a2713aSLionel Sambuc   const void *bar(B2 b2) {
92f4a2713aSLionel Sambuc     return b2.b1.pa;
93f4a2713aSLionel Sambuc   }
94f4a2713aSLionel Sambuc }
95f4a2713aSLionel Sambuc 
96f4a2713aSLionel Sambuc namespace test5 {
97f4a2713aSLionel Sambuc   struct Xbase { };
98f4a2713aSLionel Sambuc   struct Empty { };
99f4a2713aSLionel Sambuc   struct Y;
100f4a2713aSLionel Sambuc   struct X : public Xbase {
101f4a2713aSLionel Sambuc     Empty empty;
102f4a2713aSLionel Sambuc     Y f();
103f4a2713aSLionel Sambuc   };
104f4a2713aSLionel Sambuc   struct Y : public X {
105f4a2713aSLionel Sambuc     Empty empty;
106f4a2713aSLionel Sambuc   };
107f4a2713aSLionel Sambuc   X getX();
108f4a2713aSLionel Sambuc   int takeY(const Y&, int y);
g()109f4a2713aSLionel Sambuc   void g() {
110f4a2713aSLionel Sambuc     // rdar://8340348 - The temporary for the X object needs to have a defined
111f4a2713aSLionel Sambuc     // address when passed into X::f as 'this'.
112f4a2713aSLionel Sambuc     takeY(getX().f(), 42);
113f4a2713aSLionel Sambuc   }
114f4a2713aSLionel Sambuc   // CHECK: void @_ZN5test51gEv()
115f4a2713aSLionel Sambuc   // CHECK: alloca %"struct.test5::Y"
116f4a2713aSLionel Sambuc   // CHECK: alloca %"struct.test5::X"
117f4a2713aSLionel Sambuc   // CHECK: alloca %"struct.test5::Y"
118f4a2713aSLionel Sambuc }
119f4a2713aSLionel Sambuc 
120f4a2713aSLionel Sambuc 
121f4a2713aSLionel Sambuc // rdar://8360877
122f4a2713aSLionel Sambuc namespace test6 {
123f4a2713aSLionel Sambuc   struct outer {
124f4a2713aSLionel Sambuc     int x;
125f4a2713aSLionel Sambuc     struct epsilon_matcher {} e;
126f4a2713aSLionel Sambuc     int f;
127f4a2713aSLionel Sambuc   };
128f4a2713aSLionel Sambuc 
test(outer x)129f4a2713aSLionel Sambuc   int test(outer x) {
130f4a2713aSLionel Sambuc     return x.x + x.f;
131f4a2713aSLionel Sambuc   }
132f4a2713aSLionel Sambuc   // CHECK-LABEL: define i32 @_ZN5test64testENS_5outerE(i64 %x.coerce0, i32 %x.coerce1)
133f4a2713aSLionel Sambuc }
134f4a2713aSLionel Sambuc 
135f4a2713aSLionel Sambuc namespace test7 {
136f4a2713aSLionel Sambuc   struct StringRef {char* ptr; long len; };
137f4a2713aSLionel Sambuc   class A { public: ~A(); };
x(A,A,long,long,StringRef)138f4a2713aSLionel Sambuc   A x(A, A, long, long, StringRef) { return A(); }
139f4a2713aSLionel Sambuc   // Check that the StringRef is passed byval instead of expanded
140f4a2713aSLionel Sambuc   // (which would split it between registers and memory).
141f4a2713aSLionel Sambuc   // rdar://problem/9686430
142f4a2713aSLionel Sambuc   // CHECK: define void @_ZN5test71xENS_1AES0_llNS_9StringRefE({{.*}} byval align 8)
143f4a2713aSLionel Sambuc 
144f4a2713aSLionel Sambuc   // And a couple extra related tests:
y(A,long double,long,long,StringRef)145f4a2713aSLionel Sambuc   A y(A, long double, long, long, StringRef) { return A(); }
146f4a2713aSLionel Sambuc   // CHECK: define void @_ZN5test71yENS_1AEellNS_9StringRefE({{.*}} i8*
147f4a2713aSLionel Sambuc   struct StringDouble {char * ptr; double d;};
z(A,A,A,A,A,StringDouble)148f4a2713aSLionel Sambuc   A z(A, A, A, A, A, StringDouble) { return A(); }
zz(A,A,A,A,StringDouble)149f4a2713aSLionel Sambuc   A zz(A, A, A, A, StringDouble) { return A(); }
150f4a2713aSLionel Sambuc   // CHECK: define void @_ZN5test71zENS_1AES0_S0_S0_S0_NS_12StringDoubleE({{.*}} byval align 8)
151f4a2713aSLionel Sambuc   // CHECK: define void @_ZN5test72zzENS_1AES0_S0_S0_NS_12StringDoubleE({{.*}} i8*
152f4a2713aSLionel Sambuc }
153f4a2713aSLionel Sambuc 
154f4a2713aSLionel Sambuc namespace test8 {
155f4a2713aSLionel Sambuc   // CHECK: declare void @_ZN5test83fooENS_1BE(%"class.test8::B"* byval align 8)
156f4a2713aSLionel Sambuc   class A {
157f4a2713aSLionel Sambuc    char big[17];
158f4a2713aSLionel Sambuc   };
159f4a2713aSLionel Sambuc 
160f4a2713aSLionel Sambuc   class B : public A {};
161f4a2713aSLionel Sambuc 
162f4a2713aSLionel Sambuc   void foo(B b);
bar()163f4a2713aSLionel Sambuc   void bar() {
164f4a2713aSLionel Sambuc    B b;
165f4a2713aSLionel Sambuc    foo(b);
166f4a2713aSLionel Sambuc   }
167f4a2713aSLionel Sambuc }
168f4a2713aSLionel Sambuc 
169f4a2713aSLionel Sambuc // PR4242
170f4a2713aSLionel Sambuc namespace test9 {
171f4a2713aSLionel Sambuc   // Large enough to be passed indirectly.
172f4a2713aSLionel Sambuc   struct S { void *data[3]; };
173f4a2713aSLionel Sambuc 
174f4a2713aSLionel Sambuc   struct T { void *data[2]; };
175f4a2713aSLionel Sambuc 
176f4a2713aSLionel Sambuc   // CHECK: define void @_ZN5test93fooEPNS_1SEPNS_1TE([[S:%.*]]*, [[T:%.*]]*)
foo(S *,T *)177f4a2713aSLionel Sambuc   void foo(S*, T*) {}
178f4a2713aSLionel Sambuc 
179f4a2713aSLionel Sambuc   // CHECK: define void @_ZN5test91aEiiiiNS_1TEPv([[S]]* noalias sret {{%.*}}, i32, i32, i32, i32, [[T]]* byval align 8, i8*)
a(int,int,int,int,T,void *)180f4a2713aSLionel Sambuc   S a(int, int, int, int, T, void*) {
181f4a2713aSLionel Sambuc     return S();
182f4a2713aSLionel Sambuc   }
183f4a2713aSLionel Sambuc 
184f4a2713aSLionel Sambuc   // CHECK: define [[S]]* @_ZN5test91bEPNS_1SEiiiiNS_1TEPv([[S]]* {{%.*}}, i32, i32, i32, i32, [[T:%.*]]* byval align 8, i8*)
b(S * sret,int,int,int,int,T,void *)185f4a2713aSLionel Sambuc   S* b(S* sret, int, int, int, int, T, void*) {
186f4a2713aSLionel Sambuc     return sret;
187f4a2713aSLionel Sambuc   }
188f4a2713aSLionel Sambuc 
189f4a2713aSLionel Sambuc   // CHECK: define void @_ZN5test91cEiiiNS_1TEPv([[S]]* noalias sret {{%.*}}, i32, i32, i32, i8* {{%.*}}, i8* {{%.*}}, i8*)
c(int,int,int,T,void *)190f4a2713aSLionel Sambuc   S c(int, int, int, T, void*) {
191f4a2713aSLionel Sambuc     return S();
192f4a2713aSLionel Sambuc   }
193f4a2713aSLionel Sambuc 
194f4a2713aSLionel Sambuc   // CHECK: define [[S]]* @_ZN5test91dEPNS_1SEiiiNS_1TEPv([[S]]* {{%.*}}, i32, i32, i32, i8* {{%.*}}, i8* {{%.*}}, i8*)
d(S * sret,int,int,int,T,void *)195f4a2713aSLionel Sambuc   S* d(S* sret, int, int, int, T, void*) {
196f4a2713aSLionel Sambuc     return sret;
197f4a2713aSLionel Sambuc   }
198f4a2713aSLionel Sambuc }
199