Driver: tweak handling of '--analyze' to invoke
[clang.git] / test / Sema / builtins.c
blob4072faa94b9f829d47af9e8184994c9a23edd685
1 // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -triple=i686-apple-darwin9
2 // This test needs to set the target because it uses __builtin_ia32_vec_ext_v4si
4 int test1(float a, int b) {
5 return __builtin_isless(a, b);
7 int test2(int a, int b) {
8 return __builtin_islessequal(a, b); // expected-error {{floating point type}}
11 int test3(double a, float b) {
12 return __builtin_isless(a, b);
14 int test4(int* a, double b) {
15 return __builtin_islessequal(a, b); // expected-error {{floating point type}}
18 int test5(float a, long double b) {
19 return __builtin_isless(a, b, b); // expected-error {{too many arguments}}
21 int test6(float a, long double b) {
22 return __builtin_islessequal(a); // expected-error {{too few arguments}}
26 #define CFSTR __builtin___CFStringMakeConstantString
27 void test7() {
28 const void *X;
29 X = CFSTR("\242"); // expected-warning {{input conversion stopped}}
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}}
36 // atomics.
38 void test9(short v) {
39 unsigned i, old;
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}}
43 old = __sync_fetch_and_add((unsigned*)0, 42i); // expected-warning {{imaginary constants are an extension}}
45 // PR7600: Pointers are implicitly casted to integers and back.
46 void *old_ptr = __sync_val_compare_and_swap((void**)0, 0, 0);
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) {
55 // rdar://7236819
56 void test10(void) __attribute__((noreturn));
58 void test10(void) {
59 __asm__("int3");
60 __builtin_unreachable();
62 // No warning about falling off the end of a noreturn function.
65 void test11(int X) {
66 switch (X) {
67 case __builtin_eh_return_data_regno(0): // constant foldable.
68 break;
71 __builtin_eh_return_data_regno(X); // expected-error {{argument to '__builtin_eh_return_data_regno' must be a constant integer}}
74 // PR5062
75 void test12(void) __attribute__((__noreturn__));
76 void test12(void) {
77 __builtin_trap(); // no warning because trap is noreturn.
80 void test_unknown_builtin(int a, int b) {
81 __builtin_foo(a, b); // expected-error{{use of unknown builtin}}
84 int test13() {
85 __builtin_eh_return(0, 0); // no warning, eh_return never returns.
88 // <rdar://problem/8228293>
89 void test14() {
90 int old;
91 old = __sync_fetch_and_min((volatile int *)&old, 1);
94 // <rdar://problem/8336581>
95 void test15(const char *s) {
96 __builtin_printf("string is %s\n", s);
99 // PR7885
100 int test16() {
101 return __builtin_constant_p() + // expected-error{{too few arguments}}
102 __builtin_constant_p(1, 2); // expected-error {{too many arguments}}