builtins.c revision 691ebc3f3225542e5abd85e107ebdbec907cf510
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
3
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
27void test7() {
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}}
33}
34
35
36// atomics.
37
38void test9(short v) {
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}}
43  old = __sync_fetch_and_add((int**)0, 42i); // expected-warning {{imaginary constants are an extension}}
44}
45
46
47// rdar://7236819
48void test10(void) __attribute__((noreturn));
49
50void test10(void) {
51  __asm__("int3");
52  __builtin_unreachable();
53
54  // No warning about falling off the end of a noreturn function.
55}
56
57void test11(int X) {
58  switch (X) {
59  case __builtin_eh_return_data_regno(0):  // constant foldable.
60    break;
61  }
62
63  __builtin_eh_return_data_regno(X);  // expected-error {{argument 0 to '__builtin_eh_return_data_regno' must be a constant integer}}
64}
65
66// PR5062
67void test12(void) __attribute__((__noreturn__));
68void test12(void) {
69  __builtin_trap();  // no warning because trap is noreturn.
70}
71
72void test_unknown_builtin(int a, int b) {
73  __builtin_foo(a, b); // expected-error{{use of unknown builtin}}
74}
75