blob: 815ef6111a9ae1e4ce6bc39d6cb0330434c89c63 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
Anders Carlsson0a8f8472009-09-16 15:53:40 +00002
Daniel Dunbarce9f4232009-11-22 23:01:23 +00003// Basic base class test.
4struct f0_s0 { unsigned a; };
5struct f0_s1 : public f0_s0 { void *b; };
Stephen Lin93ab6bf2013-08-15 06:47:53 +00006// CHECK-LABEL: define void @_Z2f05f0_s1(i32 %a0.coerce0, i8* %a0.coerce1)
Daniel Dunbarce9f4232009-11-22 23:01:23 +00007void f0(f0_s1 a0) { }
8
9// Check with two eight-bytes in base class.
10struct f1_s0 { unsigned a; unsigned b; float c; };
11struct f1_s1 : public f1_s0 { float d;};
Stephen Lin93ab6bf2013-08-15 06:47:53 +000012// CHECK-LABEL: define void @_Z2f15f1_s1(i64 %a0.coerce0, <2 x float> %a0.coerce1)
Daniel Dunbarce9f4232009-11-22 23:01:23 +000013void f1(f1_s1 a0) { }
14
15// Check with two eight-bytes in base class and merge.
16struct f2_s0 { unsigned a; unsigned b; float c; };
17struct f2_s1 : public f2_s0 { char d;};
Stephen Lin93ab6bf2013-08-15 06:47:53 +000018// CHECK-LABEL: define void @_Z2f25f2_s1(i64 %a0.coerce0, i64 %a0.coerce1)
Daniel Dunbarce9f4232009-11-22 23:01:23 +000019void f2(f2_s1 a0) { }
20
Daniel Dunbar4971ff82009-12-22 01:19:25 +000021// PR5831
Stephen Lin93ab6bf2013-08-15 06:47:53 +000022// CHECK-LABEL: define void @_Z2f34s3_1(i64 %x.coerce)
Daniel Dunbar4971ff82009-12-22 01:19:25 +000023struct s3_0 {};
24struct s3_1 { struct s3_0 a; long b; };
25void f3(struct s3_1 x) {}
Daniel Dunbar67d438d2010-05-15 00:00:37 +000026
Stephen Lin93ab6bf2013-08-15 06:47:53 +000027// CHECK-LABEL: define i64 @_Z4f4_0M2s4i(i64 %a)
Chris Lattner9c254f02010-06-29 06:01:59 +000028// CHECK: define {{.*}} @_Z4f4_1M2s4FivE(i64 %a.coerce0, i64 %a.coerce1)
Daniel Dunbar67d438d2010-05-15 00:00:37 +000029struct s4 {};
30typedef int s4::* s4_mdp;
31typedef int (s4::*s4_mfp)();
32s4_mdp f4_0(s4_mdp a) { return a; }
33s4_mfp f4_1(s4_mfp a) { return a; }
Chris Lattnerbcaedae2010-06-30 19:14:05 +000034
Stephen Hines176edba2014-12-01 14:53:08 -080035// A struct with <= one eightbyte before a member data pointer should still
36// be allowed in registers.
37// CHECK-LABEL: define void @{{.*}}f_struct_with_mdp{{.*}}(i8* %a.coerce0, i64 %a.coerce1)
38struct struct_with_mdp { char *a; s4_mdp b; };
39void f_struct_with_mdp(struct_with_mdp a) { (void)a; }
40
41// A struct with anything before a member function will be too big and
42// goes in memory.
43// CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_0{{.*}}(%struct{{.*}} byval align 8 %a)
44struct struct_with_mfp_0 { char a; s4_mfp b; };
45void f_struct_with_mfp_0(struct_with_mfp_0 a) { (void)a; }
46
47// CHECK-LABEL: define void @{{.*}}f_struct_with_mfp_1{{.*}}(%struct{{.*}} byval align 8 %a)
48struct struct_with_mfp_1 { void *a; s4_mfp b; };
49void f_struct_with_mfp_1(struct_with_mfp_1 a) { (void)a; }
Chris Lattnerbcaedae2010-06-30 19:14:05 +000050
51namespace PR7523 {
52struct StringRef {
53 char *a;
54};
55
56void AddKeyword(StringRef, int x);
57
58void foo() {
Stephen Lin93ab6bf2013-08-15 06:47:53 +000059 // CHECK-LABEL: define void @_ZN6PR75233fooEv()
Chris Lattnerbcaedae2010-06-30 19:14:05 +000060 // CHECK: call void @_ZN6PR752310AddKeywordENS_9StringRefEi(i8* {{.*}}, i32 4)
61 AddKeyword(StringRef(), 4);
62}
Chris Lattnera7206c52010-07-29 17:04:54 +000063}
64
Chris Lattnera7206c52010-07-29 17:04:54 +000065namespace PR7742 { // Also rdar://8250764
66 struct s2 {
67 float a[2];
68 };
69
70 struct c2 : public s2 {};
71
Stephen Lin93ab6bf2013-08-15 06:47:53 +000072 // CHECK-LABEL: define <2 x float> @_ZN6PR77423fooEPNS_2c2E(%"struct.PR7742::c2"* %P)
Chris Lattnera7206c52010-07-29 17:04:54 +000073 c2 foo(c2 *P) {
John McCall92c6c902012-05-03 01:34:46 +000074 return c2();
Chris Lattnera7206c52010-07-29 17:04:54 +000075 }
76
Chris Lattner117e3f42010-07-30 04:02:24 +000077}
78
79namespace PR5179 {
80 struct B {};
81
82 struct B1 : B {
83 int* pa;
84 };
85
86 struct B2 : B {
87 B1 b1;
88 };
89
Stephen Lin93ab6bf2013-08-15 06:47:53 +000090 // CHECK-LABEL: define i8* @_ZN6PR51793barENS_2B2E(i32* %b2.coerce)
Chris Lattner117e3f42010-07-30 04:02:24 +000091 const void *bar(B2 b2) {
92 return b2.b1.pa;
93 }
94}
Chris Lattnerb6c504b2010-08-23 05:26:13 +000095
96namespace test5 {
97 struct Xbase { };
98 struct Empty { };
99 struct Y;
100 struct X : public Xbase {
101 Empty empty;
102 Y f();
103 };
104 struct Y : public X {
105 Empty empty;
106 };
107 X getX();
108 int takeY(const Y&, int y);
109 void g() {
110 // rdar://8340348 - The temporary for the X object needs to have a defined
111 // address when passed into X::f as 'this'.
112 takeY(getX().f(), 42);
113 }
114 // CHECK: void @_ZN5test51gEv()
115 // CHECK: alloca %"struct.test5::Y"
116 // CHECK: alloca %"struct.test5::X"
117 // CHECK: alloca %"struct.test5::Y"
118}
Chris Lattner66e7b682010-09-01 00:50:20 +0000119
120
121// rdar://8360877
122namespace test6 {
123 struct outer {
124 int x;
125 struct epsilon_matcher {} e;
126 int f;
127 };
128
129 int test(outer x) {
130 return x.x + x.f;
131 }
Stephen Lin93ab6bf2013-08-15 06:47:53 +0000132 // CHECK-LABEL: define i32 @_ZN5test64testENS_5outerE(i64 %x.coerce0, i32 %x.coerce1)
Chris Lattner66e7b682010-09-01 00:50:20 +0000133}
Eli Friedmanded137f2011-06-29 07:04:55 +0000134
135namespace test7 {
136 struct StringRef {char* ptr; long len; };
137 class A { public: ~A(); };
138 A x(A, A, long, long, StringRef) { return A(); }
139 // Check that the StringRef is passed byval instead of expanded
140 // (which would split it between registers and memory).
141 // rdar://problem/9686430
Bill Wendlingc1ea4b92013-02-15 05:25:49 +0000142 // CHECK: define void @_ZN5test71xENS_1AES0_llNS_9StringRefE({{.*}} byval align 8)
Eli Friedmanded137f2011-06-29 07:04:55 +0000143
144 // And a couple extra related tests:
145 A y(A, long double, long, long, StringRef) { return A(); }
146 // CHECK: define void @_ZN5test71yENS_1AEellNS_9StringRefE({{.*}} i8*
147 struct StringDouble {char * ptr; double d;};
148 A z(A, A, A, A, A, StringDouble) { return A(); }
149 A zz(A, A, A, A, StringDouble) { return A(); }
Bill Wendlingc1ea4b92013-02-15 05:25:49 +0000150 // CHECK: define void @_ZN5test71zENS_1AES0_S0_S0_S0_NS_12StringDoubleE({{.*}} byval align 8)
Eli Friedmanded137f2011-06-29 07:04:55 +0000151 // CHECK: define void @_ZN5test72zzENS_1AES0_S0_S0_NS_12StringDoubleE({{.*}} i8*
152}
Bruno Cardoso Lopesb8981df2011-07-13 21:58:55 +0000153
154namespace test8 {
Bill Wendlingc1ea4b92013-02-15 05:25:49 +0000155 // CHECK: declare void @_ZN5test83fooENS_1BE(%"class.test8::B"* byval align 8)
Bruno Cardoso Lopesb8981df2011-07-13 21:58:55 +0000156 class A {
157 char big[17];
158 };
159
160 class B : public A {};
161
162 void foo(B b);
163 void bar() {
164 B b;
165 foo(b);
166 }
167}
John McCall92c6c902012-05-03 01:34:46 +0000168
169// PR4242
170namespace test9 {
171 // Large enough to be passed indirectly.
172 struct S { void *data[3]; };
173
174 struct T { void *data[2]; };
175
176 // CHECK: define void @_ZN5test93fooEPNS_1SEPNS_1TE([[S:%.*]]*, [[T:%.*]]*)
177 void foo(S*, T*) {}
178
Bill Wendlingc1ea4b92013-02-15 05:25:49 +0000179 // CHECK: define void @_ZN5test91aEiiiiNS_1TEPv([[S]]* noalias sret {{%.*}}, i32, i32, i32, i32, [[T]]* byval align 8, i8*)
John McCall92c6c902012-05-03 01:34:46 +0000180 S a(int, int, int, int, T, void*) {
181 return S();
182 }
183
Bill Wendlingc1ea4b92013-02-15 05:25:49 +0000184 // CHECK: define [[S]]* @_ZN5test91bEPNS_1SEiiiiNS_1TEPv([[S]]* {{%.*}}, i32, i32, i32, i32, [[T:%.*]]* byval align 8, i8*)
John McCall92c6c902012-05-03 01:34:46 +0000185 S* b(S* sret, int, int, int, int, T, void*) {
186 return sret;
187 }
188
Bill Wendling5e314742013-01-31 23:17:12 +0000189 // CHECK: define void @_ZN5test91cEiiiNS_1TEPv([[S]]* noalias sret {{%.*}}, i32, i32, i32, i8* {{%.*}}, i8* {{%.*}}, i8*)
John McCall92c6c902012-05-03 01:34:46 +0000190 S c(int, int, int, T, void*) {
191 return S();
192 }
193
194 // CHECK: define [[S]]* @_ZN5test91dEPNS_1SEiiiNS_1TEPv([[S]]* {{%.*}}, i32, i32, i32, i8* {{%.*}}, i8* {{%.*}}, i8*)
195 S* d(S* sret, int, int, int, T, void*) {
196 return sret;
197 }
198}