Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -triple=i686-apple-darwin9 |
Eli Friedman | 1435202 | 2008-05-25 04:43:38 +0000 | [diff] [blame] | 2 | // This test needs to set the target because it uses __builtin_ia32_vec_ext_v4si |
Chris Lattner | 1b9a079 | 2007-12-20 00:26:33 +0000 | [diff] [blame] | 3 | |
| 4 | int test1(float a, int b) { |
| 5 | return __builtin_isless(a, b); |
| 6 | } |
| 7 | int test2(int a, int b) { |
| 8 | return __builtin_islessequal(a, b); // expected-error {{floating point type}} |
| 9 | } |
| 10 | |
| 11 | int test3(double a, float b) { |
| 12 | return __builtin_isless(a, b); |
| 13 | } |
| 14 | int test4(int* a, double b) { |
| 15 | return __builtin_islessequal(a, b); // expected-error {{floating point type}} |
| 16 | } |
| 17 | |
| 18 | int test5(float a, long double b) { |
| 19 | return __builtin_isless(a, b, b); // expected-error {{too many arguments}} |
| 20 | } |
| 21 | int 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 Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 27 | void test7() { |
Chris Lattner | 634785c | 2009-12-30 22:10:22 +0000 | [diff] [blame] | 28 | const void *X; |
| 29 | X = CFSTR("\242"); |
| 30 | X = CFSTR("\0"); // expected-warning {{ CFString literal contains NUL character }} |
| 31 | 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 Lattner | 1b9a079 | 2007-12-20 00:26:33 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Chris Lattner | 95e2c71 | 2008-05-05 22:18:14 +0000 | [diff] [blame] | 35 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 36 | // atomics. |
| 37 | |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 38 | void test9(short v) { |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 39 | unsigned i, old; |
| 40 | |
| 41 | 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 Carruth | d201457 | 2010-07-09 18:59:35 +0000 | [diff] [blame] | 43 | 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); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 47 | } |
Chris Lattner | 21190d5 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 48 | |
| 49 | |
| 50 | // rdar://7236819 |
| 51 | void test10(void) __attribute__((noreturn)); |
| 52 | |
| 53 | void test10(void) { |
| 54 | __asm__("int3"); |
| 55 | __builtin_unreachable(); |
| 56 | |
| 57 | // No warning about falling off the end of a noreturn function. |
| 58 | } |
Chris Lattner | 21fb98e | 2009-09-23 06:06:36 +0000 | [diff] [blame] | 59 | |
| 60 | void test11(int X) { |
| 61 | switch (X) { |
| 62 | case __builtin_eh_return_data_regno(0): // constant foldable. |
| 63 | break; |
| 64 | } |
| 65 | |
Eric Christopher | 5e89655 | 2010-04-19 18:23:02 +0000 | [diff] [blame] | 66 | __builtin_eh_return_data_regno(X); // expected-error {{argument to '__builtin_eh_return_data_regno' must be a constant integer}} |
Chris Lattner | 21fb98e | 2009-09-23 06:06:36 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Chris Lattner | 50dd255 | 2009-09-26 21:16:00 +0000 | [diff] [blame] | 69 | // PR5062 |
| 70 | void test12(void) __attribute__((__noreturn__)); |
| 71 | void test12(void) { |
| 72 | __builtin_trap(); // no warning because trap is noreturn. |
| 73 | } |
Douglas Gregor | 9a8c9a2 | 2009-09-28 21:14:19 +0000 | [diff] [blame] | 74 | |
| 75 | void test_unknown_builtin(int a, int b) { |
| 76 | __builtin_foo(a, b); // expected-error{{use of unknown builtin}} |
| 77 | } |