2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -triple=i686-apple-darwin9
|
2008-05-25 12:43:38 +08:00
|
|
|
// This test needs to set the target because it uses __builtin_ia32_vec_ext_v4si
|
2007-12-20 08:26:33 +08:00
|
|
|
|
|
|
|
int test1(float a, int b) {
|
|
|
|
return __builtin_isless(a, b);
|
|
|
|
}
|
|
|
|
int test2(int a, int b) {
|
|
|
|
return __builtin_islessequal(a, b); // expected-error {{floating point type}}
|
|
|
|
}
|
|
|
|
|
|
|
|
int test3(double a, float b) {
|
|
|
|
return __builtin_isless(a, b);
|
|
|
|
}
|
|
|
|
int test4(int* a, double b) {
|
|
|
|
return __builtin_islessequal(a, b); // expected-error {{floating point type}}
|
|
|
|
}
|
|
|
|
|
|
|
|
int test5(float a, long double b) {
|
|
|
|
return __builtin_isless(a, b, b); // expected-error {{too many arguments}}
|
|
|
|
}
|
|
|
|
int test6(float a, long double b) {
|
|
|
|
return __builtin_islessequal(a); // expected-error {{too few arguments}}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define CFSTR __builtin___CFStringMakeConstantString
|
2009-05-08 14:58:22 +08:00
|
|
|
void test7() {
|
2009-12-31 06:10:22 +08:00
|
|
|
const void *X;
|
2010-09-08 03:38:13 +08:00
|
|
|
X = CFSTR("\242"); // expected-warning {{input conversion stopped}}
|
2011-03-16 05:18:52 +08:00
|
|
|
X = CFSTR("\0"); // no-warning
|
2009-12-31 06:10:22 +08:00
|
|
|
X = CFSTR(242); // expected-error {{ CFString literal is not a string constant }} expected-warning {{incompatible integer to pointer conversion}}
|
|
|
|
X = CFSTR("foo", "bar"); // expected-error {{too many arguments to function call}}
|
2007-12-20 08:26:33 +08:00
|
|
|
}
|
|
|
|
|
2008-05-06 06:18:14 +08:00
|
|
|
|
2009-05-08 14:58:22 +08:00
|
|
|
// atomics.
|
|
|
|
|
2009-07-22 08:43:08 +08:00
|
|
|
void test9(short v) {
|
2009-05-08 14:58:22 +08:00
|
|
|
unsigned i, old;
|
2010-10-15 16:48:51 +08:00
|
|
|
|
2009-05-08 14:58:22 +08:00
|
|
|
old = __sync_fetch_and_add(); // expected-error {{too few arguments to function call}}
|
|
|
|
old = __sync_fetch_and_add(&old); // expected-error {{too few arguments to function call}}
|
2010-07-10 02:59:35 +08:00
|
|
|
old = __sync_fetch_and_add((unsigned*)0, 42i); // expected-warning {{imaginary constants are an extension}}
|
|
|
|
|
|
|
|
// PR7600: Pointers are implicitly casted to integers and back.
|
|
|
|
void *old_ptr = __sync_val_compare_and_swap((void**)0, 0, 0);
|
2010-07-18 15:23:17 +08:00
|
|
|
|
|
|
|
// Ensure the return type is correct even when implicit casts are stripped
|
|
|
|
// away. This triggers an assertion while checking the comparison otherwise.
|
|
|
|
if (__sync_fetch_and_add(&old, 1) == 1) {
|
|
|
|
}
|
2009-05-08 14:58:22 +08:00
|
|
|
}
|
2009-09-21 11:09:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
// rdar://7236819
|
|
|
|
void test10(void) __attribute__((noreturn));
|
|
|
|
|
|
|
|
void test10(void) {
|
2010-10-15 16:48:51 +08:00
|
|
|
__asm__("int3");
|
2009-09-21 11:09:59 +08:00
|
|
|
__builtin_unreachable();
|
2010-10-15 16:48:51 +08:00
|
|
|
|
2009-09-21 11:09:59 +08:00
|
|
|
// No warning about falling off the end of a noreturn function.
|
|
|
|
}
|
2009-09-23 14:06:36 +08:00
|
|
|
|
|
|
|
void test11(int X) {
|
2010-10-15 16:48:51 +08:00
|
|
|
switch (X) {
|
2009-09-23 14:06:36 +08:00
|
|
|
case __builtin_eh_return_data_regno(0): // constant foldable.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-20 02:23:02 +08:00
|
|
|
__builtin_eh_return_data_regno(X); // expected-error {{argument to '__builtin_eh_return_data_regno' must be a constant integer}}
|
2009-09-23 14:06:36 +08:00
|
|
|
}
|
|
|
|
|
2009-09-27 05:16:00 +08:00
|
|
|
// PR5062
|
|
|
|
void test12(void) __attribute__((__noreturn__));
|
|
|
|
void test12(void) {
|
|
|
|
__builtin_trap(); // no warning because trap is noreturn.
|
|
|
|
}
|
2009-09-29 05:14:19 +08:00
|
|
|
|
|
|
|
void test_unknown_builtin(int a, int b) {
|
|
|
|
__builtin_foo(a, b); // expected-error{{use of unknown builtin}}
|
|
|
|
}
|
2010-07-27 06:04:15 +08:00
|
|
|
|
|
|
|
int test13() {
|
|
|
|
__builtin_eh_return(0, 0); // no warning, eh_return never returns.
|
|
|
|
}
|
2010-07-29 02:42:27 +08:00
|
|
|
|
|
|
|
// <rdar://problem/8228293>
|
|
|
|
void test14() {
|
|
|
|
int old;
|
|
|
|
old = __sync_fetch_and_min((volatile int *)&old, 1);
|
|
|
|
}
|
2010-08-25 23:47:31 +08:00
|
|
|
|
|
|
|
// <rdar://problem/8336581>
|
|
|
|
void test15(const char *s) {
|
|
|
|
__builtin_printf("string is %s\n", s);
|
|
|
|
}
|
2010-10-13 01:47:42 +08:00
|
|
|
|
|
|
|
// PR7885
|
|
|
|
int test16() {
|
|
|
|
return __builtin_constant_p() + // expected-error{{too few arguments}}
|
|
|
|
__builtin_constant_p(1, 2); // expected-error {{too many arguments}}
|
|
|
|
}
|
2010-10-15 16:48:51 +08:00
|
|
|
|