1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -funknown-anytype -emit-llvm -o %t %s
2// RUN: FileCheck -check-prefix COMMON %s < %t
3// RUN: FileCheck -check-prefix X86_64 %s < %t
4// RUN: %clang_cc1 -triple i386-apple-darwin10 -funknown-anytype -emit-llvm -o %t %s
5// RUN: FileCheck -check-prefix COMMON %s < %t
6// RUN: FileCheck -check-prefix I386 %s < %t
7
8// x86-64 is the special case here because of its variadic convention.
9// We want to ensure that it always uses a variadic convention even if
10// other platforms do not.
11// rdar://13731520
12
13int test0() {
14  extern __unknown_anytype test0_any;
15  // COMMON: load i32, i32* @test0_any
16  return (int) test0_any;
17}
18
19int test1() {
20  extern __unknown_anytype test1_any();
21  // COMMON: call i32 @_Z9test1_anyv()
22  return (int) test1_any();
23}
24
25extern "C" __unknown_anytype test2_any(...);
26float test2() {
27  // X86_64: call float (double, ...) @test2_any(double {{[^,]+}})
28  // I386: call float (double, ...) @test2_any(double {{[^,]+}})
29  return (float) test2_any(0.5f);
30}
31
32extern "C" __unknown_anytype test2a_any(...);
33float test2a() {
34  // X86_64: call float (float, ...) @test2a_any(float {{[^,]+}})
35  // I386: call float (float, ...) @test2a_any(float {{[^,]+}})
36  return (float) test2a_any((float) 0.5f);
37}
38
39float test3() {
40  extern __unknown_anytype test3_any;
41  // COMMON: [[FN:%.*]] = load float (i32)*, float (i32)** @test3_any,
42  // COMMON: call float [[FN]](i32 5)
43  return ((float(*)(int)) test3_any)(5);
44}
45
46namespace test4 {
47  extern __unknown_anytype test4_any1;
48  extern __unknown_anytype test4_any2;
49
50  int test() {
51    // COMMON: load i32, i32* @_ZN5test410test4_any1E
52    // COMMON: load i8, i8* @_ZN5test410test4_any2E
53    return (int) test4_any1 + (char) test4_any2;
54  }
55}
56
57extern "C" __unknown_anytype test5_any();
58void test5() {
59  // COMMON: call void @test5_any()
60  return (void) test5_any();
61}
62
63extern "C" __unknown_anytype test6_any(float *);
64long test6() {
65  // COMMON: call i64 @test6_any(float* null)
66  return (long long) test6_any(0);
67}
68
69struct Test7 {
70  ~Test7();
71};
72extern "C" __unknown_anytype test7_any(int);
73Test7 test7() {
74  // COMMON: call void @test7_any({{%.*}}* sret {{%.*}}, i32 5)
75  return (Test7) test7_any(5);
76}
77
78struct Test8 {
79  __unknown_anytype foo();
80  __unknown_anytype foo(int);
81
82  void test();
83};
84void Test8::test() {
85  float f;
86  // COMMON: call i32 @_ZN5Test83fooEv(
87  f = (int) foo();
88  // COMMON: call i32 @_ZN5Test83fooEi(
89  f = (int) foo(5);
90  // COMMON: call i32 @_ZN5Test83fooEv(
91  f = (float) this->foo();
92  // COMMON: call i32 @_ZN5Test83fooEi(
93  f = (float) this->foo(5);
94}
95void test8(Test8 *p) {
96  double d;
97  // COMMON: call i32 @_ZN5Test83fooEv(
98  d = (double) p->foo();
99  // COMMON: call i32 @_ZN5Test83fooEi(
100  d = (double) p->foo(5);
101  // COMMON: call i32 @_ZN5Test83fooEv(
102  d = (bool) (*p).foo();
103  // COMMON: call i32 @_ZN5Test83fooEi(
104  d = (bool) (*p).foo(5);
105}
106
107extern "C" __unknown_anytype test9_foo;
108void *test9() {
109  // COMMON: ret i8* bitcast (i32* @test9_foo to i8*)
110  return (int*) &test9_foo;
111}
112
113// Don't explode on this.
114extern "C" __unknown_anytype test10_any(...);
115void test10() {
116  (void) test10_any(), (void) test10_any();
117}
118
119extern "C" __unknown_anytype malloc(...);
120void test11() {
121  void *s = (void*)malloc(12);
122  // COMMON: call i8* (i32, ...) @malloc(i32 12)
123  void *d = (void*)malloc(435);
124  // COMMON: call i8* (i32, ...) @malloc(i32 435)
125}
126