diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
| commit | 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 (patch) | |
| tree | 02a1ac369cb734d0abfa5000dd86e5b7797e6a74 /test/Sema | |
| parent | c7e70c433efc6953dc3888b9fbf9f3512d7da2b0 (diff) | |
Notes
Diffstat (limited to 'test/Sema')
78 files changed, 1509 insertions, 231 deletions
diff --git a/test/Sema/Inputs/pragma-pack1.h b/test/Sema/Inputs/pragma-pack1.h index abbf8a8609f1..3fd299e642a1 100644 --- a/test/Sema/Inputs/pragma-pack1.h +++ b/test/Sema/Inputs/pragma-pack1.h @@ -16,7 +16,7 @@ struct ReceivesPragma { }; #include "pragma-pack2.h" #ifdef SET_SECOND_HEADER -// expected-warning@-3 {{the current #pragma pack aligment value is modified in the included file}} +// expected-warning@-3 {{the current #pragma pack alignment value is modified in the included file}} #endif #ifdef PUSH_POP_FIRST_HEADER diff --git a/test/Sema/aarch64-vpcs.c b/test/Sema/aarch64-vpcs.c new file mode 100644 index 000000000000..93ad00324177 --- /dev/null +++ b/test/Sema/aarch64-vpcs.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple aarch64-linux-gnu -verify %s + +typedef __attribute__((aarch64_vector_pcs)) int invalid_typedef; // expected-warning {{'aarch64_vector_pcs' only applies to function types; type here is 'int'}} + +void __attribute__((aarch64_vector_pcs(0))) foo0(void); // expected-error {{'aarch64_vector_pcs' attribute takes no arguments}} + +void __attribute__((aarch64_vector_pcs, preserve_all)) foo1(void); // expected-error {{not compatible}} + +void __attribute__((cdecl)) foo2(void); // expected-note {{previous declaration is here}} +void __attribute__((aarch64_vector_pcs)) foo2(void) {} // expected-error {{function declared 'aarch64_vector_pcs' here was previously declared 'cdecl'}} + +void foo3(void); // expected-note {{previous declaration is here}} +void __attribute__((aarch64_vector_pcs)) foo3(void) {} // expected-error {{function declared 'aarch64_vector_pcs' here was previously declared without calling convention}} + +typedef int (*fn_ty)(void); +typedef int __attribute__((aarch64_vector_pcs)) (*aavpcs_fn_ty)(void); +void foo4(fn_ty ptr1, aavpcs_fn_ty ptr2) { + ptr1 = ptr2; // expected-warning {{incompatible function pointer types}} +} diff --git a/test/Sema/address_spaces.c b/test/Sema/address_spaces.c index 87707d7deb0d..a9046d86f18c 100644 --- a/test/Sema/address_spaces.c +++ b/test/Sema/address_spaces.c @@ -71,5 +71,19 @@ __attribute__((address_space("12"))) int *i; // expected-error {{'address_space' // Clang extension doesn't forbid operations on pointers to different address spaces. char* cmp(_AS1 char *x, _AS2 char *y) { - return x < y ? x : y; // expected-warning {{pointer type mismatch ('__attribute__((address_space(1))) char *' and '__attribute__((address_space(2))) char *')}} + return x < y ? x : y; // expected-error{{conditional operator with the second and third operands of type ('__attribute__((address_space(1))) char *' and '__attribute__((address_space(2))) char *') which are pointers to non-overlapping address spaces}} +} + +struct SomeStruct { + int a; + long b; + int c; +}; + +// Compound literals in function scope are lvalues with automatic storage duration, +// so they cannot realistically be qualified with an address space. +void as_compound_literal() { + (_AS1 struct SomeStruct){1, 2, 3}; // expected-error {{compound literal in function scope may not be qualified with an address space}} + (_AS1 char[]){"test"}; // expected-error {{compound literal in function scope may not be qualified with an address space}} + (_AS1 char[]){'a', 'b', 'c'}; // expected-error {{compound literal in function scope may not be qualified with an address space}} } diff --git a/test/Sema/alias-unused.c b/test/Sema/alias-unused.c new file mode 100644 index 000000000000..5cedc93c2974 --- /dev/null +++ b/test/Sema/alias-unused.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wunneeded-internal-declaration -x c -verify %s +// expected-no-diagnostics +static int f() { return 42; } +int g() __attribute__((alias("f"))); + +static int foo [] = { 42, 0xDEAD }; +extern typeof(foo) bar __attribute__((unused, alias("foo"))); diff --git a/test/Sema/align-x86-abi7.c b/test/Sema/align-x86-abi7.c new file mode 100644 index 000000000000..49ca66f69251 --- /dev/null +++ b/test/Sema/align-x86-abi7.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -std=c11 -triple i386-apple-darwin9 -fsyntax-only -verify -fclang-abi-compat=7 %s +// expected-no-diagnostics + +#define STATIC_ASSERT(cond) _Static_assert(cond, #cond) + +// PR3433 +#define CHECK_ALIGNMENT(type, name, pref) \ + type name; \ + STATIC_ASSERT(__alignof__(name) == pref); \ + STATIC_ASSERT(__alignof__(type) == pref); \ + STATIC_ASSERT(_Alignof(type) == pref) + +CHECK_ALIGNMENT(double, g_double, 8); +CHECK_ALIGNMENT(long long, g_longlong, 8); +CHECK_ALIGNMENT(unsigned long long, g_ulonglong, 8); + +typedef double arr3double[3]; +CHECK_ALIGNMENT(arr3double, g_arr3double, 8); + +enum big_enum { x = 18446744073709551615ULL }; +CHECK_ALIGNMENT(enum big_enum, g_bigenum, 8);
\ No newline at end of file diff --git a/test/Sema/align-x86.c b/test/Sema/align-x86.c index e3b8c704b858..519cbe66f181 100644 --- a/test/Sema/align-x86.c +++ b/test/Sema/align-x86.c @@ -1,34 +1,33 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c11 -triple i386-apple-darwin9 -fsyntax-only -verify %s // expected-no-diagnostics -// PR3433 -double g1; -short chk1[__alignof__(g1) == 8 ? 1 : -1]; -short chk2[__alignof__(double) == 8 ? 1 : -1]; - -long long g2; -short chk1[__alignof__(g2) == 8 ? 1 : -1]; -short chk2[__alignof__(long long) == 8 ? 1 : -1]; +#define STATIC_ASSERT(cond) _Static_assert(cond, #cond) -unsigned long long g5; -short chk1[__alignof__(g5) == 8 ? 1 : -1]; -short chk2[__alignof__(unsigned long long) == 8 ? 1 : -1]; +// PR3433 +#define CHECK_ALIGNMENT(type, name, abi, pref) \ + type name; \ + STATIC_ASSERT(__alignof__(name) == pref); \ + STATIC_ASSERT(__alignof__(type) == pref); \ + STATIC_ASSERT(_Alignof(type) == abi) -_Complex double g3; -short chk1[__alignof__(g3) == 8 ? 1 : -1]; -short chk2[__alignof__(_Complex double) == 8 ? 1 : -1]; +CHECK_ALIGNMENT(double, g_double, 4, 8); +CHECK_ALIGNMENT(long long, g_longlong, 4, 8); +CHECK_ALIGNMENT(unsigned long long, g_ulonglong, 4, 8); +CHECK_ALIGNMENT(_Complex double, g_complexdouble, 4, 8); // PR6362 -struct __attribute__((packed)) {unsigned int a;} g4; -short chk1[__alignof__(g4) == 1 ? 1 : -1]; -short chk2[__alignof__(g4.a) == 1 ? 1 : -1]; +struct __attribute__((packed)) +packed_struct { + unsigned int a; +}; +CHECK_ALIGNMENT(struct packed_struct, g_packedstruct, 1, 1); +STATIC_ASSERT(__alignof__(g_packedstruct.a) == 1); -double g6[3]; -short chk1[__alignof__(g6) == 8 ? 1 : -1]; -short chk2[__alignof__(double[3]) == 8 ? 1 : -1]; +typedef double arr3double[3]; +CHECK_ALIGNMENT(arr3double, g_arr3double, 4, 8); -enum { x = 18446744073709551615ULL } g7; -short chk1[__alignof__(g7) == 8 ? 1 : -1]; +enum big_enum { x = 18446744073709551615ULL }; +CHECK_ALIGNMENT(enum big_enum, g_bigenum, 4, 8); // PR5637 @@ -36,20 +35,20 @@ short chk1[__alignof__(g7) == 8 ? 1 : -1]; typedef ALIGNED(2) struct { char a[3]; -} T; +} aligned_before_struct; -short chk1[sizeof(T) == 3 ? 1 : -1]; -short chk2[sizeof(T[1]) == 4 ? 1 : -1]; -short chk3[sizeof(T[2]) == 6 ? 1 : -1]; -short chk4[sizeof(T[2][1]) == 8 ? 1 : -1]; -short chk5[sizeof(T[1][2]) == 6 ? 1 : -1]; +STATIC_ASSERT(sizeof(aligned_before_struct) == 3); +STATIC_ASSERT(sizeof(aligned_before_struct[1]) == 4); +STATIC_ASSERT(sizeof(aligned_before_struct[2]) == 6); +STATIC_ASSERT(sizeof(aligned_before_struct[2][1]) == 8); +STATIC_ASSERT(sizeof(aligned_before_struct[1][2]) == 6); typedef struct ALIGNED(2) { char a[3]; -} T2; +} aligned_after_struct; -short chk1[sizeof(T2) == 4 ? 1 : -1]; -short chk2[sizeof(T2[1]) == 4 ? 1 : -1]; -short chk3[sizeof(T2[2]) == 8 ? 1 : -1]; -short chk4[sizeof(T2[2][1]) == 8 ? 1 : -1]; -short chk5[sizeof(T2[1][2]) == 8 ? 1 : -1]; +STATIC_ASSERT(sizeof(aligned_after_struct) == 4); +STATIC_ASSERT(sizeof(aligned_after_struct[1]) == 4); +STATIC_ASSERT(sizeof(aligned_after_struct[2]) == 8); +STATIC_ASSERT(sizeof(aligned_after_struct[2][1]) == 8); +STATIC_ASSERT(sizeof(aligned_after_struct[1][2]) == 8); diff --git a/test/Sema/altivec-generic-overload.c b/test/Sema/altivec-generic-overload.c new file mode 100644 index 000000000000..7e0679c68794 --- /dev/null +++ b/test/Sema/altivec-generic-overload.c @@ -0,0 +1,100 @@ +// RUN: %clang_cc1 %s -triple=powerpc64le-unknown-linux -target-feature +altivec -target-feature +vsx -verify -verify-ignore-unexpected=note -pedantic -fsyntax-only + +typedef signed char __v16sc __attribute__((__vector_size__(16))); +typedef unsigned char __v16uc __attribute__((__vector_size__(16))); +typedef signed short __v8ss __attribute__((__vector_size__(16))); +typedef unsigned short __v8us __attribute__((__vector_size__(16))); +typedef signed int __v4si __attribute__((__vector_size__(16))); +typedef unsigned int __v4ui __attribute__((__vector_size__(16))); +typedef signed long long __v2sll __attribute__((__vector_size__(16))); +typedef unsigned long long __v2ull __attribute__((__vector_size__(16))); +typedef signed __int128 __v1slll __attribute__((__vector_size__(16))); +typedef unsigned __int128 __v1ulll __attribute__((__vector_size__(16))); +typedef float __v4f __attribute__((__vector_size__(16))); +typedef double __v2d __attribute__((__vector_size__(16))); + +__v16sc *__attribute__((__overloadable__)) convert1(vector signed char); +__v16uc *__attribute__((__overloadable__)) convert1(vector unsigned char); +__v8ss *__attribute__((__overloadable__)) convert1(vector signed short); +__v8us *__attribute__((__overloadable__)) convert1(vector unsigned short); +__v4si *__attribute__((__overloadable__)) convert1(vector signed int); +__v4ui *__attribute__((__overloadable__)) convert1(vector unsigned int); +__v2sll *__attribute__((__overloadable__)) convert1(vector signed long long); +__v2ull *__attribute__((__overloadable__)) convert1(vector unsigned long long); +__v1slll *__attribute__((__overloadable__)) convert1(vector signed __int128); +__v1ulll *__attribute__((__overloadable__)) convert1(vector unsigned __int128); +__v4f *__attribute__((__overloadable__)) convert1(vector float); +__v2d *__attribute__((__overloadable__)) convert1(vector double); +void __attribute__((__overloadable__)) convert1(vector bool int); +void __attribute__((__overloadable__)) convert1(vector pixel short); + +vector signed char *__attribute__((__overloadable__)) convert2(__v16sc); +vector unsigned char *__attribute__((__overloadable__)) convert2(__v16uc); +vector signed short *__attribute__((__overloadable__)) convert2(__v8ss); +vector unsigned short *__attribute__((__overloadable__)) convert2(__v8us); +vector signed int *__attribute__((__overloadable__)) convert2(__v4si); +vector unsigned int *__attribute__((__overloadable__)) convert2(__v4ui); +vector signed long long *__attribute__((__overloadable__)) convert2(__v2sll); +vector unsigned long long *__attribute__((__overloadable__)) convert2(__v2ull); +vector signed __int128 *__attribute__((__overloadable__)) convert2(__v1slll); +vector unsigned __int128 *__attribute__((__overloadable__)) convert2(__v1ulll); +vector float *__attribute__((__overloadable__)) convert2(__v4f); +vector double *__attribute__((__overloadable__)) convert2(__v2d); + +void test() { + __v16sc gv1; + __v16uc gv2; + __v8ss gv3; + __v8us gv4; + __v4si gv5; + __v4ui gv6; + __v2sll gv7; + __v2ull gv8; + __v1slll gv9; + __v1ulll gv10; + __v4f gv11; + __v2d gv12; + + vector signed char av1; + vector unsigned char av2; + vector signed short av3; + vector unsigned short av4; + vector signed int av5; + vector unsigned int av6; + vector signed long long av7; + vector unsigned long long av8; + vector signed __int128 av9; + vector unsigned __int128 av10; + vector float av11; + vector double av12; + vector bool int av13; + vector pixel short av14; + + __v16sc *gv1_p = convert1(gv1); + __v16uc *gv2_p = convert1(gv2); + __v8ss *gv3_p = convert1(gv3); + __v8us *gv4_p = convert1(gv4); + __v4si *gv5_p = convert1(gv5); + __v4ui *gv6_p = convert1(gv6); + __v2sll *gv7_p = convert1(gv7); + __v2ull *gv8_p = convert1(gv8); + __v1slll *gv9_p = convert1(gv9); + __v1ulll *gv10_p = convert1(gv10); + __v4f *gv11_p = convert1(gv11); + __v2d *gv12_p = convert1(gv12); + + vector signed char *av1_p = convert2(av1); + vector unsigned char *av2_p = convert2(av2); + vector signed short *av3_p = convert2(av3); + vector unsigned short *av4_p = convert2(av4); + vector signed int *av5_p = convert2(av5); + vector unsigned int *av6_p = convert2(av6); + vector signed long long *av7_p = convert2(av7); + vector unsigned long long *av8_p = convert2(av8); + vector signed __int128 *av9_p = convert2(av9); + vector unsigned __int128 *av10_p = convert2(av10); + vector float *av11_p = convert2(av11); + vector double *av12_p = convert2(av12); + convert2(av13); // expected-error {{call to 'convert2' is ambiguous}} + convert2(av14); // expected-error {{call to 'convert2' is ambiguous}} +} diff --git a/test/Sema/arm-no-fp16.c b/test/Sema/arm-no-fp16.c index 2a23270e92d8..91c48483f295 100644 --- a/test/Sema/arm-no-fp16.c +++ b/test/Sema/arm-no-fp16.c @@ -83,3 +83,213 @@ float16x4_t test_vminnm_f16(float16x4_t a, float16x4_t b) { float16x8_t test_vminnmq_f16(float16x8_t a, float16x8_t b) { return vminnmq_f16(a, b); // expected-warning{{implicit declaration of function 'vminnmq_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8_t'}} } + +float16x4_t test_vld1_f16(const float16_t *a) { + return vld1_f16(a); // expected-warning{{implicit declaration of function 'vld1_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4_t'}} +} + +float16x8_t test_vld1q_f16(const float16_t *a) { + return vld1q_f16(a); // expected-warning{{implicit declaration of function 'vld1q_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8_t'}} +} + +float16x4_t test_vld1_dup_f16(const float16_t *a) { + return vld1_dup_f16(a); // expected-warning{{implicit declaration of function 'vld1_dup_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4_t'}} +} + +float16x8_t test_vld1q_dup_f16(const float16_t *a) { + return vld1q_dup_f16(a); // expected-warning{{implicit declaration of function 'vld1q_dup_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8_t'}} +} + +float16x4_t test_vld1_lane_f16(const float16_t *a, float16x4_t b) { + return vld1_lane_f16(a, b, 3); // expected-warning{{implicit declaration of function 'vld1_lane_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4_t'}} +} + +float16x8_t test_vld1q_lane_f16(const float16_t *a, float16x8_t b) { + return vld1q_lane_f16(a, b, 7); // expected-warning{{implicit declaration of function 'vld1q_lane_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8_t'}} +} + +float16x4x2_t test_vld1_f16_x2(const float16_t *a) { + return vld1_f16_x2(a); // expected-warning{{implicit declaration of function 'vld1_f16_x2'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x2_t'}} +} + +float16x8x2_t test_vld1q_f16_x2(const float16_t *a) { + return vld1q_f16_x2(a); // expected-warning{{implicit declaration of function 'vld1q_f16_x2'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x2_t'}} +} + +float16x4x3_t test_vld1_f16_x3(const float16_t *a) { + return vld1_f16_x3(a); // expected-warning{{implicit declaration of function 'vld1_f16_x3'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x3_t'}} +} + +float16x8x3_t test_vld1q_f16_x3(const float16_t *a) { + return vld1q_f16_x3(a); // expected-warning{{implicit declaration of function 'vld1q_f16_x3'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x3_t'}} +} + +float16x4x4_t test_vld1_f16_x4(const float16_t *a) { + return vld1_f16_x4(a); // expected-warning{{implicit declaration of function 'vld1_f16_x4'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x4_t'}} +} + +float16x8x4_t test_vld1q_f16_x4(const float16_t *a) { + return vld1q_f16_x4(a); // expected-warning{{implicit declaration of function 'vld1q_f16_x4'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x4_t'}} +} + +float16x4x2_t test_vld2_f16(const float16_t *a) { + return vld2_f16(a); // expected-warning{{implicit declaration of function 'vld2_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x2_t'}} +} + +float16x8x2_t test_vld2q_f16(const float16_t *a) { + return vld2q_f16(a); // expected-warning{{implicit declaration of function 'vld2q_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x2_t'}} +} + +float16x4x2_t test_vld2_lane_f16(const float16_t *a, float16x4x2_t b) { + return vld2_lane_f16(a, b, 3); // expected-warning{{implicit declaration of function 'vld2_lane_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x2_t'}} +} + +float16x8x2_t test_vld2q_lane_f16(const float16_t *a, float16x8x2_t b) { + return vld2q_lane_f16(a, b, 7); // expected-warning{{implicit declaration of function 'vld2q_lane_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x2_t'}} +} + +float16x4x2_t test_vld2_dup_f16(const float16_t *src) { + return vld2_dup_f16(src); // expected-warning{{implicit declaration of function 'vld2_dup_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x2_t'}} +} + +float16x8x2_t test_vld2q_dup_f16(const float16_t *src) { + return vld2q_dup_f16(src); // expected-warning{{implicit declaration of function 'vld2q_dup_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x2_t'}} +} + +float16x4x3_t test_vld3_f16(const float16_t *a) { + return vld3_f16(a); // expected-warning{{implicit declaration of function 'vld3_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x3_t'}} +} + +float16x8x3_t test_vld3q_f16(const float16_t *a) { + return vld3q_f16(a); // expected-warning{{implicit declaration of function 'vld3q_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x3_t'}} +} + +float16x4x3_t test_vld3_lane_f16(const float16_t *a, float16x4x3_t b) { + return vld3_lane_f16(a, b, 3); // expected-warning{{implicit declaration of function 'vld3_lane_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x3_t'}} +} + +float16x8x3_t test_vld3q_lane_f16(const float16_t *a, float16x8x3_t b) { + return vld3q_lane_f16(a, b, 7); // expected-warning{{implicit declaration of function 'vld3q_lane_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x3_t'}} +} + +float16x4x3_t test_vld3_dup_f16(const float16_t *src) { + return vld3_dup_f16(src); // expected-warning{{implicit declaration of function 'vld3_dup_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x3_t'}} +} + +float16x8x3_t test_vld3q_dup_f16(const float16_t *src) { + return vld3q_dup_f16(src); // expected-warning{{implicit declaration of function 'vld3q_dup_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x3_t'}} +} + +float16x4x4_t test_vld4_f16(const float16_t *a) { + return vld4_f16(a); // expected-warning{{implicit declaration of function 'vld4_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x4_t'}} +} + +float16x8x4_t test_vld4q_f16(const float16_t *a) { + return vld4q_f16(a); // expected-warning{{implicit declaration of function 'vld4q_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x4_t'}} +} + +float16x4x4_t test_vld4_lane_f16(const float16_t *a, float16x4x4_t b) { + return vld4_lane_f16(a, b, 3); // expected-warning{{implicit declaration of function 'vld4_lane_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x4_t'}} +} + +float16x8x4_t test_vld4q_lane_f16(const float16_t *a, float16x8x4_t b) { + return vld4q_lane_f16(a, b, 7); // expected-warning{{implicit declaration of function 'vld4q_lane_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x4_t'}} +} + +float16x4x4_t test_vld4_dup_f16(const float16_t *src) { + return vld4_dup_f16(src); // expected-warning{{implicit declaration of function 'vld4_dup_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4x4_t'}} +} + +float16x8x4_t test_vld4q_dup_f16(const float16_t *src) { + return vld4q_dup_f16(src); // expected-warning{{implicit declaration of function 'vld4q_dup_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x8x4_t'}} +} + +void test_vst1_f16(float16_t *a, float16x4_t b) { + vst1_f16(a, b); // expected-warning{{implicit declaration of function 'vst1_f16'}} +} + +// aarch64-neon-intrinsics.c:void test_vst1q_f16(float16_t *a, float16x8_t b) { +void test_vst1q_f16(float16_t *a, float16x8_t b) { + vst1q_f16(a, b); // expected-warning{{implicit declaration of function 'vst1q_f16'}} +} + +// aarch64-neon-ldst-one.c:void test_vst1_lane_f16(float16_t *a, float16x4_t b) { +void test_vst1_lane_f16(float16_t *a, float16x4_t b) { + vst1_lane_f16(a, b, 3); // expected-warning{{implicit declaration of function 'vst1_lane_f16'}} +} + +void test_vst1q_lane_f16(float16_t *a, float16x8_t b) { + vst1q_lane_f16(a, b, 7); // expected-warning{{implicit declaration of function 'vst1q_lane_f16'}} +} + +void test_vst1_f16_x2(float16_t *a, float16x4x2_t b) { + vst1_f16_x2(a, b); // expected-warning{{implicit declaration of function 'vst1_f16_x2'}} +} + +void test_vst1q_f16_x2(float16_t *a, float16x8x2_t b) { + vst1q_f16_x2(a, b); // expected-warning{{implicit declaration of function 'vst1q_f16_x2'}} +} + +void test_vst1_f16_x3(float16_t *a, float16x4x3_t b) { + vst1_f16_x3(a, b); // expected-warning{{implicit declaration of function 'vst1_f16_x3'}} +} + +void test_vst1q_f16_x3(float16_t *a, float16x8x3_t b) { + vst1q_f16_x3(a, b); // expected-warning{{implicit declaration of function 'vst1q_f16_x3'}} +} + +void test_vst1_f16_x4(float16_t *a, float16x4x4_t b) { + vst1_f16_x4(a, b); // expected-warning{{implicit declaration of function 'vst1_f16_x4'}} +} + +void test_vst1q_f16_x4(float16_t *a, float16x8x4_t b) { + vst1q_f16_x4(a, b); // expected-warning{{implicit declaration of function 'vst1q_f16_x4'}} +} + +void test_vst2_f16(float16_t *a, float16x4x2_t b) { + vst2_f16(a, b); // expected-warning{{implicit declaration of function 'vst2_f16'}} +} + +void test_vst2q_f16(float16_t *a, float16x8x2_t b) { + vst2q_f16(a, b); // expected-warning{{implicit declaration of function 'vst2q_f16'}} +} + +void test_vst2_lane_f16(float16_t *a, float16x4x2_t b) { + vst2_lane_f16(a, b, 3); // expected-warning{{implicit declaration of function 'vst2_lane_f16'}} +} + +void test_vst2q_lane_f16(float16_t *a, float16x8x2_t b) { + vst2q_lane_f16(a, b, 7); // expected-warning{{implicit declaration of function 'vst2q_lane_f16'}} +} + +void test_vst3_f16(float16_t *a, float16x4x3_t b) { + vst3_f16(a, b); // expected-warning{{implicit declaration of function 'vst3_f16'}} +} + +void test_vst3q_f16(float16_t *a, float16x8x3_t b) { + vst3q_f16(a, b); // expected-warning{{implicit declaration of function 'vst3q_f16'}} +} + +void test_vst3_lane_f16(float16_t *a, float16x4x3_t b) { + vst3_lane_f16(a, b, 3); // expected-warning{{implicit declaration of function 'vst3_lane_f16'}} +} + +void test_vst3q_lane_f16(float16_t *a, float16x8x3_t b) { + vst3q_lane_f16(a, b, 7); // expected-warning{{implicit declaration of function 'vst3q_lane_f16'}} +} + +void test_vst4_f16(float16_t *a, float16x4x4_t b) { + vst4_f16(a, b); // expected-warning{{implicit declaration of function 'vst4_f16'}} +} + +void test_vst4q_f16(float16_t *a, float16x8x4_t b) { + vst4q_f16(a, b); // expected-warning{{implicit declaration of function 'vst4q_f16'}} +} + +void test_vst4_lane_f16(float16_t *a, float16x4x4_t b) { + vst4_lane_f16(a, b, 3); // expected-warning{{implicit declaration of function 'vst4_lane_f16'}} +} + +void test_vst4q_lane_f16(float16_t *a, float16x8x4_t b) { + vst4q_lane_f16(a, b, 7); // expected-warning{{implicit declaration of function 'vst4q_lane_f16'}} +} diff --git a/test/Sema/assign.c b/test/Sema/assign.c index 28d7b9f3bbdf..4d305aca4b5a 100644 --- a/test/Sema/assign.c +++ b/test/Sema/assign.c @@ -59,3 +59,37 @@ void testK1_(K k, J j) { void testK2_(K k, I i) { k.j->i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}} } + +// PR39946: Recursive checking of hasConstFields caused stack overflow. +struct L { // expected-note {{definition of 'struct L' is not complete until the closing '}'}} + struct L field; // expected-error {{field has incomplete type 'struct L'}} +}; +void testL(struct L *l) { + *l = 0; // expected-error {{assigning to 'struct L' from incompatible type 'int'}} +} + +// Additionally, this example overflowed the stack when figuring out the field. +struct M1; // expected-note {{forward declaration of 'struct M1'}} +struct M2 { + //expected-note@+1 {{nested data member 'field' declared const here}} + const struct M1 field; // expected-error {{field has incomplete type 'const struct M1'}} +}; +struct M1 { + struct M2 field; +}; + +void testM(struct M1 *l) { + *l = 0; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'field'}} +} + +struct N1; // expected-note {{forward declaration of 'struct N1'}} +struct N2 { + struct N1 field; // expected-error {{field has incomplete type 'struct N1'}} +}; +struct N1 { + struct N2 field; +}; + +void testN(struct N1 *l) { + *l = 0; // expected-error {{assigning to 'struct N1' from incompatible type 'int'}} +} diff --git a/test/Sema/atomic-implicit-seq_cst.c b/test/Sema/atomic-implicit-seq_cst.c new file mode 100644 index 000000000000..fff7b2444906 --- /dev/null +++ b/test/Sema/atomic-implicit-seq_cst.c @@ -0,0 +1,325 @@ +// RUN: %clang_cc1 %s -verify -ffreestanding -fsyntax-only -triple=i686-linux-gnu -std=c11 -Watomic-implicit-seq-cst + +// _Atomic operations are implicitly sequentially-consistent. Some codebases +// want to force explicit usage of memory order instead. + +_Atomic(int) atom; +void gimme_int(int); + +void bad_pre_inc(void) { + ++atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_pre_dec(void) { + --atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_post_inc(void) { + atom++; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_post_dec(void) { + atom--; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_call(void) { + gimme_int(atom); // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_unary_plus(void) { + return +atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_unary_minus(void) { + return -atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_unary_logical_not(void) { + return !atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_unary_bitwise_not(void) { + return ~atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_explicit_cast(void) { + return (int)atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_implicit_cast(void) { + return atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_mul_1(int i) { + return atom * i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_mul_2(int i) { + return i * atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_div_1(int i) { + return atom / i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_div_2(int i) { + return i / atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_mod_1(int i) { + return atom % i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_mod_2(int i) { + return i % atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_add_1(int i) { + return atom + i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_add_2(int i) { + return i + atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_sub_1(int i) { + return atom - i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_sub_2(int i) { + return i - atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_shl_1(int i) { + return atom << i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_shl_2(int i) { + return i << atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_shr_1(int i) { + return atom >> i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_shr_2(int i) { + return i >> atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_lt_1(int i) { + return atom < i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_lt_2(int i) { + return i < atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_le_1(int i) { + return atom <= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_le_2(int i) { + return i <= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_gt_1(int i) { + return atom > i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_gt_2(int i) { + return i > atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_ge_1(int i) { + return atom >= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_ge_2(int i) { + return i >= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_eq_1(int i) { + return atom == i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_eq_2(int i) { + return i == atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_ne_1(int i) { + return atom != i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_ne_2(int i) { + return i != atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_bitand_1(int i) { + return atom & i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_bitand_2(int i) { + return i & atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_bitxor_1(int i) { + return atom ^ i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_bitxor_2(int i) { + return i ^ atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_bitor_1(int i) { + return atom | i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_bitor_2(int i) { + return i | atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_and_1(int i) { + return atom && i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_and_2(int i) { + return i && atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_or_1(int i) { + return atom || i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_or_2(int i) { + return i || atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} +int bad_ternary_1(int i, int j) { + return i ? atom : j; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_ternary_2(int i, int j) { + return atom ? i : j; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_ternary_3(int i, int j) { + return i ? j : atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_assign_1(int i) { + atom = i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_assign_2(int *i) { + *i = atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_assign_3() { + atom = atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_add_1(int i) { + atom += i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_add_2(int *i) { + *i += atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_sub_1(int i) { + atom -= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_sub_2(int *i) { + *i -= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_mul_1(int i) { + atom *= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_mul_2(int *i) { + *i *= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_div_1(int i) { + atom /= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_div_2(int *i) { + *i /= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_mod_1(int i) { + atom %= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_mod_2(int *i) { + *i %= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_shl_1(int i) { + atom <<= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_shl_2(int *i) { + *i <<= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_shr_1(int i) { + atom >>= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_shr_2(int *i) { + *i >>= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_bitand_1(int i) { + atom &= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_bitand_2(int *i) { + *i &= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_bitxor_1(int i) { + atom ^= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_bitxor_2(int *i) { + *i ^= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_bitor_1(int i) { + atom |= i; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void bad_compound_bitor_2(int *i) { + *i |= atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +int bad_comma(int i) { + return (void)i, atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +} + +void good_c11_atomic_init(int i) { __c11_atomic_init(&atom, i); } +void good_c11_atomic_thread_fence(void) { __c11_atomic_thread_fence(__ATOMIC_RELAXED); } +void good_c11_atomic_signal_fence(void) { __c11_atomic_signal_fence(__ATOMIC_RELAXED); } +void good_c11_atomic_is_lock_free(void) { __c11_atomic_is_lock_free(sizeof(int)); } +void good_c11_atomic_store(int i) { __c11_atomic_store(&atom, i, __ATOMIC_RELAXED); } +int good_c11_atomic_load(void) { return __c11_atomic_load(&atom, __ATOMIC_RELAXED); } +int good_c11_atomic_exchange(int i) { return __c11_atomic_exchange(&atom, i, __ATOMIC_RELAXED); } +int good_c11_atomic_compare_exchange_strong(int *e, int i) { return __c11_atomic_compare_exchange_strong(&atom, e, i, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } +int good_c11_atomic_compare_exchange_weak(int *e, int i) { return __c11_atomic_compare_exchange_weak(&atom, e, i, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } +int good_c11_atomic_fetch_add(int i) { return __c11_atomic_fetch_add(&atom, i, __ATOMIC_RELAXED); } +int good_c11_atomic_fetch_sub(int i) { return __c11_atomic_fetch_sub(&atom, i, __ATOMIC_RELAXED); } +int good_c11_atomic_fetch_and(int i) { return __c11_atomic_fetch_and(&atom, i, __ATOMIC_RELAXED); } +int good_c11_atomic_fetch_or(int i) { return __c11_atomic_fetch_or(&atom, i, __ATOMIC_RELAXED); } +int good_c11_atomic_fetch_xor(int i) { return __c11_atomic_fetch_xor(&atom, i, __ATOMIC_RELAXED); } + +void good_cast_to_void(void) { (void)atom; } +_Atomic(int) * good_address_of(void) { return &atom; } +int good_sizeof(void) { return sizeof(atom); } +_Atomic(int) * good_pointer_arith(_Atomic(int) * p) { return p + 10; } +_Bool good_pointer_to_bool(_Atomic(int) * p) { return p; } +void good_no_init(void) { _Atomic(int) no_init; } +void good_init(void) { _Atomic(int) init = 42; } diff --git a/test/Sema/atomic-ops.c b/test/Sema/atomic-ops.c index 49310bf45b68..638c30f278ce 100644 --- a/test/Sema/atomic-ops.c +++ b/test/Sema/atomic-ops.c @@ -115,7 +115,7 @@ void f(_Atomic(int) *i, const _Atomic(int) *ci, __c11_atomic_load(i, memory_order_seq_cst); __c11_atomic_load(p, memory_order_seq_cst); __c11_atomic_load(d, memory_order_seq_cst); - __c11_atomic_load(ci, memory_order_seq_cst); // expected-error {{address argument to atomic operation must be a pointer to non-const _Atomic type ('const _Atomic(int) *' invalid)}} + __c11_atomic_load(ci, memory_order_seq_cst); int load_n_1 = __atomic_load_n(I, memory_order_relaxed); int *load_n_2 = __atomic_load_n(P, memory_order_relaxed); @@ -222,7 +222,7 @@ void f(_Atomic(int) *i, const _Atomic(int) *ci, __c11_atomic_init(ci, 0); // expected-error {{address argument to atomic operation must be a pointer to non-const _Atomic type ('const _Atomic(int) *' invalid)}} __c11_atomic_store(ci, 0, memory_order_release); // expected-error {{address argument to atomic operation must be a pointer to non-const _Atomic type ('const _Atomic(int) *' invalid)}} - __c11_atomic_load(ci, memory_order_acquire); // expected-error {{address argument to atomic operation must be a pointer to non-const _Atomic type ('const _Atomic(int) *' invalid)}} + __c11_atomic_load(ci, memory_order_acquire); // Ensure the <stdatomic.h> macros behave appropriately. atomic_int n = ATOMIC_VAR_INIT(123); diff --git a/test/Sema/attr-availability-ios.c b/test/Sema/attr-availability-ios.c index 3f901bb33cb5..f418c7dcfd5f 100644 --- a/test/Sema/attr-availability-ios.c +++ b/test/Sema/attr-availability-ios.c @@ -7,8 +7,8 @@ void f3(int) __attribute__((availability(ios,introduced=3.0))); void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(ios,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}} void f5(int) __attribute__((availability(ios,introduced=2.0))) __attribute__((availability(ios,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}} -void f6(int) __attribute__((availability(ios,deprecated=3.0))); -void f6(int) __attribute__((availability(iOS,introduced=2.0))); // expected-note {{'f6' has been explicitly marked deprecated here}} +void f6(int) __attribute__((availability(ios,deprecated=3.0))); // expected-note {{'f6' has been explicitly marked deprecated here}} +void f6(int) __attribute__((availability(iOS,introduced=2.0))); void test() { f0(0); // expected-warning{{'f0' is deprecated: first deprecated in iOS 2.1}} diff --git a/test/Sema/attr-availability-swift.c b/test/Sema/attr-availability-swift.c new file mode 100644 index 000000000000..d77094cb2163 --- /dev/null +++ b/test/Sema/attr-availability-swift.c @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -ast-dump %s | FileCheck %s +// + +#if !__has_feature(attribute_availability_with_message) +# error "Missing __has_feature" +#endif + +#if __has_feature(attribute_availability_swift) +# warning "okay" +// expected-warning@-1{{okay}} +#else +# error "Missing __has_feature" +#endif + +extern int noSwiftGlobal1 __attribute__((availability(swift, unavailable))); +// CHECK: AvailabilityAttr {{.*}}swift 0 0 0 Unavailable "" "" +extern int noSwiftGlobal1 __attribute__((availability(macosx, introduced=10.1))); // okay +// CHECK: AvailabilityAttr {{.*}}Inherited swift 0 0 0 Unavailable "" "" +// CHECK: AvailabilityAttr {{.*}}macos 10.1 0 0 "" "" +extern int noSwiftGlobal1 __attribute__((availability(swift, unavailable, message="and this one has a message"))); // okay +// CHECK: AvailabilityAttr {{.*}}Inherited macos 10.1 0 0 "" "" +// CHECK: AvailabilityAttr {{.*}}swift 0 0 0 Unavailable "and this one has a message" "" +extern int noSwiftGlobal2 __attribute__((availability(swift, introduced=5))); // expected-warning{{only 'unavailable' and 'deprecated' are supported for Swift availability}} +// CHECK: VarDecl +// CHECK-NOT: AvailabilityAttr +extern int noSwiftGlobal3 __attribute__((availability(swift, deprecated, message="t"))); +// CHECK: VarDecl +// CHECK: AvailabilityAttr {{.*}}swift 0 1 0 "t" "" diff --git a/test/Sema/attr-availability-tvos.c b/test/Sema/attr-availability-tvos.c index 68337e49ce44..b940a9ad3a99 100644 --- a/test/Sema/attr-availability-tvos.c +++ b/test/Sema/attr-availability-tvos.c @@ -7,8 +7,8 @@ void f3(int) __attribute__((availability(tvos,introduced=3.0))); void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}} void f5(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}} -void f6(int) __attribute__((availability(tvos,deprecated=3.0))); -void f6(int) __attribute__((availability(tvos,introduced=2.0))); // expected-note {{'f6' has been explicitly marked deprecated here}} +void f6(int) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f6' has been explicitly marked deprecated here}} +void f6(int) __attribute__((availability(tvos,introduced=2.0))); void test() { f0(0); // expected-warning{{'f0' is deprecated: first deprecated in tvOS 2.1}} @@ -27,10 +27,8 @@ void test_transcribed_availability() { f9(0); } -__attribute__((availability(ios,introduced=9_0,deprecated=9_0,message="" ))) // expected-note{{previous attribute is here}} \ - // expected-note{{previous attribute is here}} -__attribute__((availability(ios,introduced=7_0))) // expected-warning{{availability does not match previous declaration}} \ - // expected-warning{{availability does not match previous declaration}} +__attribute__((availability(ios,introduced=9_0,deprecated=9_0,message="" ))) // expected-warning 2{{availability does not match previous declaration}} +__attribute__((availability(ios,introduced=7_0))) // expected-note 2{{previous attribute is here}} void f10(int); // Test tvOS specific attributes. @@ -43,8 +41,8 @@ void f5_tvos(int) __attribute__((availability(tvos,introduced=2.0))) __attribute void f5_attr_reversed_tvos(int) __attribute__((availability(ios, deprecated=3.0))) __attribute__((availability(tvos,introduced=2.0))); void f5b_tvos(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5b_tvos' has been explicitly marked deprecated here}} void f5c_tvos(int) __attribute__((availability(ios,introduced=2.0))) __attribute__((availability(ios,deprecated=3.0))); // expected-note {{'f5c_tvos' has been explicitly marked deprecated here}} -void f6_tvos(int) __attribute__((availability(tvos,deprecated=3.0))); -void f6_tvos(int) __attribute__((availability(tvOS,introduced=2.0))); // expected-note {{'f6_tvos' has been explicitly marked deprecated here}} +void f6_tvos(int) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f6_tvos' has been explicitly marked deprecated here}} +void f6_tvos(int) __attribute__((availability(tvOS,introduced=2.0))); void test_tvos() { f0_tvos(0); // expected-warning{{'f0_tvos' is deprecated: first deprecated in tvOS 2.1}} diff --git a/test/Sema/attr-availability-watchos.c b/test/Sema/attr-availability-watchos.c index 59233986ee46..866efac6a04f 100644 --- a/test/Sema/attr-availability-watchos.c +++ b/test/Sema/attr-availability-watchos.c @@ -32,8 +32,8 @@ void f5_watchos(int) __attribute__((availability(watchos,introduced=2.0))) __att void f5_attr_reversed_watchos(int) __attribute__((availability(ios, deprecated=3.0))) __attribute__((availability(watchos,introduced=2.0))); void f5b_watchos(int) __attribute__((availability(watchos,introduced=2.0))) __attribute__((availability(watchos,deprecated=3.0))); // expected-note {{'f5b_watchos' has been explicitly marked deprecated here}} void f5c_watchos(int) __attribute__((availability(ios,introduced=2.0))) __attribute__((availability(ios,deprecated=3.0))); // expected-note {{'f5c_watchos' has been explicitly marked deprecated here}} -void f6_watchos(int) __attribute__((availability(watchos,deprecated=3.0))); -void f6_watchos(int) __attribute__((availability(watchOS,introduced=2.0))); // expected-note {{'f6_watchos' has been explicitly marked deprecated here}} +void f6_watchos(int) __attribute__((availability(watchos,deprecated=3.0))); // expected-note {{'f6_watchos' has been explicitly marked deprecated here}} +void f6_watchos(int) __attribute__((availability(watchOS,introduced=2.0))); void test_watchos() { f0_watchos(0); // expected-warning{{'f0_watchos' is deprecated: first deprecated in watchOS 2.1}} diff --git a/test/Sema/attr-availability.c b/test/Sema/attr-availability.c index 1b8cbd256ce9..dbdf6593c3f7 100644 --- a/test/Sema/attr-availability.c +++ b/test/Sema/attr-availability.c @@ -16,13 +16,13 @@ extern void ATSFontGetPostScriptName(int flags) __attribute__((availability(macosx,introduced=8.0,obsoleted=9.0, message="use ATSFontGetFullPostScriptName"))); // expected-note {{'ATSFontGetPostScriptName' has been explicitly marked unavailable here}} #if defined(WARN_PARTIAL) -// expected-note@+3 {{has been explicitly marked partial here}} +// expected-note@+3 {{'PartiallyAvailable' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5.0}} #endif extern void PartiallyAvailable() __attribute__((availability(macosx,introduced=10.8))); #ifdef WARN_PARTIAL -// expected-note@+2 2 {{marked partial here}} +// expected-note@+2 2 {{'PartialEnum' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5.0}} #endif enum __attribute__((availability(macosx,introduced=10.8))) PartialEnum { kPartialEnumConstant, @@ -41,7 +41,7 @@ void test_10095131() { #ifdef WARN_PARTIAL // FIXME: This note should point to the declaration with the availability // attribute. -// expected-note@+2 {{marked partial here}} +// expected-note@+2 {{'PartiallyAvailable' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5.0}} #endif extern void PartiallyAvailable() ; void with_redeclaration() { @@ -64,8 +64,8 @@ enum { void f4(int) __attribute__((availability(ios,deprecated=3.0))); void f4(int) __attribute__((availability(ios,introduced=4.0))); // expected-warning {{feature cannot be deprecated in iOS version 3.0 before it was introduced in version 4.0; attribute ignored}} -void f5(int) __attribute__((availability(ios,deprecated=3.0), - availability(ios,introduced=4.0))); // expected-warning {{feature cannot be deprecated in iOS version 3.0 before it was introduced in version 4.0; attribute ignored}} +void f5(int) __attribute__((availability(ios,deprecated=3.0), // expected-warning {{feature cannot be deprecated in iOS version 3.0 before it was introduced in version 4.0; attribute ignored}} + availability(ios,introduced=4.0))); void f6(int) __attribute__((availability(ios,deprecated=3.0))); // expected-note {{previous attribute is here}} void f6(int) __attribute__((availability(ios,deprecated=4.0))); // expected-warning {{availability does not match previous declaration}} diff --git a/test/Sema/attr-capabilities.c b/test/Sema/attr-capabilities.c index 21cbae9e6090..8bfc4a506543 100644 --- a/test/Sema/attr-capabilities.c +++ b/test/Sema/attr-capabilities.c @@ -37,15 +37,25 @@ void Func6(void) __attribute__((requires_shared_capability(BadCapability))) {} void Func7(void) __attribute__((assert_capability(GUI))) {} void Func8(void) __attribute__((assert_shared_capability(GUI))) {} +void Func9(void) __attribute__((assert_capability())) {} // expected-warning {{'assert_capability' attribute without capability arguments can only be applied to non-static methods of a class}} +void Func10(void) __attribute__((assert_shared_capability())) {} // expected-warning {{'assert_shared_capability' attribute without capability arguments can only be applied to non-static methods of a class}} + void Func11(void) __attribute__((acquire_capability(GUI))) {} void Func12(void) __attribute__((acquire_shared_capability(GUI))) {} +void Func13(void) __attribute__((acquire_capability())) {} // expected-warning {{'acquire_capability' attribute without capability arguments can only be applied to non-static methods of a class}} +void Func14(void) __attribute__((acquire_shared_capability())) {} // expected-warning {{'acquire_shared_capability' attribute without capability arguments can only be applied to non-static methods of a class}} + void Func15(void) __attribute__((release_capability(GUI))) {} void Func16(void) __attribute__((release_shared_capability(GUI))) {} void Func17(void) __attribute__((release_generic_capability(GUI))) {} -void Func21(void) __attribute__((try_acquire_capability(1))) {} -void Func22(void) __attribute__((try_acquire_shared_capability(1))) {} +void Func18(void) __attribute__((release_capability())) {} // expected-warning {{'release_capability' attribute without capability arguments can only be applied to non-static methods of a class}} +void Func19(void) __attribute__((release_shared_capability())) {} // expected-warning {{'release_shared_capability' attribute without capability arguments can only be applied to non-static methods of a class}} +void Func20(void) __attribute__((release_generic_capability())) {} // expected-warning {{'release_generic_capability' attribute without capability arguments can only be applied to non-static methods of a class}} + +void Func21(void) __attribute__((try_acquire_capability(1))) {} // expected-warning {{'try_acquire_capability' attribute without capability arguments can only be applied to non-static methods of a class}} +void Func22(void) __attribute__((try_acquire_shared_capability(1))) {} // expected-warning {{'try_acquire_shared_capability' attribute without capability arguments can only be applied to non-static methods of a class}} void Func23(void) __attribute__((try_acquire_capability(1, GUI))) {} void Func24(void) __attribute__((try_acquire_shared_capability(1, GUI))) {} diff --git a/test/Sema/attr-coldhot.c b/test/Sema/attr-coldhot.c index 972f5a5266aa..a4b15822065c 100644 --- a/test/Sema/attr-coldhot.c +++ b/test/Sema/attr-coldhot.c @@ -6,7 +6,7 @@ int bar() __attribute__((__cold__)); int var1 __attribute__((__cold__)); // expected-warning{{'__cold__' attribute only applies to functions}} int var2 __attribute__((__hot__)); // expected-warning{{'__hot__' attribute only applies to functions}} -int qux() __attribute__((__hot__)) __attribute__((__cold__)); // expected-error{{'__hot__' and 'cold' attributes are not compatible}} \ +int qux() __attribute__((__hot__)) __attribute__((__cold__)); // expected-error{{'__cold__' and 'hot' attributes are not compatible}} \ // expected-note{{conflicting attribute is here}} -int baz() __attribute__((__cold__)) __attribute__((__hot__)); // expected-error{{'__cold__' and 'hot' attributes are not compatible}} \ +int baz() __attribute__((__cold__)) __attribute__((__hot__)); // expected-error{{'__hot__' and 'cold' attributes are not compatible}} \ // expected-note{{conflicting attribute is here}} diff --git a/test/Sema/attr-cpuspecific.c b/test/Sema/attr-cpuspecific.c index 91063c1c5b8a..e87ad4de7525 100644 --- a/test/Sema/attr-cpuspecific.c +++ b/test/Sema/attr-cpuspecific.c @@ -37,10 +37,16 @@ int __attribute__((cpu_dispatch(atom))) redecl2(void) { } // expected-note@-2 {{previous definition is here}} int __attribute__((cpu_dispatch(atom))) redecl2(void) { } -int redecl3(void); -// expected-error@-1 {{function declaration is missing 'cpu_specific' or 'cpu_dispatch' attribute in a multiversioned function}} -// expected-note@+1 {{function multiversioning caused by this declaration}} -int __attribute__((cpu_dispatch(atom))) redecl3(void) {} +int allow_fwd_decl(void); +int __attribute__((cpu_dispatch(atom))) allow_fwd_decl(void) {} + +int allow_fwd_decl2(void); +void use_fwd_decl(void) { + allow_fwd_decl2(); +} +// expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}} +int __attribute__((cpu_dispatch(atom))) allow_fwd_decl2(void) {} + int __attribute__((cpu_specific(atom))) redecl4(void); // expected-error@+1 {{function declaration is missing 'cpu_specific' or 'cpu_dispatch' attribute in a multiversioned function}} @@ -94,3 +100,15 @@ __vectorcall int __attribute__((cpu_specific(sandybridge))) diff_cc(void); int __attribute__((cpu_dispatch(atom))) disp_with_body(void) { return 5; } + +// expected-error@+1 {{invalid option 'INVALID'}} +int __attribute__((cpu_specific(INVALID))) called_invalid_value(void){ return 1;} +// expected-warning@+3 {{attribute declaration must precede definition}} +// expected-note@-2 2 {{previous definition is here}} +// expected-error@+1 {{redefinition of}} +int __attribute__((cpu_specific(pentium_iii))) called_invalid_value(void){ return 2;} +int __attribute__((cpu_specific(pentium_4))) called_invalid_value(void){ return 3;} + +int use3(void) { + return called_invalid_value(); +} diff --git a/test/Sema/attr-disable-tail-calls.c b/test/Sema/attr-disable-tail-calls.c index e8f5bcc73ee8..0545e951e60e 100644 --- a/test/Sema/attr-disable-tail-calls.c +++ b/test/Sema/attr-disable-tail-calls.c @@ -1,10 +1,10 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -void __attribute__((disable_tail_calls,naked)) foo1(int a) { // expected-error {{'disable_tail_calls' and 'naked' attributes are not compatible}} expected-note {{conflicting attribute is here}} +void __attribute__((disable_tail_calls,naked)) foo1(int a) { // expected-error {{'naked' and 'disable_tail_calls' attributes are not compatible}} expected-note {{conflicting attribute is here}} __asm__(""); } -void __attribute__((naked,disable_tail_calls)) foo2(int a) { // expected-error {{'naked' and 'disable_tail_calls' attributes are not compatible}} expected-note {{conflicting attribute is here}} +void __attribute__((naked,disable_tail_calls)) foo2(int a) { // expected-error {{'disable_tail_calls' and 'naked' attributes are not compatible}} expected-note {{conflicting attribute is here}} __asm__(""); } diff --git a/test/Sema/attr-ifunc.c b/test/Sema/attr-ifunc.c index af7a7e33da09..907b61c4451e 100644 --- a/test/Sema/attr-ifunc.c +++ b/test/Sema/attr-ifunc.c @@ -27,10 +27,6 @@ void f4_ifunc() {} void f4() __attribute__((ifunc("f4_ifunc"))); //expected-error@-1 {{ifunc resolver function must return a pointer}} -void* f5_ifunc(int i) { return 0; } -void f5() __attribute__((ifunc("f5_ifunc"))); -//expected-error@-1 {{ifunc resolver function must have no parameters}} - #else void f1a() __asm("f1"); void f1a() {} diff --git a/test/Sema/attr-long-call.c b/test/Sema/attr-long-call.c index cd3de1bf9e41..e80f8fdd52a7 100644 --- a/test/Sema/attr-long-call.c +++ b/test/Sema/attr-long-call.c @@ -19,8 +19,8 @@ __attribute((near)) void foo6(); __attribute((long_call, far)) void foo7(); __attribute((short_call, near)) void foo11(); -__attribute((far, near)) void foo8(); // expected-error {{'far' and 'near' attributes are not compatible}} \ +__attribute((far, near)) void foo8(); // expected-error {{'near' and 'far' attributes are not compatible}} \ // expected-note {{conflicting attribute is here}} -__attribute((short_call, long_call)) void foo12(); // expected-error {{'short_call' and 'long_call' attributes are not compatible}} \ +__attribute((short_call, long_call)) void foo12(); // expected-error {{'long_call' and 'short_call' attributes are not compatible}} \ // expected-note {{conflicting attribute is here}} diff --git a/test/Sema/attr-micromips.c b/test/Sema/attr-micromips.c index fe587fa3db07..27c9d3b54f6a 100644 --- a/test/Sema/attr-micromips.c +++ b/test/Sema/attr-micromips.c @@ -6,9 +6,9 @@ __attribute__((micromips(1))) void foo2(); // expected-error {{'micromips' at __attribute((nomicromips)) int a; // expected-error {{attribute only applies to functions}} __attribute((micromips)) int b; // expected-error {{attribute only applies to functions}} -__attribute__((micromips,mips16)) void foo5(); // expected-error {{'micromips' and 'mips16' attributes are not compatible}} \ +__attribute__((micromips,mips16)) void foo5(); // expected-error {{'mips16' and 'micromips' attributes are not compatible}} \ // expected-note {{conflicting attribute is here}} -__attribute__((mips16,micromips)) void foo6(); // expected-error {{'mips16' and 'micromips' attributes are not compatible}} \ +__attribute__((mips16,micromips)) void foo6(); // expected-error {{'micromips' and 'mips16' attributes are not compatible}} \ // expected-note {{conflicting attribute is here}} __attribute((micromips)) void foo7(); diff --git a/test/Sema/attr-notail.c b/test/Sema/attr-notail.c index 4d05fcf6f2c0..f65af47518d1 100644 --- a/test/Sema/attr-notail.c +++ b/test/Sema/attr-notail.c @@ -1,8 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -int callee0() __attribute__((not_tail_called,always_inline)); // expected-error{{'not_tail_called' and 'always_inline' attributes are not compatible}} \ +int callee0() __attribute__((not_tail_called,always_inline)); // expected-error{{'always_inline' and 'not_tail_called' attributes are not compatible}} \ // expected-note{{conflicting attribute is here}} -int callee1() __attribute__((always_inline,not_tail_called)); // expected-error{{'always_inline' and 'not_tail_called' attributes are not compatible}} \ +int callee1() __attribute__((always_inline,not_tail_called)); // expected-error{{'not_tail_called' and 'always_inline' attributes are not compatible}} \ // expected-note{{conflicting attribute is here}} int foo(int a) { diff --git a/test/Sema/attr-osobject.cpp b/test/Sema/attr-osobject.cpp new file mode 100644 index 000000000000..1659a82533be --- /dev/null +++ b/test/Sema/attr-osobject.cpp @@ -0,0 +1,74 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct S { + __attribute__((os_returns_retained)) S* method_returns_retained() { + return nullptr; + } + + __attribute__((os_consumes_this)) void method_consumes_this(); + + __attribute__((os_consumes_this)) static void rejected_on_static(); // expected-warning{{'os_consumes_this' attribute only applies to non-static member functions}} +}; +__attribute__((os_returns_retained)) S *ret_retained() { + return nullptr; +} + +__attribute__((os_returns_retained)) S ret_retained_value() { // expected-warning{{'os_returns_retained' attribute only applies to functions that return a pointer}} + return {}; +} + +__attribute__((os_returns_not_retained)) S *ret_not_retained() { + return nullptr; +} + +__attribute__((os_returns_not_retained)) S ret_not_retained_value() { // expected-warning{{'os_returns_not_retained' attribute only applies to functions that return a pointer}} + return {}; +} + +void accept_consumed_arg(__attribute__((os_consumed)) S *arg) {} + +void accept_consumed_arg_by_value(__attribute__((os_consumed)) S arg) {} // expected-warning{{os_consumed attribute only applies to pointer parameters}} + +void accept_consumed_arg_no_extra_arg(__attribute__((os_consumed(10))) S *arg) {} // expected-error{{'os_consumed' attribute takes no arguments}} + +struct __attribute__((os_consumed)) NoAttrOnStruct {}; // expected-warning{{'os_consumed' attribute only applies to parameters}} + +__attribute__((os_returns_retained(10))) S* returns_retained_no_extra_arg() { // expected-error{{'os_returns_retained' attribute takes no arguments}} + return nullptr; +} + +struct __attribute__((os_returns_retained)) NoRetainAttrOnStruct {}; // expected-warning{{'os_returns_retained' attribute only applies to functions, Objective-C methods, Objective-C properties, and parameters}} + +__attribute__((os_returns_not_retained(10))) S* os_returns_no_retained_no_extra_args( S *arg) { // expected-error{{'os_returns_not_retained' attribute takes no arguments}} + return nullptr; +} + +struct __attribute__((os_returns_not_retained)) NoNotRetainedAttrOnStruct {}; // expected-warning{{'os_returns_not_retained' attribute only applies to functions, Objective-C methods, Objective-C properties, and parameters}} + +__attribute__((os_consumes_this)) void no_consumes_this_on_function() {} // expected-warning{{'os_consumes_this' attribute only applies to non-static member functions}} + +void write_into_out_parameter(__attribute__((os_returns_retained)) S** out) {} + +bool write_into_out_parameter_on_nonzero(__attribute__((os_returns_retained_on_non_zero)) S** out) {} + +bool write_into_out_parameter_on_nonzero_invalid(__attribute__((os_returns_retained_on_non_zero)) S* out) {} // expected-warning{{'os_returns_retained_on_non_zero' attribute only applies to pointer/reference-to-OSObject-pointer parameters}} + +bool write_into_out_parameter_on_zero(__attribute__((os_returns_retained_on_zero)) S** out) {} + +bool write_into_out_parameter_on_zero_invalid(__attribute__((os_returns_retained_on_zero)) S* out) {} // expected-warning{{'os_returns_retained_on_zero' attribute only applies to pointer/reference-to-OSObject-pointer parameters}} + +void write_into_out_parameter_ref(__attribute__((os_returns_retained)) S*& out) {} + +typedef S* SPtr; + +void write_into_out_parameter_typedef(__attribute__((os_returns_retained)) SPtr* out) {} + +void write_into_out_parameter_invalid(__attribute__((os_returns_retained)) S* out) {} // expected-warning{{'os_returns_retained' attribute only applies to pointer/reference-to-OSObject-pointer parameters}} + +void write_into_out_parameter_not_retained(__attribute__((os_returns_not_retained)) S **out) {} + +void write_into_out_parameter_not_retained(__attribute__((os_returns_not_retained)) S volatile * const * const out) {} + +void write_into_not_retainedout_parameter_invalid(__attribute__((os_returns_not_retained)) S* out) {} // expected-warning{{'os_returns_not_retained' attribute only applies to pointer/reference-to-OSObject-pointer parameters}} + +void write_into_not_retainedout_parameter_too_many_pointers(__attribute__((os_returns_not_retained)) S*** out) {} // expected-warning{{'os_returns_not_retained' attribute only applies to pointer/reference-to-OSObject-pointer parameters}} diff --git a/test/Sema/attr-osobject.mm b/test/Sema/attr-osobject.mm new file mode 100644 index 000000000000..8b3aadff801c --- /dev/null +++ b/test/Sema/attr-osobject.mm @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s + +struct S {}; + +@interface I + @property (readonly) S* prop __attribute__((os_returns_retained)); + - (S*) generateS __attribute__((os_returns_retained)); + - (void) takeS:(S*) __attribute__((os_consumed)) s; +@end + +typedef __attribute__((os_returns_retained)) id (^blockType)(); // expected-warning{{'os_returns_retained' attribute only applies to functions, Objective-C methods, Objective-C properties, and parameters}} + +__auto_type b = ^ id (id filter) __attribute__((os_returns_retained)) { // expected-warning{{'os_returns_retained' attribute only applies to functions, Objective-C methods, Objective-C properties, and parameters}} + return filter; +}; diff --git a/test/Sema/attr-ownership.c b/test/Sema/attr-ownership.c index ff6c7197df8d..5ce758d9f4ad 100644 --- a/test/Sema/attr-ownership.c +++ b/test/Sema/attr-ownership.c @@ -16,11 +16,11 @@ void *f11(float i) __attribute__((ownership_returns(foo, 1))); // expected-erro void *f12(float i, int k, int f, int *j) __attribute__((ownership_returns(foo, 4))); // expected-error {{'ownership_returns' attribute only applies to integer arguments}} void f13(int *i, int *j) __attribute__((ownership_holds(foo, 1))) __attribute__((ownership_takes(foo, 2))); -void f14(int i, int j, int *k) __attribute__((ownership_holds(foo, 3))) __attribute__((ownership_takes(foo, 3))); // expected-error {{'ownership_holds' and 'ownership_takes' attributes are not compatible}} +void f14(int i, int j, int *k) __attribute__((ownership_holds(foo, 3))) __attribute__((ownership_takes(foo, 3))); // expected-error {{'ownership_takes' and 'ownership_holds' attributes are not compatible}} void f15(int, int) - __attribute__((ownership_returns(foo, 1))) // expected-note {{declared with index 1 here}} - __attribute__((ownership_returns(foo, 2))); // expected-error {{'ownership_returns' attribute index does not match; here it is 2}} + __attribute__((ownership_returns(foo, 1))) // expected-error {{'ownership_returns' attribute index does not match; here it is 1}} + __attribute__((ownership_returns(foo, 2))); // expected-note {{declared with index 2 here}} void f16(int *i, int *j) __attribute__((ownership_holds(foo, 1))) __attribute__((ownership_holds(foo, 1))); // OK, same index void f17(void*) __attribute__((ownership_takes(__, 1))); void f18() __attribute__((ownership_takes(foo, 1))); // expected-warning {{'ownership_takes' attribute only applies to non-K&R-style functions}} diff --git a/test/Sema/attr-ownership.cpp b/test/Sema/attr-ownership.cpp index cde195ff0aa8..7381285e2da4 100644 --- a/test/Sema/attr-ownership.cpp +++ b/test/Sema/attr-ownership.cpp @@ -2,6 +2,6 @@ class C { void f(int, int) - __attribute__((ownership_returns(foo, 2))) // expected-note {{declared with index 2 here}} - __attribute__((ownership_returns(foo, 3))); // expected-error {{'ownership_returns' attribute index does not match; here it is 3}} + __attribute__((ownership_returns(foo, 2))) // expected-error {{'ownership_returns' attribute index does not match; here it is 2}} + __attribute__((ownership_returns(foo, 3))); // expected-note {{declared with index 3 here}} }; diff --git a/test/Sema/attr-print.c b/test/Sema/attr-print.c index 16b440d5d73a..a326e1c58f48 100644 --- a/test/Sema/attr-print.c +++ b/test/Sema/attr-print.c @@ -22,15 +22,13 @@ int * __ptr32 p32; // CHECK: int * __ptr64 p64; int * __ptr64 p64; -// TODO: the Type Printer has no way to specify the order to print attributes -// in, and so it currently always prints them in reverse order. Fix this. -// CHECK: int * __ptr32 __uptr p32_2; +// CHECK: int * __uptr __ptr32 p32_2; int * __uptr __ptr32 p32_2; -// CHECK: int * __ptr64 __sptr p64_2; +// CHECK: int * __sptr __ptr64 p64_2; int * __sptr __ptr64 p64_2; -// CHECK: int * __ptr32 __uptr p32_3; +// CHECK: int * __uptr __ptr32 p32_3; int * __uptr __ptr32 p32_3; // CHECK: int * __sptr * __ptr32 ppsp32; diff --git a/test/Sema/attr-target-ast.c b/test/Sema/attr-target-ast.c deleted file mode 100644 index 6e8497ea9c8d..000000000000 --- a/test/Sema/attr-target-ast.c +++ /dev/null @@ -1,5 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-linux-gnu -ast-dump %s | FileCheck %s - -int __attribute__((target("arch=hiss,arch=woof"))) pine_tree() { return 4; } -// CHECK-NOT: arch=hiss -// CHECK-NOT: arch=woof diff --git a/test/Sema/attr-target-mv-bad-target.c b/test/Sema/attr-target-mv-bad-target.c index 9cf3c5e10a6b..4d61872b9075 100644 --- a/test/Sema/attr-target-mv-bad-target.c +++ b/test/Sema/attr-target-mv-bad-target.c @@ -1,4 +1,3 @@ -// RUN: %clang_cc1 -triple x86_64-windows-pc -fsyntax-only -verify %s // RUN: %clang_cc1 -triple arm-none-eabi -fsyntax-only -verify %s int __attribute__((target("sse4.2"))) redecl1(void) { return 1; } diff --git a/test/Sema/attr-target-mv.c b/test/Sema/attr-target-mv.c index 671adff5b042..664ade1c0fa5 100644 --- a/test/Sema/attr-target-mv.c +++ b/test/Sema/attr-target-mv.c @@ -65,10 +65,9 @@ int __attribute__((target("sse4.2,arch=sandybridge"))) mangle(void) { return 1; //expected-note@-2 {{previous declaration is here}} int __attribute__((target("arch=sandybridge,sse4.2"))) mangle(void) { return 2; } +// allow this, since we want to treat the 1st one as fwd-decl of the sandybridge version. int prev_no_target(void); int __attribute__((target("arch=sandybridge"))) prev_no_target(void) { return 2; } -// expected-error@-2 {{function declaration is missing 'target' attribute in a multiversioned function}} -// expected-note@+1 {{function multiversioning caused by this declaration}} int __attribute__((target("arch=ivybridge"))) prev_no_target(void) { return 2; } int __attribute__((target("arch=sandybridge"))) prev_no_target2(void); diff --git a/test/Sema/attr-uninitialized.c b/test/Sema/attr-uninitialized.c new file mode 100644 index 000000000000..44c7b4a54efc --- /dev/null +++ b/test/Sema/attr-uninitialized.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only + +void good() { + int dont_initialize_me __attribute((uninitialized)); +} + +void bad() { + int im_bad __attribute((uninitialized("zero"))); // expected-error {{'uninitialized' attribute takes no arguments}} + static int im_baaad __attribute((uninitialized)); // expected-warning {{'uninitialized' attribute only applies to local variables}} +} + +extern int come_on __attribute((uninitialized)); // expected-warning {{'uninitialized' attribute only applies to local variables}} +int you_know __attribute((uninitialized)); // expected-warning {{'uninitialized' attribute only applies to local variables}} +static int and_the_whole_world_has_to __attribute((uninitialized)); // expected-warning {{'uninitialized' attribute only applies to local variables}} + +void answer_right_now() __attribute((uninitialized)) {} // expected-warning {{'uninitialized' attribute only applies to local variables}} +void just_to_tell_you_once_again(__attribute((uninitialized)) int whos_bad) {} // expected-warning {{'uninitialized' attribute only applies to local variables}} + +struct TheWordIsOut { + __attribute((uninitialized)) int youre_doin_wrong; // expected-warning {{'uninitialized' attribute only applies to local variables}} +} __attribute((uninitialized)); // expected-warning {{'uninitialized' attribute only applies to local variables}} diff --git a/test/Sema/attr-visibility.c b/test/Sema/attr-visibility.c index ed52ec2743f9..798d6dcd78fc 100644 --- a/test/Sema/attr-visibility.c +++ b/test/Sema/attr-visibility.c @@ -15,8 +15,8 @@ struct test5; struct __attribute__((visibility("hidden"))) test5; // expected-note {{previous attribute is here}} struct __attribute__((visibility("default"))) test5; // expected-error {{visibility does not match previous declaration}} -void test6() __attribute__((visibility("hidden"), // expected-note {{previous attribute is here}} - visibility("default"))); // expected-error {{visibility does not match previous declaration}} +void test6() __attribute__((visibility("default"), // expected-error {{visibility does not match previous declaration}} + visibility("hidden"))); // expected-note {{previous attribute is here}} extern int test7 __attribute__((visibility("default"))); // expected-note {{previous attribute is here}} extern int test7 __attribute__((visibility("hidden"))); // expected-error {{visibility does not match previous declaration}} diff --git a/test/Sema/availability-guard-format.mm b/test/Sema/availability-guard-format.mm index 910de49ffc81..0e158c4173c2 100644 --- a/test/Sema/availability-guard-format.mm +++ b/test/Sema/availability-guard-format.mm @@ -1,9 +1,9 @@ -// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.11 -Wunguarded-availability -fdiagnostics-parseable-fixits -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.11 -Wunguarded-availability -fdiagnostics-parseable-fixits -fsyntax-only -verify %s // Testing that even for source code using '_' as a delimiter in availability version tuple '.' is actually used in diagnostic output as a delimiter. @interface foo -- (void) method_bar __attribute__((availability(macosx, introduced = 10_12))); // expected-note {{'method_bar' has been explicitly marked partial here}} +- (void) method_bar __attribute__((availability(macosx, introduced = 10_12))); // expected-note {{'method_bar' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.11.0}} @end int main() { diff --git a/test/Sema/builtin-object-size.c b/test/Sema/builtin-object-size.c index 436e99d9ab88..fcf86f3e344a 100644 --- a/test/Sema/builtin-object-size.c +++ b/test/Sema/builtin-object-size.c @@ -23,7 +23,7 @@ int f3() { // rdar://6252231 - cannot call vsnprintf with va_list on x86_64 void f4(const char *fmt, ...) { __builtin_va_list args; - __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); // expected-warning {{'__builtin___vsnprintf_chk' will always overflow destination buffer}} + __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); // expected-warning {{'__builtin___vsnprintf_chk' will always overflow; destination buffer has size 11, but size argument is 42}} } // rdar://18334276 @@ -50,7 +50,7 @@ void f6(void) char b[5]; char buf[10]; __builtin___memccpy_chk (buf, b, '\0', sizeof(b), __builtin_object_size (buf, 0)); - __builtin___memccpy_chk (b, buf, '\0', sizeof(buf), __builtin_object_size (b, 0)); // expected-warning {{'__builtin___memccpy_chk' will always overflow destination buffer}} + __builtin___memccpy_chk (b, buf, '\0', sizeof(buf), __builtin_object_size (b, 0)); // expected-warning {{'__builtin___memccpy_chk' will always overflow; destination buffer has size 5, but size argument is 10}} } int pr28314(void) { diff --git a/test/Sema/builtins-arm-strex-rettype.c b/test/Sema/builtins-arm-strex-rettype.c deleted file mode 100644 index 4ee96ce3277e..000000000000 --- a/test/Sema/builtins-arm-strex-rettype.c +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: %clang_cc1 -triple thumbv7m-apple-darwin-eabi -ast-dump %s | FileCheck %s - -// CHECK: CallExpr {{.*}} 'int' - -void foo(int a, int *b) { - do { - } while (__builtin_arm_strex(a, b)); -} diff --git a/test/Sema/builtins-microsoft-arm64.c b/test/Sema/builtins-microsoft-arm64.c new file mode 100644 index 000000000000..b72e7038954c --- /dev/null +++ b/test/Sema/builtins-microsoft-arm64.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple arm64-windows -fsyntax-only -verify \ +// RUN: -fms-compatibility -ffreestanding -fms-compatibility-version=17.00 %s + +#include <intrin.h> + +void check__getReg() { + __getReg(-1); // expected-error-re {{argument value {{.*}} is outside the valid range}} + __getReg(32); // expected-error-re {{argument value {{.*}} is outside the valid range}} +} + +void check_ReadWriteStatusReg(int v) { + int x; + _ReadStatusReg(x); // expected-error {{argument to '_ReadStatusReg' must be a constant integer}} + _WriteStatusReg(x, v); // expected-error {{argument to '_WriteStatusReg' must be a constant integer}} +} diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c index a831d030ef11..62992c0a47eb 100644 --- a/test/Sema/builtins.c +++ b/test/Sema/builtins.c @@ -122,6 +122,14 @@ int test16() { __builtin_constant_p(1, 2); // expected-error {{too many arguments}} } +// __builtin_constant_p cannot resolve non-constants as a file scoped array. +int expr; +char y[__builtin_constant_p(expr) ? -1 : 1]; // no warning, the builtin is false. + +// no warning, the builtin is false. +struct foo { int a; }; +struct foo x = (struct foo) { __builtin_constant_p(42) ? 37 : 927 }; + const int test17_n = 0; const char test17_c[] = {1, 2, 3, 0}; const char test17_d[] = {1, 2, 3, 4}; @@ -161,6 +169,7 @@ void test17() { F(&test17_d); F((struct Aggregate){0, 1}); F((IntVector){0, 1, 2, 3}); + F(test17); // Ensure that a technique used in glibc is handled correctly. #define OPT(...) (__builtin_constant_p(__VA_ARGS__) && strlen(__VA_ARGS__) < 4) @@ -221,14 +230,14 @@ void Test19(void) // expected-note {{change size argument to be the size of the destination}} __builtin___strlcpy_chk(buf, b, sizeof(b), __builtin_object_size(buf, 0)); // expected-warning {{size argument in '__builtin___strlcpy_chk' call appears to be size of the source; expected the size of the destination}} \ // expected-note {{change size argument to be the size of the destination}} \ - // expected-warning {{'__builtin___strlcpy_chk' will always overflow destination buffer}} + // expected-warning {{'__builtin___strlcpy_chk' will always overflow; destination buffer has size 20, but size argument is 40}} strlcat(buf, b, sizeof(b)); // expected-warning {{size argument in 'strlcat' call appears to be size of the source; expected the size of the destination}} \ // expected-note {{change size argument to be the size of the destination}} __builtin___strlcat_chk(buf, b, sizeof(b), __builtin_object_size(buf, 0)); // expected-warning {{size argument in '__builtin___strlcat_chk' call appears to be size of the source; expected the size of the destination}} \ // expected-note {{change size argument to be the size of the destination}} \ - // expected-warning {{'__builtin___strlcat_chk' will always overflow destination buffer}} + // expected-warning {{'__builtin___strlcat_chk' will always overflow; destination buffer has size 20, but size argument is 40}} } // rdar://11076881 @@ -236,7 +245,7 @@ char * Test20(char *p, const char *in, unsigned n) { static char buf[10]; - __builtin___memcpy_chk (&buf[6], in, 5, __builtin_object_size (&buf[6], 0)); // expected-warning {{'__builtin___memcpy_chk' will always overflow destination buffer}} + __builtin___memcpy_chk (&buf[6], in, 5, __builtin_object_size (&buf[6], 0)); // expected-warning {{'__builtin___memcpy_chk' will always overflow; destination buffer has size 4, but size argument is 5}} __builtin___memcpy_chk (p, "abcde", n, __builtin_object_size (p, 0)); @@ -244,11 +253,29 @@ char * Test20(char *p, const char *in, unsigned n) __builtin___memcpy_chk (&buf[5], "abcde", n, __builtin_object_size (&buf[5], 0)); - __builtin___memcpy_chk (&buf[6], "abcde", 5, __builtin_object_size (&buf[6], 0)); // expected-warning {{'__builtin___memcpy_chk' will always overflow destination buffer}} + __builtin___memcpy_chk (&buf[6], "abcde", 5, __builtin_object_size (&buf[6], 0)); // expected-warning {{'__builtin___memcpy_chk' will always overflow; destination buffer has size 4, but size argument is 5}} return buf; } +typedef void (fn_t)(int); + +void test_builtin_launder(char *p, void *vp, const void *cvp, + const volatile int *ip, float *restrict fp, + fn_t *fn) { + __builtin_launder(); // expected-error {{too few arguments to function call, expected 1, have 0}} + __builtin_launder(p, p); // expected-error {{too many arguments to function call, expected 1, have 2}} + int x; + __builtin_launder(x); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}} + char *d = __builtin_launder(p); + __builtin_launder(vp); // expected-error {{void pointer argument to '__builtin_launder' is not allowed}} + __builtin_launder(cvp); // expected-error {{void pointer argument to '__builtin_launder' is not allowed}} + const volatile int *id = __builtin_launder(ip); + int *id2 = __builtin_launder(ip); // expected-warning {{discards qualifiers}} + float *fd = __builtin_launder(fp); + __builtin_launder(fn); // expected-error {{function pointer argument to '__builtin_launder' is not allowed}} +} + void test21(const int *ptr) { __sync_fetch_and_add(ptr, 1); // expected-error{{address argument to atomic builtin cannot be const-qualified ('const int *' invalid)}} __atomic_fetch_add(ptr, 1, 0); // expected-error {{address argument to atomic operation must be a pointer to non-const type ('const int *' invalid)}} @@ -276,3 +303,14 @@ void test22(void) { (void)__builtin_signbitl(1.0f); (void)__builtin_signbitl(1.0L); } + +// rdar://43909200 +#define memcpy(x,y,z) __builtin___memcpy_chk(x,y,z, __builtin_object_size(x,0)) +#define my_memcpy(x,y,z) __builtin___memcpy_chk(x,y,z, __builtin_object_size(x,0)) + +void test23() { + char src[1024]; + char buf[10]; + memcpy(buf, src, 11); // expected-warning{{'memcpy' will always overflow; destination buffer has size 10, but size argument is 11}} + my_memcpy(buf, src, 11); // expected-warning{{'__builtin___memcpy_chk' will always overflow; destination buffer has size 10, but size argument is 11}} +} diff --git a/test/Sema/callingconv.c b/test/Sema/callingconv.c index c7a4821412cd..8b64bee0474f 100644 --- a/test/Sema/callingconv.c +++ b/test/Sema/callingconv.c @@ -51,6 +51,8 @@ int __attribute__((pcs("aapcs"))) pcs5(void); // expected-warning {{calling conv int __attribute__((pcs("aapcs-vfp"))) pcs6(void); // expected-warning {{calling convention 'pcs' ignored for this target}} int __attribute__((pcs("foo"))) pcs7(void); // expected-error {{invalid PCS type}} +int __attribute__((aarch64_vector_pcs)) aavpcs(void); // expected-warning {{calling convention 'aarch64_vector_pcs' ignored for this target}} + // PR6361 void ctest3(); void __attribute__((cdecl)) ctest3() {} diff --git a/test/Sema/conditional-expr.c b/test/Sema/conditional-expr.c index 5ff58a2ec476..6b24ef49b3e6 100644 --- a/test/Sema/conditional-expr.c +++ b/test/Sema/conditional-expr.c @@ -73,10 +73,10 @@ void foo() { int __attribute__((address_space(2))) *adr2; int __attribute__((address_space(3))) *adr3; - test0 ? adr2 : adr3; // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}} + test0 ? adr2 : adr3; // expected-error{{conditional operator with the second and third operands of type ('__attribute__((address_space(2))) int *' and '__attribute__((address_space(3))) int *') which are pointers to non-overlapping address spaces}} // Make sure address-space mask ends up in the result type - (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}} + (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-error{{conditional operator with the second and third operands of type ('__attribute__((address_space(2))) int *' and 'int *') which are pointers to non-overlapping address spaces}} } int Postgresql() { diff --git a/test/Sema/conditional.c b/test/Sema/conditional.c index 3d7bccaf9758..1f3a6d04f14d 100644 --- a/test/Sema/conditional.c +++ b/test/Sema/conditional.c @@ -12,3 +12,10 @@ int _php_stream_free1() { int _php_stream_free2() { return (1 ? _efree(0) : free(0)); // expected-error {{returning 'void' from a function with incompatible result type 'int'}} } + +void pr39809() { + _Generic(0 ? (int const *)0 : (void *)0, int const *: (void)0); + _Generic(0 ? (int const *)0 : (void *)1, void const *: (void)0); + _Generic(0 ? (int volatile*)0 : (void const*)1, void volatile const*: (void)0); + _Generic(0 ? (int volatile*)0 : (void const*)0, void volatile const*: (void)0); +} diff --git a/test/Sema/constant-builtins-2.c b/test/Sema/constant-builtins-2.c index 40cfce1f4a00..9bb5215b8dbd 100644 --- a/test/Sema/constant-builtins-2.c +++ b/test/Sema/constant-builtins-2.c @@ -176,6 +176,19 @@ char ffs4[__builtin_ffs(0xfbe70) == 5 ? 1 : -1]; char ffs5[__builtin_ffs(1U << (BITSIZE(int) - 1)) == BITSIZE(int) ? 1 : -1]; char ffs6[__builtin_ffsl(0x10L) == 5 ? 1 : -1]; char ffs7[__builtin_ffsll(0x100LL) == 9 ? 1 : -1]; + +char clrsb1[__builtin_clrsb(0) == BITSIZE(int) - 1 ? 1 : -1]; +char clrsb2[__builtin_clrsbl(0L) == BITSIZE(long) - 1 ? 1 : -1]; +char clrsb3[__builtin_clrsbll(0LL) == BITSIZE(long long) - 1 ? 1 : -1]; +char clrsb4[__builtin_clrsb(~0) == BITSIZE(int) - 1 ? 1 : -1]; +char clrsb5[__builtin_clrsbl(~0L) == BITSIZE(long) - 1 ? 1 : -1]; +char clrsb6[__builtin_clrsbll(~0LL) == BITSIZE(long long) - 1 ? 1 : -1]; +char clrsb7[__builtin_clrsb(1) == BITSIZE(int) - 2 ? 1 : -1]; +char clrsb8[__builtin_clrsb(~1) == BITSIZE(int) - 2 ? 1 : -1]; +char clrsb9[__builtin_clrsb(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1]; +char clrsb10[__builtin_clrsb(~(1 << (BITSIZE(int) - 1))) == 0 ? 1 : -1]; +char clrsb11[__builtin_clrsb(0xf) == BITSIZE(int) - 5 ? 1 : -1]; +char clrsb12[__builtin_clrsb(~0x1f) == BITSIZE(int) - 6 ? 1 : -1]; #undef BITSIZE // GCC misc stuff diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index aa591c9fa60d..07b22a8a6489 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -359,7 +359,7 @@ void f7676608(int); void test_7676608(void) { float q = 0.7f; char c = 5; - f7676608(c *= q); + f7676608(c *= q); // expected-warning {{conversion}} } // <rdar://problem/7904686> diff --git a/test/Sema/div-sizeof-ptr.cpp b/test/Sema/div-sizeof-ptr.cpp new file mode 100644 index 000000000000..4a411ff6bb09 --- /dev/null +++ b/test/Sema/div-sizeof-ptr.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 %s -verify -Wsizeof-pointer-div -fsyntax-only + +template <typename Ty, int N> +int f(Ty (&Array)[N]) { + return sizeof(Array) / sizeof(Ty); // Should not warn +} + +void test(int *p, int **q) { + int a1 = sizeof(p) / sizeof(*p); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} + int a2 = sizeof p / sizeof *p; // expected-warning {{'sizeof p' will return the size of the pointer, not the array itself}} + int a3 = sizeof(*q) / sizeof(**q); // expected-warning {{'sizeof (*q)' will return the size of the pointer, not the array itself}} + int a4 = sizeof(p) / sizeof(int); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} + int a5 = sizeof(p) / sizeof(p[0]); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} + + // Should not warn + int b1 = sizeof(int *) / sizeof(int); + int b2 = sizeof(p) / sizeof(p); + int b3 = sizeof(*q) / sizeof(q); + int b4 = sizeof(p) / sizeof(char); + + int arr[10]; + int b5 = sizeof(arr) / sizeof(*arr); + int b6 = sizeof(arr) / sizeof(arr[0]); + int b7 = sizeof(arr) / sizeof(int); + + int arr2[10][12]; + int b8 = sizeof(arr2) / sizeof(*arr2); +} diff --git a/test/Sema/enum.c b/test/Sema/enum.c index f9e40690c6a6..7681ebccd4fa 100644 --- a/test/Sema/enum.c +++ b/test/Sema/enum.c @@ -135,3 +135,26 @@ struct PR28903 { }; int makeStructNonEmpty; }; + +static int EnumRedecl; // expected-note 2 {{previous definition is here}} +struct S { + enum { + EnumRedecl = 4 // expected-error {{redefinition of 'EnumRedecl'}} + } e; +}; + +union U { + enum { + EnumRedecl = 5 // expected-error {{redefinition of 'EnumRedecl'}} + } e; +}; + +enum PR15071 { + PR15071_One // expected-note {{previous definition is here}} +}; + +struct EnumRedeclStruct { + enum { + PR15071_One // expected-error {{redefinition of enumerator 'PR15071_One'}} + } e; +}; diff --git a/test/Sema/ext-typecheck-comparison-of-pointer-integer.c b/test/Sema/ext-typecheck-comparison-of-pointer-integer.c new file mode 100644 index 000000000000..b928156aff28 --- /dev/null +++ b/test/Sema/ext-typecheck-comparison-of-pointer-integer.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify -DEXPECTWARNING %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify -Wno-pointer-integer-compare %s + +#ifdef EXPECTWARNING +// expected-warning@+6 {{comparison between pointer and integer ('int' and 'int *')}} +#else +// expected-no-diagnostics +#endif + +int test_ext_typecheck_comparison_of_pointer_integer(int integer, int * pointer) { + return integer != pointer; +} diff --git a/test/Sema/fixed-enum.c b/test/Sema/fixed-enum.c new file mode 100644 index 000000000000..60a4bc474f71 --- /dev/null +++ b/test/Sema/fixed-enum.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -Weverything -xc++ -std=c++11 -DCXX11 -verify %s +// RUN: %clang_cc1 -Weverything -xc++ -std=c++03 -DCXX03 -verify %s +// RUN: %clang_cc1 -Weverything -xobjective-c -DOBJC -verify %s +// RUN: %clang_cc1 -Weverything -std=c11 -xc -DC11 -verify %s +// RUN: %clang_cc1 -Weverything -std=c11 -xc -fms-extensions -DMS -verify %s + +enum X : int {e}; +#if defined(CXX11) +// expected-warning@-2{{enumeration types with a fixed underlying type are incompatible with C++98}} +#elif defined(CXX03) +// expected-warning@-4{{enumeration types with a fixed underlying type are a C++11 extension}} +#elif defined(OBJC) +// expected-no-diagnostics +#elif defined(C11) +// expected-warning@-8{{enumeration types with a fixed underlying type are a Clang extension}} +#elif defined(MS) +// expected-warning@-10{{enumeration types with a fixed underlying type are a Microsoft extension}} +#endif diff --git a/test/Sema/format-strings-bitfield-promotion.c b/test/Sema/format-strings-bitfield-promotion.c new file mode 100644 index 000000000000..cbe00e7510dd --- /dev/null +++ b/test/Sema/format-strings-bitfield-promotion.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only -verify %s + +int printf(const char *restrict, ...); + +struct bitfields { + long a : 2; + unsigned long b : 2; + long c : 32; // assumes that int is 32 bits + unsigned long d : 32; // assumes that int is 32 bits +} bf; + +void bitfield_promotion() { + printf("%ld", bf.a); // expected-warning {{format specifies type 'long' but the argument has type 'int'}} + printf("%lu", bf.b); // expected-warning {{format specifies type 'unsigned long' but the argument has type 'int'}} + printf("%ld", bf.c); // expected-warning {{format specifies type 'long' but the argument has type 'int'}} + printf("%lu", bf.d); // expected-warning {{format specifies type 'unsigned long' but the argument has type 'unsigned int'}} +} diff --git a/test/Sema/format-strings-bitfield-promotion.cxx b/test/Sema/format-strings-bitfield-promotion.cxx new file mode 100644 index 000000000000..2309e98066c6 --- /dev/null +++ b/test/Sema/format-strings-bitfield-promotion.cxx @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only -verify %s + +// In C++, the bitfield promotion from long to int does not occur, unlike C. +// expected-no-diagnostics + +int printf(const char *restrict, ...); + +struct bitfields { + long a : 2; + unsigned long b : 2; + long c : 32; // assumes that int is 32 bits + unsigned long d : 32; // assumes that int is 32 bits +} bf; + +void bitfield_promotion() { + printf("%ld", bf.a); + printf("%lu", bf.b); + printf("%ld", bf.c); + printf("%lu", bf.d); +} diff --git a/test/Sema/format-strings-ms.c b/test/Sema/format-strings-ms.c index 42676e7a4e06..56a349051d42 100644 --- a/test/Sema/format-strings-ms.c +++ b/test/Sema/format-strings-ms.c @@ -49,7 +49,7 @@ void w_test(wchar_t c, wchar_t *s) { scanf("%S", s); double bad; - printf("%wc", bad); // expected-warning{{format specifies type 'wint_t' (aka 'int') but the argument has type 'double'}} + printf("%wc", bad); // expected-warning{{format specifies type 'wint_t' (aka 'unsigned short') but the argument has type 'double'}} printf("%wC", bad); // expected-warning{{format specifies type 'wchar_t' (aka 'unsigned short') but the argument has type 'double'}} printf("%C", bad); // expected-warning{{format specifies type 'wchar_t' (aka 'unsigned short') but the argument has type 'double'}} printf("%ws", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}} diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 54651226adc5..a9af8ce5dee9 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -401,7 +401,11 @@ void bug7377_bad_length_mod_usage() { void pr7981(wint_t c, wchar_t c2) { printf("%lc", c); // no-warning printf("%lc", 1.0); // expected-warning{{the argument has type 'double'}} +#if __WINT_WIDTH__ == 32 printf("%lc", (char) 1); // no-warning +#else + printf("%lc", (char) 1); // expected-warning{{the argument has type 'char'}} +#endif printf("%lc", &c); // expected-warning{{the argument has type 'wint_t *'}} // If wint_t and wchar_t are the same width and wint_t is signed where // wchar_t is unsigned, an implicit conversion isn't possible. @@ -609,6 +613,11 @@ void pr12761(char c) { printf("%hhx", c); } +void test_opencl_vector_format(int x) { + printf("%v4d", x); // expected-warning{{invalid conversion specifier 'v'}} + printf("%vd", x); // expected-warning{{invalid conversion specifier 'v'}} + printf("%0vd", x); // expected-warning{{invalid conversion specifier 'v'}} +} // Test that we correctly merge the format in both orders. extern void test14_foo(const char *, const char *, ...) diff --git a/test/Sema/implicit-cast-dump.c b/test/Sema/implicit-cast-dump.c deleted file mode 100644 index 4cd855fb1d46..000000000000 --- a/test/Sema/implicit-cast-dump.c +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %clang_cc1 -ast-dump %s | FileCheck %s - -void foo1(void*); -void foo2(void* const); - - -void bar() { - // CHECK: FunctionDecl {{.*}} <line:{{.*}}, line:{{.*}}> line:{{.*}} bar 'void ()' - - foo1(0); - // CHECK: ImplicitCastExpr {{.*}} <col:{{.*}}> 'void *' <NullToPointer> - - foo2(0); - // CHECK: ImplicitCastExpr {{.*}} <col:{{.*}}> 'void *' <NullToPointer> -} diff --git a/test/Sema/implicit-int-conversion.c b/test/Sema/implicit-int-conversion.c new file mode 100644 index 000000000000..6d07d385e0bd --- /dev/null +++ b/test/Sema/implicit-int-conversion.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s -verify -Wconversion -Wno-implicit-int-conversion -DSMALL=char -DBIG=int -DNO_DIAG +// RUN: %clang_cc1 %s -verify -Wno-conversion -Wimplicit-int-conversion -DSMALL=char -DBIG=int +// RUN: %clang_cc1 %s -verify -Wconversion -Wno-implicit-float-conversion -DSMALL=float -DBIG=double -DNO_DIAG +// RUN: %clang_cc1 %s -verify -Wno-conversion -Wimplicit-float-conversion -DSMALL=float -DBIG=double + +void f() { + SMALL a; + BIG b = 0; + a = b; +#ifndef NO_DIAG + // expected-warning@-2 {{implicit conversion}} +#else + // expected-no-diagnostics +#endif +} diff --git a/test/Sema/integer-overflow.c b/test/Sema/integer-overflow.c index d66ce7ff1647..39395d9bc1fd 100644 --- a/test/Sema/integer-overflow.c +++ b/test/Sema/integer-overflow.c @@ -172,6 +172,9 @@ void check_integer_overflows_in_function_calls() { // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}} (void)f2(0, f0(4608 * 1024 * 1024)); } +void check_integer_overflows_in_array_size() { + int arr[4608 * 1024 * 1024]; // expected-warning {{overflow in expression; result is 536870912 with type 'int'}} +} struct s { unsigned x; diff --git a/test/Sema/internal_linkage.c b/test/Sema/internal_linkage.c index 57315d826e24..cc8039acd275 100644 --- a/test/Sema/internal_linkage.c +++ b/test/Sema/internal_linkage.c @@ -1,9 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -verify -fdouble-square-bracket-attributes %s int var __attribute__((internal_linkage)); -int var2 __attribute__((internal_linkage,common)); // expected-error{{'internal_linkage' and 'common' attributes are not compatible}} \ +int var2 __attribute__((internal_linkage,common)); // expected-error{{'common' and 'internal_linkage' attributes are not compatible}} \ // expected-note{{conflicting attribute is here}} -int var3 __attribute__((common,internal_linkage)); // expected-error{{'common' and 'internal_linkage' attributes are not compatible}} \ +int var3 __attribute__((common,internal_linkage)); // expected-error{{'internal_linkage' and 'common' attributes are not compatible}} \ // expected-note{{conflicting attribute is here}} int var4 __attribute__((common)); // expected-error{{'common' and 'internal_linkage' attributes are not compatible}} \ diff --git a/test/Sema/mips-interrupt-attr.c b/test/Sema/mips-interrupt-attr.c index 17344b6edcf0..7c5c9ddab5d6 100644 --- a/test/Sema/mips-interrupt-attr.c +++ b/test/Sema/mips-interrupt-attr.c @@ -19,11 +19,11 @@ __attribute__((interrupt(""))) void food() {} __attribute__((interrupt)) int foob() {return 0;} // expected-warning {{MIPS 'interrupt' attribute only applies to functions that have a 'void' return type}} __attribute__((interrupt())) void fooc(int a) {} // expected-warning {{MIPS 'interrupt' attribute only applies to functions that have no parameters}} -__attribute__((interrupt,mips16)) void fooe() {} // expected-error {{'interrupt' and 'mips16' attributes are not compatible}} \ +__attribute__((interrupt,mips16)) void fooe() {} // expected-error {{'mips16' and 'interrupt' attributes are not compatible}} \ // expected-note {{conflicting attribute is here}} -__attribute__((mips16,interrupt)) void foof() {} // expected-error {{'mips16' and 'interrupt' attributes are not compatible}} \ +__attribute__((mips16,interrupt)) void foof() {} // expected-error {{'interrupt' and 'mips16' attributes are not compatible}} \ // expected-note {{conflicting attribute is here}} -__attribute__((interrupt)) __attribute__ ((mips16)) void foo10() {} // expected-error {{'interrupt' and 'mips16' attributes are not compatible}} \ +__attribute__((interrupt)) __attribute__ ((mips16)) void foo10() {} // expected-error {{'mips16' and 'interrupt' attributes are not compatible}} \ // expected-note {{conflicting attribute is here}} -__attribute__((mips16)) __attribute ((interrupt)) void foo11() {} // expected-error {{'mips16' and 'interrupt' attributes are not compatible}} \ +__attribute__((mips16)) __attribute ((interrupt)) void foo11() {} // expected-error {{'interrupt' and 'mips16' attributes are not compatible}} \ // expected-note {{conflicting attribute is here}} diff --git a/test/Sema/multistep-explicit-cast.c b/test/Sema/multistep-explicit-cast.c deleted file mode 100644 index aeb591961812..000000000000 --- a/test/Sema/multistep-explicit-cast.c +++ /dev/null @@ -1,70 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -ast-dump %s | FileCheck %s - -// We are checking that implicit casts don't get marked with 'part_of_explicit_cast', -// while in explicit casts, the implicitly-inserted implicit casts are marked with 'part_of_explicit_cast' - -unsigned char implicitcast_0(unsigned int x) { - // CHECK: FunctionDecl {{.*}} <{{.*}}, line:{{.*}}> line:{{.*}} implicitcast_0 'unsigned char (unsigned int)'{{$}} - // CHECK: ImplicitCastExpr {{.*}} <col:{{.*}}> 'unsigned char' <IntegralCast>{{$}} - // CHECK-NEXT: ImplicitCastExpr {{.*}} <col:{{.*}}> 'unsigned int' <LValueToRValue>{{$}} - // CHECK-NEXT: DeclRefExpr {{.*}} <col:{{.*}}> 'unsigned int' lvalue ParmVar {{.*}} 'x' 'unsigned int'{{$}} - return x; -} - -signed char implicitcast_1(unsigned int x) { - // CHECK: FunctionDecl {{.*}} <{{.*}}, line:{{.*}}> line:{{.*}} implicitcast_1 'signed char (unsigned int)'{{$}} - // CHECK: ImplicitCastExpr {{.*}} <col:{{.*}}> 'signed char' <IntegralCast>{{$}} - // CHECK-NEXT: ImplicitCastExpr {{.*}} <col:{{.*}}> 'unsigned int' <LValueToRValue>{{$}} - // CHECK-NEXT: DeclRefExpr {{.*}} <col:{{.*}}> 'unsigned int' lvalue ParmVar {{.*}} 'x' 'unsigned int'{{$}} - return x; -} - -unsigned char implicitcast_2(signed int x) { - // CHECK: FunctionDecl {{.*}} <{{.*}}, line:{{.*}}> line:{{.*}} implicitcast_2 'unsigned char (int)'{{$}} - // CHECK: ImplicitCastExpr {{.*}} <col:{{.*}}> 'unsigned char' <IntegralCast>{{$}} - // CHECK-NEXT: ImplicitCastExpr {{.*}} <col:{{.*}}> 'int' <LValueToRValue>{{$}} - // CHECK-NEXT: DeclRefExpr {{.*}} <col:{{.*}}> 'int' lvalue ParmVar {{.*}} 'x' 'int'{{$}} - return x; -} - -signed char implicitcast_3(signed int x) { - // CHECK: FunctionDecl {{.*}} <{{.*}}, line:{{.*}}> line:{{.*}} implicitcast_3 'signed char (int)'{{$}} - // CHECK: ImplicitCastExpr {{.*}} <col:{{.*}}> 'signed char' <IntegralCast>{{$}} - // CHECK-NEXT: ImplicitCastExpr {{.*}} <col:{{.*}}> 'int' <LValueToRValue>{{$}} - // CHECK-NEXT: DeclRefExpr {{.*}} <col:{{.*}}> 'int' lvalue ParmVar {{.*}} 'x' 'int'{{$}} - return x; -} - -//----------------------------------------------------------------------------// - -unsigned char cstylecast_0(unsigned int x) { - // CHECK: FunctionDecl {{.*}} <{{.*}}, line:{{.*}}> line:{{.*}} cstylecast_0 'unsigned char (unsigned int)'{{$}} - // CHECK: CStyleCastExpr {{.*}} <col:{{.*}}> 'unsigned char' <IntegralCast>{{$}} - // CHECK-NEXT: ImplicitCastExpr {{.*}} <col:{{.*}}> 'unsigned int' <LValueToRValue> part_of_explicit_cast{{$}} - // CHECK-NEXT: DeclRefExpr {{.*}} <col:{{.*}}> 'unsigned int' lvalue ParmVar {{.*}} 'x' 'unsigned int'{{$}} - return (unsigned char)x; -} - -signed char cstylecast_1(unsigned int x) { - // CHECK: FunctionDecl {{.*}} <{{.*}}, line:{{.*}}> line:{{.*}} cstylecast_1 'signed char (unsigned int)'{{$}} - // CHECK: CStyleCastExpr {{.*}} <col:{{.*}}> 'signed char' <IntegralCast>{{$}} - // CHECK-NEXT: ImplicitCastExpr {{.*}} <col:{{.*}}> 'unsigned int' <LValueToRValue> part_of_explicit_cast{{$}} - // CHECK-NEXT: DeclRefExpr {{.*}} <col:{{.*}}> 'unsigned int' lvalue ParmVar {{.*}} 'x' 'unsigned int'{{$}} - return (signed char)x; -} - -unsigned char cstylecast_2(signed int x) { - // CHECK: FunctionDecl {{.*}} <{{.*}}, line:{{.*}}> line:{{.*}} cstylecast_2 'unsigned char (int)'{{$}} - // CHECK: CStyleCastExpr {{.*}} <col:{{.*}}> 'unsigned char' <IntegralCast>{{$}} - // CHECK-NEXT: ImplicitCastExpr {{.*}} <col:{{.*}}> 'int' <LValueToRValue> part_of_explicit_cast{{$}} - // CHECK-NEXT: DeclRefExpr {{.*}} <col:{{.*}}> 'int' lvalue ParmVar {{.*}} 'x' 'int'{{$}} - return (unsigned char)x; -} - -signed char cstylecast_3(signed int x) { - // CHECK: FunctionDecl {{.*}} <{{.*}}, line:{{.*}}> line:{{.*}} cstylecast_3 'signed char (int)'{{$}} - // CHECK: CStyleCastExpr {{.*}} <col:{{.*}}> 'signed char' <IntegralCast>{{$}} - // CHECK-NEXT: ImplicitCastExpr {{.*}} <col:{{.*}}> 'int' <LValueToRValue> part_of_explicit_cast{{$}} - // CHECK-NEXT: DeclRefExpr {{.*}} <col:{{.*}}> 'int' lvalue ParmVar {{.*}} 'x' 'int'{{$}} - return (signed char)x; -} diff --git a/test/Sema/nullability.c b/test/Sema/nullability.c index a0247e5af8b3..a5cb4b9a031e 100644 --- a/test/Sema/nullability.c +++ b/test/Sema/nullability.c @@ -20,8 +20,8 @@ typedef int * _Null_unspecified null_unspecified_int_ptr; typedef int * _Nonnull _Nonnull redundant_1; // expected-warning{{duplicate nullability specifier '_Nonnull'}} // Conflicting nullability type specifiers. -typedef int * _Nonnull _Nullable conflicting_1; // expected-error{{nullability specifier '_Nonnull' conflicts with existing specifier '_Nullable'}} -typedef int * _Null_unspecified _Nonnull conflicting_2; // expected-error{{nullability specifier '_Null_unspecified' conflicts with existing specifier '_Nonnull'}} +typedef int * _Nonnull _Nullable conflicting_1; // expected-error{{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}} +typedef int * _Null_unspecified _Nonnull conflicting_2; // expected-error{{nullability specifier '_Nonnull' conflicts with existing specifier '_Null_unspecified'}} // Redundant nullability specifiers via a typedef are okay. typedef nonnull_int_ptr _Nonnull redundant_okay_1; diff --git a/test/Sema/pr32985.c b/test/Sema/pr32985.c new file mode 100644 index 000000000000..f61cea4e7314 --- /dev/null +++ b/test/Sema/pr32985.c @@ -0,0 +1,20 @@ +/* +RUN: %clang_cc1 %s -std=gnu89 -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-GNU89 %s -allow-empty +RUN: %clang_cc1 %s -std=gnu89 -pedantic -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-GNU89-PEDANTIC %s +*/ + +typedef const int t; +const t c_i; +/* +CHECK-GNU89-NOT: 7:1: warning: duplicate 'const' declaration specifier +CHECK-GNU89-PEDANTIC: 7:1: warning: duplicate 'const' declaration specifier +*/ + +const int c_i2; +const typeof(c_i2) c_i3; +/* +CHECK-GNU89-NOT: 14:7: warning: extension used +CHECK-GNU89-NOT: 14:1: warning: duplicate 'const' declaration specifier +CHECK-GNU89-PEDANTIC: 14:7: warning: extension used +CHECK-GNU89-PEDANTIC: 14:1: warning: duplicate 'const' declaration specifier +*/ diff --git a/test/Sema/pragma-attribute-namespace.c b/test/Sema/pragma-attribute-namespace.c new file mode 100644 index 000000000000..e7a36afcdc23 --- /dev/null +++ b/test/Sema/pragma-attribute-namespace.c @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +#if !__has_extension(pragma_clang_attribute_namespaces) +#error +#endif + +#pragma clang attribute MyNamespace.push (__attribute__((annotate)), apply_to=function) // expected-error 2 {{'annotate' attribute}} + +int some_func(); // expected-note{{when applied to this declaration}} + +#pragma clang attribute pop // expected-error{{'#pragma clang attribute pop' with no matching '#pragma clang attribute push'}} +#pragma clang attribute NotMyNamespace.pop // expected-error{{'#pragma clang attribute NotMyNamespace.pop' with no matching '#pragma clang attribute NotMyNamespace.push'}} + +#pragma clang attribute MyOtherNamespace.push (__attribute__((annotate)), apply_to=function) // expected-error 2 {{'annotate' attribute}} + +int some_other_func(); // expected-note 2 {{when applied to this declaration}} + +// Out of order! +#pragma clang attribute MyNamespace.pop + +int some_other_other_func(); // expected-note 1 {{when applied to this declaration}} + +#pragma clang attribute MyOtherNamespace.pop + +#pragma clang attribute Misc. () // expected-error{{namespace can only apply to 'push' or 'pop' directives}} expected-note {{omit the namespace to add attributes to the most-recently pushed attribute group}} + +#pragma clang attribute Misc push // expected-error{{expected '.' after pragma attribute namespace 'Misc'}} + +// Test how pushes with namespaces interact with pushes without namespaces. + +#pragma clang attribute Merp.push (__attribute__((annotate)), apply_to=function) // expected-error{{'annotate' attribute}} +#pragma clang attribute push (__attribute__((annotate)), apply_to=function) // expected-warning {{unused attribute}} +#pragma clang attribute pop // expected-note{{ends here}} +int test(); // expected-note{{when applied to this declaration}} +#pragma clang attribute Merp.pop + +#pragma clang attribute push (__attribute__((annotate)), apply_to=function) // expected-warning {{unused attribute}} +#pragma clang attribute Merp.push (__attribute__((annotate)), apply_to=function) // expected-error{{'annotate' attribute}} +#pragma clang attribute pop // expected-note{{ends here}} +int test2(); // expected-note{{when applied to this declaration}} +#pragma clang attribute Merp.pop diff --git a/test/Sema/pragma-attribute.c b/test/Sema/pragma-attribute.c index d321f2ce4be7..202b3f75faa6 100644 --- a/test/Sema/pragma-attribute.c +++ b/test/Sema/pragma-attribute.c @@ -38,6 +38,29 @@ __attribute__((always_inline)) void optnone3() { } // expected-warning {{'always #pragma clang attribute pop +#pragma clang attribute push (__attribute__((annotate())), apply_to = function) // expected-error{{'annotate' attribute takes one argument}} +#pragma clang attribute (__attribute__((annotate())), apply_to = function) // expected-error{{'annotate' attribute takes one argument}} + +void fun(); // expected-note 2 {{when applied to this declaration}} + +#pragma clang attribute pop +#pragma clang attribute pop // expected-error{{'#pragma clang attribute pop' with no matching '#pragma clang attribute push'}} + + +#pragma clang attribute push +#pragma clang attribute (__attribute__((annotate())), apply_to = function) // expected-error 2 {{'annotate' attribute takes one argument}} + +void fun2(); // expected-note {{when applied to this declaration}} + +#pragma clang attribute push (__attribute__((annotate())), apply_to = function) // expected-error{{'annotate' attribute takes one argument}} +void fun3(); // expected-note 2 {{when applied to this declaration}} +#pragma clang attribute pop + +#pragma clang attribute pop +#pragma clang attribute pop // expected-error{{'#pragma clang attribute pop' with no matching '#pragma clang attribute push'}} + +#pragma clang attribute (__attribute__((annotate)), apply_to = function) // expected-error{{'#pragma clang attribute' attribute with no matching '#pragma clang attribute push}} + #pragma clang attribute push ([[]], apply_to = function) // A noop #pragma clang attribute pop // expected-error {{'#pragma clang attribute pop' with no matching '#pragma clang attribute push'}} diff --git a/test/Sema/pragma-pipeline.cpp b/test/Sema/pragma-pipeline.cpp new file mode 100644 index 000000000000..7b277601d063 --- /dev/null +++ b/test/Sema/pragma-pipeline.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s + +#pragma clang loop pipeline(disable) /* expected-error {{expected unqualified-id}} */ +int main() { + for (int i = 0; i < 10; ++i) + ; +} + +void test(int *List, int Length, int Value) { + int i = 0; + +/* expected-error {{invalid argument of type 'double'; expected an integer type}} */ #pragma clang loop pipeline_initiation_interval(1.0) +/* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop pipeline_initiation_interval(0) +/* expected-error {{invalid value '-1'; must be positive}} */ #pragma clang loop pipeline_initiation_interval(-1) + for (int i = 0; i < Length; i++) { + for (int j = 0; j < Length; j++) { + List[i * Length + j] = Value; + } + } + +#pragma clang loop pipeline(disable) +/* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int j = Length; +#pragma clang loop pipeline_initiation_interval(4) +/* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int k = Length; + +#pragma clang loop pipeline(disable) +#pragma clang loop pipeline_initiation_interval(4) /* expected-error {{incompatible directives 'pipeline(disable)' and 'pipeline_initiation_interval(4)'}} */ + for (int i = 0; i < Length; i++) { + List[i] = Value; + } + +#pragma clang loop pipeline(disable) +/* expected-error {{expected statement}} */ } + diff --git a/test/Sema/rdr6094103-unordered-compare-promote.c b/test/Sema/rdr6094103-unordered-compare-promote.c deleted file mode 100644 index 7bb363e797c8..000000000000 --- a/test/Sema/rdr6094103-unordered-compare-promote.c +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: %clang_cc1 -ast-dump %s 2>&1 | grep ImplicitCastExpr | count 4 - -int foo (double x, long double y) { - // There needs to be an implicit cast on x here. - return __builtin_isgreater(x, y); -} diff --git a/test/Sema/statements.c b/test/Sema/statements.c index dbb4d56ee1d1..ddaec8d433ef 100644 --- a/test/Sema/statements.c +++ b/test/Sema/statements.c @@ -34,6 +34,15 @@ bar: return &&bar; // expected-warning {{returning address of label, which is local}} } +// PR38569: Don't warn when returning a label from a statement expression. +void test10_logpc(void*); +void test10a() { + test10_logpc(({ + my_pc: + &&my_pc; + })); +} + // PR6034 void test11(int bit) { switch (bit) diff --git a/test/Sema/static-assert.c b/test/Sema/static-assert.c index 87fa0504b200..e8cfb1fa58d7 100644 --- a/test/Sema/static-assert.c +++ b/test/Sema/static-assert.c @@ -38,5 +38,5 @@ struct A { typedef UNION(unsigned, struct A) U1; UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; -typedef UNION(char, short) U3; // expected-error {{static_assert failed "type size mismatch"}} +typedef UNION(char, short) U3; // expected-error {{static_assert failed due to requirement 'sizeof(char) == sizeof(short)' "type size mismatch"}} typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} diff --git a/test/Sema/suspicious-pragma-pack.c b/test/Sema/suspicious-pragma-pack.c index d7c5faf06910..1acf63b46892 100644 --- a/test/Sema/suspicious-pragma-pack.c +++ b/test/Sema/suspicious-pragma-pack.c @@ -38,7 +38,7 @@ #include "pragma-pack1.h" #ifdef WARN_MODIFIED_HEADER -// expected-warning@-3 {{the current #pragma pack aligment value is modified in the included file}} +// expected-warning@-3 {{the current #pragma pack alignment value is modified in the included file}} #endif #ifdef PUSH_SET_HERE diff --git a/test/Sema/swift-call-conv.c b/test/Sema/swift-call-conv.c new file mode 100644 index 000000000000..755c18f5183f --- /dev/null +++ b/test/Sema/swift-call-conv.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -triple aarch64-unknown-windows-msvc -fsyntax-only %s -verify +// RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fsyntax-only %s -verify +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only %s -verify + +// expected-no-diagnostics + +void __attribute__((__swiftcall__)) f(void) {} diff --git a/test/Sema/switch-availability.c b/test/Sema/switch-availability.c new file mode 100644 index 000000000000..888edddac463 --- /dev/null +++ b/test/Sema/switch-availability.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -verify -Wswitch -triple x86_64-apple-macosx10.12 %s + +enum SwitchOne { + Unavail __attribute__((availability(macos, unavailable))), +}; + +void testSwitchOne(enum SwitchOne so) { + switch (so) {} // no warning +} + +enum SwitchTwo { + Ed __attribute__((availability(macos, deprecated=10.12))), + Vim __attribute__((availability(macos, deprecated=10.13))), + Emacs, +}; + +void testSwitchTwo(enum SwitchTwo st) { + switch (st) {} // expected-warning{{enumeration values 'Vim' and 'Emacs' not handled in switch}} +} + +enum SwitchThree { + New __attribute__((availability(macos, introduced=1000))), +}; + +void testSwitchThree(enum SwitchThree st) { + switch (st) {} // expected-warning{{enumeration value 'New' not handled in switch}} +} diff --git a/test/Sema/sync-implicit-seq_cst.c b/test/Sema/sync-implicit-seq_cst.c new file mode 100644 index 000000000000..1d9869b2022a --- /dev/null +++ b/test/Sema/sync-implicit-seq_cst.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 %s -verify -ffreestanding -fsyntax-only -triple=i686-linux-gnu -std=c11 -Watomic-implicit-seq-cst -Wno-sync-fetch-and-nand-semantics-changed + +// __sync_* operations are implicitly sequentially-consistent. Some codebases +// want to force explicit usage of memory order instead. + +void fetch_and_add(int *ptr, int val) { __sync_fetch_and_add(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void fetch_and_sub(int *ptr, int val) { __sync_fetch_and_sub(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void fetch_and_or(int *ptr, int val) { __sync_fetch_and_or(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void fetch_and_and(int *ptr, int val) { __sync_fetch_and_and(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void fetch_and_xor(int *ptr, int val) { __sync_fetch_and_xor(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void fetch_and_nand(int *ptr, int val) { __sync_fetch_and_nand(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} + +void add_and_fetch(int *ptr, int val) { __sync_add_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void sub_and_fetch(int *ptr, int val) { __sync_sub_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void or_and_fetch(int *ptr, int val) { __sync_or_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void and_and_fetch(int *ptr, int val) { __sync_and_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void xor_and_fetch(int *ptr, int val) { __sync_xor_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void nand_and_fetch(int *ptr, int val) { __sync_nand_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} + +void bool_compare_and_swap(int *ptr, int oldval, int newval) { __sync_bool_compare_and_swap(ptr, oldval, newval); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void val_compare_and_swap(int *ptr, int oldval, int newval) { __sync_val_compare_and_swap(ptr, oldval, newval); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} + +void synchronize(void) { __sync_synchronize(); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} + +void lock_test_and_set(int *ptr, int val) { __sync_lock_test_and_set(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} +void lock_release(int *ptr) { __sync_lock_release(ptr); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}} diff --git a/test/Sema/unary-minus-integer-impcast.c b/test/Sema/unary-minus-integer-impcast.c new file mode 100644 index 000000000000..0eb440175881 --- /dev/null +++ b/test/Sema/unary-minus-integer-impcast.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 %s -verify -Wconversion -fsyntax-only -triple x86_64-pc-linux-gnu +// RUN: %clang_cc1 %s -verify -Wconversion -fsyntax-only -triple i386-pc-linux-gnu + +void test(void) { + unsigned int a = 1; + + unsigned long long b = -a; // expected-warning {{higher order bits are zeroes after implicit conversion}} + long long c = -a; // expected-warning {{the resulting value is always non-negative after implicit conversion}} + + unsigned long b2 = -a; +#ifdef __x86_64__ +// expected-warning@-2 {{higher order bits are zeroes after implicit conversion}} +#endif + long c2 = -a; +#ifdef __x86_64__ +// expected-warning@-2 {{the resulting value is always non-negative after implicit conversion}} +#else +// expected-warning@-4 {{implicit conversion changes signedness: 'unsigned int' to 'long'}} +#endif +} diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c index 89ea190cbc61..e2d98354932b 100644 --- a/test/Sema/uninit-variables.c +++ b/test/Sema/uninit-variables.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -fsyntax-only -fblocks %s -verify +// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -ftrivial-auto-var-init=pattern -fsyntax-only -fblocks %s -verify typedef __typeof(sizeof(int)) size_t; void *malloc(size_t); diff --git a/test/Sema/variadic-promotion.c b/test/Sema/variadic-promotion.c deleted file mode 100644 index 01d8e934b4eb..000000000000 --- a/test/Sema/variadic-promotion.c +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: %clang_cc1 -ast-dump %s | FileCheck %s - -void variadic(int, ...); - -void test_floating_promotion(__fp16 *f16, float f32, double f64) { - variadic(3, *f16, f32, f64); - -// CHECK: ImplicitCastExpr {{.*}} 'double' <FloatingCast> -// CHECK-NEXT: '__fp16' - -// CHECK: ImplicitCastExpr {{.*}} 'double' <FloatingCast> -// CHECK-NEXT: 'float' -} diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp index 7ffaffc07849..5083f686338c 100644 --- a/test/Sema/warn-documentation.cpp +++ b/test/Sema/warn-documentation.cpp @@ -1304,3 +1304,12 @@ typedef void (*VariadicFnType)(int a, ...); * now should work too. */ using VariadicFnType2 = void (*)(int a, ...); + +// expected-warning@+2 {{empty paragraph passed to '@note' command}} +/** +@note +\f$\texttt{mu}_{00}=\texttt{m}_{00}\f$, \f$\texttt{nu}_{00}=1\f$ +\f$\texttt{nu}_{10}=\texttt{mu}_{10}=\texttt{mu}_{01}=\texttt{mu}_{10}=0\f$ + */ +class EmptyNoteNoCrash { +}; diff --git a/test/Sema/warn-duplicate-enum.c b/test/Sema/warn-duplicate-enum.c index 84fdeb4f8fd4..4d51d055f5e9 100644 --- a/test/Sema/warn-duplicate-enum.c +++ b/test/Sema/warn-duplicate-enum.c @@ -1,5 +1,5 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -Wduplicate-enum -// RUN: %clang_cc1 %s -x c++ -fsyntax-only -verify -Wduplicate-enum +// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -x c++ -DCPP -fsyntax-only -verify -Wduplicate-enum enum A { A1 = 0, // expected-note {{element 'A1' also has value 0}} A2 = -1, @@ -99,3 +99,11 @@ enum enum1 { enum enum2 { VALUE // expected-error{{redefinition of enumerator 'VALUE'}} }; + +// rdar://44774672 +#ifdef CPP +enum BigEnumerators : long { + e1, + e2 = __LONG_MAX__, +}; +#endif diff --git a/test/Sema/warn-shadow.c b/test/Sema/warn-shadow.c index 32aca8d612b2..aa8505b0c917 100644 --- a/test/Sema/warn-shadow.c +++ b/test/Sema/warn-shadow.c @@ -59,3 +59,15 @@ void rdar8883302() { void test8() { int bob; // expected-warning {{declaration shadows a variable in the global scope}} } + +enum PR24718_1{pr24718}; // expected-note {{previous declaration is here}} +void PR24718(void) { + enum PR24718_2{pr24718}; // expected-warning {{declaration shadows a variable in the global scope}} +} + +struct PR24718_3; +struct PR24718_4 { + enum { + PR24718_3 // Does not shadow a type. + }; +}; diff --git a/test/Sema/zvector.c b/test/Sema/zvector.c index 740163fcd9d5..858e10d661f8 100644 --- a/test/Sema/zvector.c +++ b/test/Sema/zvector.c @@ -37,6 +37,49 @@ unsigned long ul_scalar; double fd_scalar; +// Verify that __vector is also recognized +__vector signed char sc3; +__vector unsigned char uc3; +__vector bool char bc3; +__vector signed short ss3; +__vector unsigned short us3; +__vector bool short bs3; +__vector signed int si3; +__vector unsigned int ui3; +__vector bool int bi3; +__vector signed long long sl3; +__vector unsigned long long ul3; +__vector bool long long bl3; +__vector double fd3; +__vector long ll3; // expected-error {{cannot use 'long' with '__vector'}} +__vector float ff3; // expected-error {{cannot use 'float' with '__vector'}} + +// Likewise for __bool +vector __bool char bc4; +vector __bool short bs4; +vector __bool int bi4; +vector __bool long long bl4; +__vector __bool char bc5; +__vector __bool short bs5; +__vector __bool int bi5; +__vector __bool long long bl5; + +// Verify operation of vec_step +int res_sc[vec_step(sc) == 16 ? 1 : -1]; +int res_uc[vec_step(uc) == 16 ? 1 : -1]; +int res_bc[vec_step(bc) == 16 ? 1 : -1]; +int res_ss[vec_step(ss) == 8 ? 1 : -1]; +int res_us[vec_step(us) == 8 ? 1 : -1]; +int res_bs[vec_step(bs) == 8 ? 1 : -1]; +int res_si[vec_step(si) == 4 ? 1 : -1]; +int res_ui[vec_step(ui) == 4 ? 1 : -1]; +int res_bi[vec_step(bi) == 4 ? 1 : -1]; +int res_sl[vec_step(sl) == 2 ? 1 : -1]; +int res_ul[vec_step(ul) == 2 ? 1 : -1]; +int res_bl[vec_step(bl) == 2 ? 1 : -1]; +int res_fd[vec_step(fd) == 2 ? 1 : -1]; + + void foo(void) { // ------------------------------------------------------------------------- diff --git a/test/Sema/zvector2.c b/test/Sema/zvector2.c index 0adc0315f0b8..08ec9dfc661f 100644 --- a/test/Sema/zvector2.c +++ b/test/Sema/zvector2.c @@ -22,6 +22,13 @@ vector double fd, fd2; vector float ff, ff2; +// Verify that __vector is also recognized +__vector float ff3; + +// Verify operation of vec_step +int res_ff[vec_step(ff) == 4 ? 1 : -1]; + + void foo(void) { // ------------------------------------------------------------------------- |
