x86_64-arguments.cpp revision b8981df0ed2886dfa221f2fad6d86872c39d3549
1// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
2
3// Basic base class test.
4struct f0_s0 { unsigned a; };
5struct f0_s1 : public f0_s0 { void *b; };
6// CHECK: define void @_Z2f05f0_s1(i32 %a0.coerce0, i8* %a0.coerce1)
7void 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;};
12// CHECK: define void @_Z2f15f1_s1(i64 %a0.coerce0, <2 x float> %a0.coerce1)
13void 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;};
18// CHECK: define void @_Z2f25f2_s1(i64 %a0.coerce0, i64 %a0.coerce1)
19void f2(f2_s1 a0) { }
20
21// PR5831
22// CHECK: define void @_Z2f34s3_1(i64 %x.coerce)
23struct s3_0 {};
24struct s3_1 { struct s3_0 a; long b; };
25void f3(struct s3_1 x) {}
26
27// CHECK: define i64 @_Z4f4_0M2s4i(i64 %a)
28// CHECK: define {{.*}} @_Z4f4_1M2s4FivE(i64 %a.coerce0, i64 %a.coerce1)
29struct 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; }
34
35
36namespace PR7523 {
37struct StringRef {
38  char *a;
39};
40
41void AddKeyword(StringRef, int x);
42
43void foo() {
44  // CHECK: define void @_ZN6PR75233fooEv()
45  // CHECK: call void @_ZN6PR752310AddKeywordENS_9StringRefEi(i8* {{.*}}, i32 4)
46  AddKeyword(StringRef(), 4);
47}
48}
49
50namespace PR7742 { // Also rdar://8250764
51  struct s2 {
52    float a[2];
53  };
54
55  struct c2 : public s2 {};
56
57  // CHECK: define <2 x float> @_ZN6PR77423fooEPNS_2c2E(%"struct.PR7742::c2"* %P)
58  c2 foo(c2 *P) {
59  }
60
61}
62
63namespace PR5179 {
64  struct B {};
65
66  struct B1 : B {
67    int* pa;
68  };
69
70  struct B2 : B {
71    B1 b1;
72  };
73
74  // CHECK: define i8* @_ZN6PR51793barENS_2B2E(i32* %b2.coerce)
75  const void *bar(B2 b2) {
76    return b2.b1.pa;
77  }
78}
79
80namespace test5 {
81  struct Xbase { };
82  struct Empty { };
83  struct Y;
84  struct X : public Xbase {
85    Empty empty;
86    Y f();
87  };
88  struct Y : public X {
89    Empty empty;
90  };
91  X getX();
92  int takeY(const Y&, int y);
93  void g() {
94    // rdar://8340348 - The temporary for the X object needs to have a defined
95    // address when passed into X::f as 'this'.
96    takeY(getX().f(), 42);
97  }
98  // CHECK: void @_ZN5test51gEv()
99  // CHECK: alloca %"struct.test5::Y"
100  // CHECK: alloca %"struct.test5::X"
101  // CHECK: alloca %"struct.test5::Y"
102}
103
104
105// rdar://8360877
106namespace test6 {
107  struct outer {
108    int x;
109    struct epsilon_matcher {} e;
110    int f;
111  };
112
113  int test(outer x) {
114    return x.x + x.f;
115  }
116  // CHECK: define i32 @_ZN5test64testENS_5outerE(i64 %x.coerce0, i32 %x.coerce1)
117}
118
119namespace test7 {
120  struct StringRef {char* ptr; long len; };
121  class A { public: ~A(); };
122  A x(A, A, long, long, StringRef) { return A(); }
123  // Check that the StringRef is passed byval instead of expanded
124  // (which would split it between registers and memory).
125  // rdar://problem/9686430
126  // CHECK: define void @_ZN5test71xENS_1AES0_llNS_9StringRefE({{.*}} byval align 8)
127
128  // And a couple extra related tests:
129  A y(A, long double, long, long, StringRef) { return A(); }
130  // CHECK: define void @_ZN5test71yENS_1AEellNS_9StringRefE({{.*}} i8*
131  struct StringDouble {char * ptr; double d;};
132  A z(A, A, A, A, A, StringDouble) { return A(); }
133  A zz(A, A, A, A, StringDouble) { return A(); }
134  // CHECK: define void @_ZN5test71zENS_1AES0_S0_S0_S0_NS_12StringDoubleE({{.*}} byval align 8)
135  // CHECK: define void @_ZN5test72zzENS_1AES0_S0_S0_NS_12StringDoubleE({{.*}} i8*
136}
137
138namespace test8 {
139  // CHECK: declare void @_ZN5test83fooENS_1BE(%"class.test8::B"* byval align 8)
140  class A {
141   char big[17];
142  };
143
144  class B : public A {};
145
146  void foo(B b);
147  void bar() {
148   B b;
149   foo(b);
150  }
151}
152