Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 2 | |
Daniel Dunbar | ce9f423 | 2009-11-22 23:01:23 +0000 | [diff] [blame] | 3 | // Basic base class test. |
| 4 | struct f0_s0 { unsigned a; }; |
| 5 | struct f0_s1 : public f0_s0 { void *b; }; |
Anders Carlsson | eb9d81d | 2011-04-17 21:56:13 +0000 | [diff] [blame] | 6 | // CHECK: define void @_Z2f05f0_s1(i32 %a0.coerce0, i8* %a0.coerce1) |
Daniel Dunbar | ce9f423 | 2009-11-22 23:01:23 +0000 | [diff] [blame] | 7 | void f0(f0_s1 a0) { } |
| 8 | |
| 9 | // Check with two eight-bytes in base class. |
| 10 | struct f1_s0 { unsigned a; unsigned b; float c; }; |
| 11 | struct f1_s1 : public f1_s0 { float d;}; |
Anders Carlsson | eb9d81d | 2011-04-17 21:56:13 +0000 | [diff] [blame] | 12 | // CHECK: define void @_Z2f15f1_s1(i64 %a0.coerce0, <2 x float> %a0.coerce1) |
Daniel Dunbar | ce9f423 | 2009-11-22 23:01:23 +0000 | [diff] [blame] | 13 | void f1(f1_s1 a0) { } |
| 14 | |
| 15 | // Check with two eight-bytes in base class and merge. |
| 16 | struct f2_s0 { unsigned a; unsigned b; float c; }; |
| 17 | struct f2_s1 : public f2_s0 { char d;}; |
Chris Lattner | 225e286 | 2010-06-29 00:14:52 +0000 | [diff] [blame] | 18 | // CHECK: define void @_Z2f25f2_s1(i64 %a0.coerce0, i64 %a0.coerce1) |
Daniel Dunbar | ce9f423 | 2009-11-22 23:01:23 +0000 | [diff] [blame] | 19 | void f2(f2_s1 a0) { } |
| 20 | |
Daniel Dunbar | 4971ff8 | 2009-12-22 01:19:25 +0000 | [diff] [blame] | 21 | // PR5831 |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 22 | // CHECK: define void @_Z2f34s3_1(i64 %x.coerce) |
Daniel Dunbar | 4971ff8 | 2009-12-22 01:19:25 +0000 | [diff] [blame] | 23 | struct s3_0 {}; |
| 24 | struct s3_1 { struct s3_0 a; long b; }; |
| 25 | void f3(struct s3_1 x) {} |
Daniel Dunbar | 67d438d | 2010-05-15 00:00:37 +0000 | [diff] [blame] | 26 | |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 27 | // CHECK: define i64 @_Z4f4_0M2s4i(i64 %a) |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 28 | // CHECK: define {{.*}} @_Z4f4_1M2s4FivE(i64 %a.coerce0, i64 %a.coerce1) |
Daniel Dunbar | 67d438d | 2010-05-15 00:00:37 +0000 | [diff] [blame] | 29 | struct s4 {}; |
| 30 | typedef int s4::* s4_mdp; |
| 31 | typedef int (s4::*s4_mfp)(); |
| 32 | s4_mdp f4_0(s4_mdp a) { return a; } |
| 33 | s4_mfp f4_1(s4_mfp a) { return a; } |
Chris Lattner | bcaedae | 2010-06-30 19:14:05 +0000 | [diff] [blame] | 34 | |
| 35 | |
| 36 | namespace PR7523 { |
| 37 | struct StringRef { |
| 38 | char *a; |
| 39 | }; |
| 40 | |
| 41 | void AddKeyword(StringRef, int x); |
| 42 | |
| 43 | void foo() { |
| 44 | // CHECK: define void @_ZN6PR75233fooEv() |
| 45 | // CHECK: call void @_ZN6PR752310AddKeywordENS_9StringRefEi(i8* {{.*}}, i32 4) |
| 46 | AddKeyword(StringRef(), 4); |
| 47 | } |
Chris Lattner | a7206c5 | 2010-07-29 17:04:54 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Chris Lattner | a7206c5 | 2010-07-29 17:04:54 +0000 | [diff] [blame] | 50 | namespace PR7742 { // Also rdar://8250764 |
| 51 | struct s2 { |
| 52 | float a[2]; |
| 53 | }; |
| 54 | |
| 55 | struct c2 : public s2 {}; |
| 56 | |
Anders Carlsson | eb9d81d | 2011-04-17 21:56:13 +0000 | [diff] [blame] | 57 | // CHECK: define <2 x float> @_ZN6PR77423fooEPNS_2c2E(%"struct.PR7742::c2"* %P) |
Chris Lattner | a7206c5 | 2010-07-29 17:04:54 +0000 | [diff] [blame] | 58 | c2 foo(c2 *P) { |
John McCall | 92c6c90 | 2012-05-03 01:34:46 +0000 | [diff] [blame^] | 59 | return c2(); |
Chris Lattner | a7206c5 | 2010-07-29 17:04:54 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | namespace PR5179 { |
| 65 | struct B {}; |
| 66 | |
| 67 | struct B1 : B { |
| 68 | int* pa; |
| 69 | }; |
| 70 | |
| 71 | struct B2 : B { |
| 72 | B1 b1; |
| 73 | }; |
| 74 | |
| 75 | // CHECK: define i8* @_ZN6PR51793barENS_2B2E(i32* %b2.coerce) |
| 76 | const void *bar(B2 b2) { |
| 77 | return b2.b1.pa; |
| 78 | } |
| 79 | } |
Chris Lattner | b6c504b | 2010-08-23 05:26:13 +0000 | [diff] [blame] | 80 | |
| 81 | namespace test5 { |
| 82 | struct Xbase { }; |
| 83 | struct Empty { }; |
| 84 | struct Y; |
| 85 | struct X : public Xbase { |
| 86 | Empty empty; |
| 87 | Y f(); |
| 88 | }; |
| 89 | struct Y : public X { |
| 90 | Empty empty; |
| 91 | }; |
| 92 | X getX(); |
| 93 | int takeY(const Y&, int y); |
| 94 | void g() { |
| 95 | // rdar://8340348 - The temporary for the X object needs to have a defined |
| 96 | // address when passed into X::f as 'this'. |
| 97 | takeY(getX().f(), 42); |
| 98 | } |
| 99 | // CHECK: void @_ZN5test51gEv() |
| 100 | // CHECK: alloca %"struct.test5::Y" |
| 101 | // CHECK: alloca %"struct.test5::X" |
| 102 | // CHECK: alloca %"struct.test5::Y" |
| 103 | } |
Chris Lattner | 66e7b68 | 2010-09-01 00:50:20 +0000 | [diff] [blame] | 104 | |
| 105 | |
| 106 | // rdar://8360877 |
| 107 | namespace test6 { |
| 108 | struct outer { |
| 109 | int x; |
| 110 | struct epsilon_matcher {} e; |
| 111 | int f; |
| 112 | }; |
| 113 | |
| 114 | int test(outer x) { |
| 115 | return x.x + x.f; |
| 116 | } |
| 117 | // CHECK: define i32 @_ZN5test64testENS_5outerE(i64 %x.coerce0, i32 %x.coerce1) |
| 118 | } |
Eli Friedman | ded137f | 2011-06-29 07:04:55 +0000 | [diff] [blame] | 119 | |
| 120 | namespace test7 { |
| 121 | struct StringRef {char* ptr; long len; }; |
| 122 | class A { public: ~A(); }; |
| 123 | A x(A, A, long, long, StringRef) { return A(); } |
| 124 | // Check that the StringRef is passed byval instead of expanded |
| 125 | // (which would split it between registers and memory). |
| 126 | // rdar://problem/9686430 |
| 127 | // CHECK: define void @_ZN5test71xENS_1AES0_llNS_9StringRefE({{.*}} byval align 8) |
| 128 | |
| 129 | // And a couple extra related tests: |
| 130 | A y(A, long double, long, long, StringRef) { return A(); } |
| 131 | // CHECK: define void @_ZN5test71yENS_1AEellNS_9StringRefE({{.*}} i8* |
| 132 | struct StringDouble {char * ptr; double d;}; |
| 133 | A z(A, A, A, A, A, StringDouble) { return A(); } |
| 134 | A zz(A, A, A, A, StringDouble) { return A(); } |
| 135 | // CHECK: define void @_ZN5test71zENS_1AES0_S0_S0_S0_NS_12StringDoubleE({{.*}} byval align 8) |
| 136 | // CHECK: define void @_ZN5test72zzENS_1AES0_S0_S0_NS_12StringDoubleE({{.*}} i8* |
| 137 | } |
Bruno Cardoso Lopes | b8981df | 2011-07-13 21:58:55 +0000 | [diff] [blame] | 138 | |
| 139 | namespace test8 { |
| 140 | // CHECK: declare void @_ZN5test83fooENS_1BE(%"class.test8::B"* byval align 8) |
| 141 | class A { |
| 142 | char big[17]; |
| 143 | }; |
| 144 | |
| 145 | class B : public A {}; |
| 146 | |
| 147 | void foo(B b); |
| 148 | void bar() { |
| 149 | B b; |
| 150 | foo(b); |
| 151 | } |
| 152 | } |
John McCall | 92c6c90 | 2012-05-03 01:34:46 +0000 | [diff] [blame^] | 153 | |
| 154 | // PR4242 |
| 155 | namespace test9 { |
| 156 | // Large enough to be passed indirectly. |
| 157 | struct S { void *data[3]; }; |
| 158 | |
| 159 | struct T { void *data[2]; }; |
| 160 | |
| 161 | // CHECK: define void @_ZN5test93fooEPNS_1SEPNS_1TE([[S:%.*]]*, [[T:%.*]]*) |
| 162 | void foo(S*, T*) {} |
| 163 | |
| 164 | // CHECK: define void @_ZN5test91aEiiiiNS_1TEPv([[S]]* noalias sret {{%.*}}, i32, i32, i32, i32, [[T]]* byval align 8, i8*) |
| 165 | S a(int, int, int, int, T, void*) { |
| 166 | return S(); |
| 167 | } |
| 168 | |
| 169 | // CHECK: define [[S]]* @_ZN5test91bEPNS_1SEiiiiNS_1TEPv([[S]]* {{%.*}}, i32, i32, i32, i32, [[T:%.*]]* byval align 8, i8*) |
| 170 | S* b(S* sret, int, int, int, int, T, void*) { |
| 171 | return sret; |
| 172 | } |
| 173 | |
| 174 | // CHECK: define void @_ZN5test91cEiiiNS_1TEPv([[S]]* noalias sret {{%.*}}, i32, i32, i32, i8* {{%.*}}, i8* {{%.*}}, i8*) |
| 175 | S c(int, int, int, T, void*) { |
| 176 | return S(); |
| 177 | } |
| 178 | |
| 179 | // CHECK: define [[S]]* @_ZN5test91dEPNS_1SEiiiNS_1TEPv([[S]]* {{%.*}}, i32, i32, i32, i8* {{%.*}}, i8* {{%.*}}, i8*) |
| 180 | S* d(S* sret, int, int, int, T, void*) { |
| 181 | return sret; |
| 182 | } |
| 183 | } |