blob: 0850cc4ee4b922f1043f279b2cfe94a533fd2e6a [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -triple=i686-apple-darwin9
Eli Friedman14352022008-05-25 04:43:38 +00002// This test needs to set the target because it uses __builtin_ia32_vec_ext_v4si
Chris Lattner1b9a0792007-12-20 00:26:33 +00003
4int test1(float a, int b) {
5 return __builtin_isless(a, b);
6}
7int test2(int a, int b) {
8 return __builtin_islessequal(a, b); // expected-error {{floating point type}}
9}
10
11int test3(double a, float b) {
12 return __builtin_isless(a, b);
13}
14int test4(int* a, double b) {
15 return __builtin_islessequal(a, b); // expected-error {{floating point type}}
16}
17
18int test5(float a, long double b) {
19 return __builtin_isless(a, b, b); // expected-error {{too many arguments}}
20}
21int test6(float a, long double b) {
22 return __builtin_islessequal(a); // expected-error {{too few arguments}}
23}
24
25
26#define CFSTR __builtin___CFStringMakeConstantString
Chris Lattner5caa3702009-05-08 06:58:22 +000027void test7() {
Chris Lattner634785c2009-12-30 22:10:22 +000028 const void *X;
Fariborz Jahanian7da71022010-09-07 19:38:13 +000029 X = CFSTR("\242"); // expected-warning {{input conversion stopped}}
Ted Kremenekdb9e9e62011-03-15 21:18:52 +000030 X = CFSTR("\0"); // no-warning
Chris Lattner634785c2009-12-30 22:10:22 +000031 X = CFSTR(242); // expected-error {{ CFString literal is not a string constant }} expected-warning {{incompatible integer to pointer conversion}}
32 X = CFSTR("foo", "bar"); // expected-error {{too many arguments to function call}}
Chris Lattner1b9a0792007-12-20 00:26:33 +000033}
34
Chris Lattner95e2c712008-05-05 22:18:14 +000035
Chris Lattner5caa3702009-05-08 06:58:22 +000036// atomics.
37
Mike Stumpd1969d82009-07-22 00:43:08 +000038void test9(short v) {
Chris Lattner5caa3702009-05-08 06:58:22 +000039 unsigned i, old;
Gabor Greif2fb985b2010-10-15 08:48:51 +000040
Chris Lattner5caa3702009-05-08 06:58:22 +000041 old = __sync_fetch_and_add(); // expected-error {{too few arguments to function call}}
42 old = __sync_fetch_and_add(&old); // expected-error {{too few arguments to function call}}
Chandler Carruthd2014572010-07-09 18:59:35 +000043 old = __sync_fetch_and_add((unsigned*)0, 42i); // expected-warning {{imaginary constants are an extension}}
44
45 // PR7600: Pointers are implicitly casted to integers and back.
46 void *old_ptr = __sync_val_compare_and_swap((void**)0, 0, 0);
Chandler Carruthdb4325b2010-07-18 07:23:17 +000047
48 // Ensure the return type is correct even when implicit casts are stripped
49 // away. This triggers an assertion while checking the comparison otherwise.
50 if (__sync_fetch_and_add(&old, 1) == 1) {
51 }
Chris Lattner5caa3702009-05-08 06:58:22 +000052}
Chris Lattner21190d52009-09-21 03:09:59 +000053
54
55// rdar://7236819
56void test10(void) __attribute__((noreturn));
57
58void test10(void) {
Gabor Greif2fb985b2010-10-15 08:48:51 +000059 __asm__("int3");
Chris Lattner21190d52009-09-21 03:09:59 +000060 __builtin_unreachable();
Gabor Greif2fb985b2010-10-15 08:48:51 +000061
Chris Lattner21190d52009-09-21 03:09:59 +000062 // No warning about falling off the end of a noreturn function.
63}
Chris Lattner21fb98e2009-09-23 06:06:36 +000064
65void test11(int X) {
Gabor Greif2fb985b2010-10-15 08:48:51 +000066 switch (X) {
Chris Lattner21fb98e2009-09-23 06:06:36 +000067 case __builtin_eh_return_data_regno(0): // constant foldable.
68 break;
69 }
70
Eric Christopher5e896552010-04-19 18:23:02 +000071 __builtin_eh_return_data_regno(X); // expected-error {{argument to '__builtin_eh_return_data_regno' must be a constant integer}}
Chris Lattner21fb98e2009-09-23 06:06:36 +000072}
73
Chris Lattner50dd2552009-09-26 21:16:00 +000074// PR5062
75void test12(void) __attribute__((__noreturn__));
76void test12(void) {
77 __builtin_trap(); // no warning because trap is noreturn.
78}
Douglas Gregor9a8c9a22009-09-28 21:14:19 +000079
80void test_unknown_builtin(int a, int b) {
Hans Wennborg122de3e2011-12-06 09:46:12 +000081 __builtin_isles(a, b); // expected-error{{use of unknown builtin}} \
82 // expected-note{{did you mean '__builtin_isless'?}}
Douglas Gregor9a8c9a22009-09-28 21:14:19 +000083}
Benjamin Kramerdee832c2010-07-26 22:04:15 +000084
85int test13() {
86 __builtin_eh_return(0, 0); // no warning, eh_return never returns.
87}
Douglas Gregorc46111e2010-07-28 18:42:27 +000088
89// <rdar://problem/8228293>
90void test14() {
91 int old;
92 old = __sync_fetch_and_min((volatile int *)&old, 1);
93}
Douglas Gregor1e32ca62010-08-25 15:47:31 +000094
95// <rdar://problem/8336581>
96void test15(const char *s) {
97 __builtin_printf("string is %s\n", s);
98}
Chris Lattner75c29a02010-10-12 17:47:42 +000099
100// PR7885
101int test16() {
102 return __builtin_constant_p() + // expected-error{{too few arguments}}
103 __builtin_constant_p(1, 2); // expected-error {{too many arguments}}
104}