blob: a23273740c789a520623e6e0b4b0616b5b522f60 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -triple=i686-apple-darwin9
Eli Friedmand042a962008-05-25 04:43:38 +00002// This test needs to set the target because it uses __builtin_ia32_vec_ext_v4si
Chris Lattner2da14fb2007-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 Lattnerdc046542009-05-08 06:58:22 +000027void test7() {
Mike Stump21c81fd2009-04-02 00:04:12 +000028 CFSTR("\242");
Chris Lattner2da14fb2007-12-20 00:26:33 +000029 CFSTR("\0"); // expected-warning {{ CFString literal contains NUL character }}
Chris Lattner940cfeb2008-01-04 18:22:42 +000030 CFSTR(242); // expected-error {{ CFString literal is not a string constant }} expected-warning {{incompatible integer to pointer conversion}}
Chris Lattnercedef8d2008-11-21 18:44:24 +000031 CFSTR("foo", "bar"); // expected-error {{too many arguments to function call}}
Chris Lattner2da14fb2007-12-20 00:26:33 +000032}
33
Chris Lattner4dd27102008-05-05 22:18:14 +000034
Chris Lattnerdc046542009-05-08 06:58:22 +000035// atomics.
36
Mike Stump753d1202009-07-22 00:43:08 +000037void test9(short v) {
Chris Lattnerdc046542009-05-08 06:58:22 +000038 unsigned i, old;
39
40 old = __sync_fetch_and_add(); // expected-error {{too few arguments to function call}}
41 old = __sync_fetch_and_add(&old); // expected-error {{too few arguments to function call}}
Chris Lattner5b9241b2009-05-08 15:36:58 +000042 old = __sync_fetch_and_add((int**)0, 42i); // expected-warning {{imaginary constants are an extension}}
Chris Lattnerdc046542009-05-08 06:58:22 +000043}
Chris Lattnerbf206382009-09-21 03:09:59 +000044
45
46// rdar://7236819
47void test10(void) __attribute__((noreturn));
48
49void test10(void) {
50 __asm__("int3");
51 __builtin_unreachable();
52
53 // No warning about falling off the end of a noreturn function.
54}
Chris Lattnerd545ad12009-09-23 06:06:36 +000055
56void test11(int X) {
57 switch (X) {
58 case __builtin_eh_return_data_regno(0): // constant foldable.
59 break;
60 }
61
62 __builtin_eh_return_data_regno(X); // expected-error {{not an integer constant expression}}
63}
64
Chris Lattnera26b4712009-09-26 21:16:00 +000065// PR5062
66void test12(void) __attribute__((__noreturn__));
67void test12(void) {
68 __builtin_trap(); // no warning because trap is noreturn.
69}
Douglas Gregor56fbc372009-09-28 21:14:19 +000070
71void test_unknown_builtin(int a, int b) {
72 __builtin_foo(a, b); // expected-error{{use of unknown builtin}}
73}