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 13 int test0() { 14 extern __unknown_anytype test0_any; 15 // COMMON: load i32, i32* @test0_any 16 return (int) test0_any; 17 } 18 19 int test1() { 20 extern __unknown_anytype test1_any(); 21 // COMMON: call i32 @_Z9test1_anyv() 22 return (int) test1_any(); 23 } 24 25 extern "C" __unknown_anytype test2_any(...); 26 float 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 32 extern "C" __unknown_anytype test2a_any(...); 33 float 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 39 float 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 46 namespace 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 57 extern "C" __unknown_anytype test5_any(); 58 void test5() { 59 // COMMON: call void @test5_any() 60 return (void) test5_any(); 61 } 62 63 extern "C" __unknown_anytype test6_any(float *); 64 long test6() { 65 // COMMON: call i64 @test6_any(float* null) 66 return (long long) test6_any(0); 67 } 68 69 struct Test7 { 70 ~Test7(); 71 }; 72 extern "C" __unknown_anytype test7_any(int); 73 Test7 test7() { 74 // COMMON: call void @test7_any({{%.*}}* sret {{%.*}}, i32 5) 75 return (Test7) test7_any(5); 76 } 77 78 struct Test8 { 79 __unknown_anytype foo(); 80 __unknown_anytype foo(int); 81 82 void test(); 83 }; 84 void 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 } 95 void 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 107 extern "C" __unknown_anytype test9_foo; 108 void *test9() { 109 // COMMON: ret i8* bitcast (i32* @test9_foo to i8*) 110 return (int*) &test9_foo; 111 } 112 113 // Don't explode on this. 114 extern "C" __unknown_anytype test10_any(...); 115 void test10() { 116 (void) test10_any(), (void) test10_any(); 117 } 118 119 extern "C" __unknown_anytype malloc(...); 120 void 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