1 // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wno-string-plus-int -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
29 X = CFSTR("\242"); // expected-warning {{input conversion stopped}}
30 X = CFSTR("\0"); // no-warning
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}}
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) {
56 void test10(void) __attribute__((noreturn));
60 __builtin_unreachable();
62 // No warning about falling off the end of a noreturn function.
67 case __builtin_eh_return_data_regno(0): // constant foldable.
71 __builtin_eh_return_data_regno(X); // expected-error {{argument to '__builtin_eh_return_data_regno' must be a constant integer}}
75 void test12(void) __attribute__((__noreturn__));
77 __builtin_trap(); // no warning because trap is noreturn.
80 void test_unknown_builtin(int a, int b) {
81 __builtin_isles(a, b); // expected-error{{use of unknown builtin}} \
82 // expected-note{{did you mean '__builtin_isless'?}}
86 __builtin_eh_return(0, 0); // no warning, eh_return never returns.
89 // <rdar://problem/8228293>
92 old = __sync_fetch_and_min((volatile int *)&old, 1);
95 // <rdar://problem/8336581>
96 void test15(const char *s) {
97 __builtin_printf("string is %s\n", s);
102 return __builtin_constant_p() + // expected-error{{too few arguments}}
103 __builtin_constant_p(1, 2); // expected-error {{too many arguments}}
106 const int test17_n = 0;
107 const char test17_c[] = {1, 2, 3, 0};
108 const char test17_d[] = {1, 2, 3, 4};
109 typedef int __attribute__((vector_size(16))) IntVector;
110 struct Aggregate { int n; char c; };
111 enum Enum { EnumValue1, EnumValue2 };
113 typedef __typeof(sizeof(int)) size_t;
114 size_t strlen(const char *);
117 #define ASSERT(...) { int arr[(__VA_ARGS__) ? 1 : -1]; }
118 #define T(...) ASSERT(__builtin_constant_p(__VA_ARGS__))
119 #define F(...) ASSERT(!__builtin_constant_p(__VA_ARGS__))
121 // __builtin_constant_p returns 1 if the argument folds to:
122 // - an arithmetic constant with value which is known at compile time
124 T(&test17_c[3] - test17_c);
125 T(3i + 5); // expected-warning {{imaginary constant}}
128 T((enum Enum)(int)EnumValue2);
130 // - the address of the first character of a string literal, losslessly cast
133 T((double*)"string literal");
134 T("string literal" + 0);
135 T((long)"string literal");
137 // ... and otherwise returns 0.
138 F("string literal" + 1);
143 F((struct Aggregate){0, 1});
144 F((IntVector){0, 1, 2, 3});
146 // Ensure that a technique used in glibc is handled correctly.
147 #define OPT(...) (__builtin_constant_p(__VA_ARGS__) && strlen(__VA_ARGS__) < 4)
148 // FIXME: These are incorrectly treated as ICEs because strlen is treated as
151 ASSERT(!OPT("abcd"));
152 // In these cases, the strlen is non-constant, but the __builtin_constant_p
153 // is 0: the array size is not an ICE but is foldable.
154 ASSERT(!OPT(test17_c)); // expected-warning {{folded}}
155 ASSERT(!OPT(&test17_c[0])); // expected-warning {{folded}}
156 ASSERT(!OPT((char*)test17_c)); // expected-warning {{folded}}
157 ASSERT(!OPT(test17_d)); // expected-warning {{folded}}
158 ASSERT(!OPT(&test17_d[0])); // expected-warning {{folded}}
159 ASSERT(!OPT((char*)test17_d)); // expected-warning {{folded}}