diff options
Diffstat (limited to 'test/Sema')
43 files changed, 774 insertions, 93 deletions
diff --git a/test/Sema/Float16.c b/test/Sema/Float16.c new file mode 100644 index 0000000000..bdfb01702c --- /dev/null +++ b/test/Sema/Float16.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE +// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE +// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE + +#ifdef HAVE +// expected-no-diagnostics +#else +// expected-error@+2{{_Float16 is not supported on this target}} +#endif // HAVE +_Float16 f; diff --git a/test/Sema/asm.c b/test/Sema/asm.c index 04b7cb19eb..67da197426 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -249,7 +249,7 @@ void fn6() { int a; __asm__("" : "=rm"(a), "=rm"(a) - : "11m"(a)) // expected-error {{invalid input constraint '11m' in asm}} + : "11m"(a)); // expected-error {{invalid input constraint '11m' in asm}} } // PR14269 diff --git a/test/Sema/attr-availability-watchos.c b/test/Sema/attr-availability-watchos.c index 866efac6a0..dbcf2c24c6 100644 --- a/test/Sema/attr-availability-watchos.c +++ b/test/Sema/attr-availability-watchos.c @@ -52,3 +52,9 @@ void test_watchos() { f5c_watchos(0); // expected-warning {{'f5c_watchos' is deprecated: first deprecated in watchOS 2.0}} f6_watchos(0); // expected-warning {{'f6_watchos' is deprecated: first deprecated in watchOS 3.0}} } + +void deprecatedAfterIntroduced() __attribute__((availability(ios,introduced=9.3,deprecated=10))); // expected-note {{here}} + +void test_ios_correctly_map_to_watchos() { + deprecatedAfterIntroduced(); // expected-warning {{'deprecatedAfterIntroduced' is deprecated: first deprecated in watchOS 3}} +} diff --git a/test/Sema/attr-callback-broken.c b/test/Sema/attr-callback-broken.c new file mode 100644 index 0000000000..b9e5f45f40 --- /dev/null +++ b/test/Sema/attr-callback-broken.c @@ -0,0 +1,75 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only + +__attribute__((callback())) void no_callee(void (*callback)(void)); // expected-error {{'callback' attribute specifies no callback callee}} + +__attribute__((callback(1, 1))) void too_many_args_1(void (*callback)(void)) {} // expected-error {{'callback' attribute takes one argument}} +__attribute__((callback(1, -1))) void too_many_args_2(double (*callback)(void)); // expected-error {{'callback' attribute takes one argument}} +__attribute__((callback(1, 2, 2))) void too_many_args_3(void (*callback)(int), int); // expected-error {{'callback' attribute requires exactly 2 arguments}} + +__attribute__((callback(1, 2))) void too_few_args_1(void (*callback)(int, int), int); // expected-error {{'callback' attribute takes one argument}} +__attribute__((callback(1))) void too_few_args_2(int (*callback)(int)); // expected-error {{'callback' attribute takes no arguments}} +__attribute__((callback(1, -1))) void too_few_args_3(void (*callback)(int, int)) {} // expected-error {{'callback' attribute takes one argument}} + +__attribute__((callback(-1))) void oob_args_1(void (*callback)(void)); // expected-error {{'callback' attribute specifies invalid callback callee}} +__attribute__((callback(2))) void oob_args_2(int *(*callback)(void)) {} // expected-error {{'callback' attribute parameter 1 is out of bounds}} +__attribute__((callback(1, 3))) void oob_args_3(short (*callback)(int), int); // expected-error {{'callback' attribute parameter 2 is out of bounds}} +__attribute__((callback(-2, 2))) void oob_args_4(void *(*callback)(int), int); // expected-error {{'callback' attribute parameter 1 is out of bounds}} +__attribute__((callback(1, -2))) void oob_args_5(void *(*callback)(int), int); // expected-error {{'callback' attribute parameter 2 is out of bounds}} +__attribute__((callback(1, 2))) void oob_args_6(void *(*callback)(int), ...); // expected-error {{'callback' attribute parameter 2 is out of bounds}} + +__attribute__((callback(1))) __attribute__((callback(1))) void multiple_cb_1(void (*callback)(void)); // expected-error {{multiple 'callback' attributes specified}} +__attribute__((callback(1))) __attribute__((callback(2))) void multiple_cb_2(void (*callback1)(void), void (*callback2)(void)); // expected-error {{multiple 'callback' attributes specified}} + +#ifdef HAS_THIS +__attribute__((callback(0))) void oob_args_0(void (*callback)(void)); // expected-error {{'callback' attribute specifies invalid callback callee}} +#else +__attribute__((callback(0))) void oob_args_0(void (*callback)(void)); // expected-error {{'callback' argument at position 1 references unavailable implicit 'this'}} +__attribute__((callback(1, 0))) void no_this_1(void *(*callback)(void *)); // expected-error {{'callback' argument at position 2 references unavailable implicit 'this'}} +__attribute__((callback(1, 0))) void no_this_2(void *(*callback)(int, void *)); // expected-error {{'callback' argument at position 2 references unavailable implicit 'this'}} +#endif + +// We could allow the following declarations if we at some point need to: + +__attribute__((callback(1, -1))) void vararg_cb_1(void (*callback)(int, ...)) {} // expected-error {{'callback' attribute callee may not be variadic}} +__attribute__((callback(1, 1))) void vararg_cb_2(void (*callback)(int, ...), int a); // expected-error {{'callback' attribute callee may not be variadic}} + +__attribute__((callback(1, -1, 1, 2, 3, 4, -1))) void varargs_1(void (*callback)(int, ...), int a, float b, double c) {} // expected-error {{'callback' attribute requires exactly 6 arguments}} +__attribute__((callback(1, -1, 4, 2, 3, 4, -1))) void varargs_2(void (*callback)(void *, double, int, ...), int a, float b, double c); // expected-error {{'callback' attribute requires exactly 6 arguments}} + +__attribute__((callback(1, -1, 1))) void self_arg_1(void (*callback)(int, ...)) {} // expected-error {{'callback' attribute requires exactly 2 arguments}} +__attribute__((callback(1, -1, 1, -1, -1, 1))) void self_arg_2(void (*callback)(int, ...)); // expected-error {{'callback' attribute requires exactly 5 arguments}} + +__attribute__((callback(cb))) void unknown_name1(void (*callback)(void)) {} // expected-error {{'callback' attribute argument 'cb' is not a known function parameter}} +__attribute__((callback(cb, ab))) void unknown_name2(void (*cb)(int), int a) {} // expected-error {{'callback' attribute argument 'ab' is not a known function parameter}} + +__attribute__((callback(callback, 1))) void too_many_args_1b(void (*callback)(void)) {} // expected-error {{'callback' attribute takes one argument}} +__attribute__((callback(callback, __))) void too_many_args_2b(double (*callback)(void)); // expected-error {{'callback' attribute takes one argument}} +__attribute__((callback(callback, 2, 2))) void too_many_args_3b(void (*callback)(int), int); // expected-error {{'callback' attribute requires exactly 2 arguments}} + +__attribute__((callback(callback, a))) void too_few_args_1b(void (*callback)(int, int), int a); // expected-error {{'callback' attribute takes one argument}} +__attribute__((callback(callback))) void too_few_args_2b(int (*callback)(int)); // expected-error {{'callback' attribute takes no arguments}} +__attribute__((callback(callback, __))) void too_few_args_3b(void (*callback)(int, int)) {} // expected-error {{'callback' attribute takes one argument}} + +__attribute__((callback(__))) void oob_args_1b(void (*callback)(void)); // expected-error {{'callback' attribute specifies invalid callback callee}} + +__attribute__((callback(callback))) __attribute__((callback(callback))) void multiple_cb_1b(void (*callback)(void)); // expected-error {{multiple 'callback' attributes specified}} +__attribute__((callback(1))) __attribute__((callback(callback2))) void multiple_cb_2b(void (*callback1)(void), void (*callback2)(void)); // expected-error {{multiple 'callback' attributes specified}} + +#ifdef HAS_THIS +__attribute__((callback(this))) void oob_args_0b(void (*callback)(void)); // expected-error {{'callback' attribute specifies invalid callback callee}} +#else +__attribute__((callback(this))) void oob_args_0b(void (*callback)(void)); // expected-error {{'callback' argument at position 1 references unavailable implicit 'this'}} +__attribute__((callback(1, this))) void no_this_1b(void *(*callback)(void *)); // expected-error {{'callback' argument at position 2 references unavailable implicit 'this'}} +__attribute__((callback(1, this))) void no_this_2b(void *(*callback)(int, void *)); // expected-error {{'callback' argument at position 2 references unavailable implicit 'this'}} +#endif + +// We could allow the following declarations if we at some point need to: + +__attribute__((callback(callback, __))) void vararg_cb_1b(void (*callback)(int, ...)) {} // expected-error {{'callback' attribute callee may not be variadic}} +__attribute__((callback(1, a))) void vararg_cb_2b(void (*callback)(int, ...), int a); // expected-error {{'callback' attribute callee may not be variadic}} + +__attribute__((callback(callback, __, callback, a, b, c, __))) void varargs_1b(void (*callback)(int, ...), int a, float b, double c) {} // expected-error {{'callback' attribute requires exactly 6 arguments}} +__attribute__((callback(1, __, c, a, b, c, -1))) void varargs_2b(void (*callback)(void *, double, int, ...), int a, float b, double c); // expected-error {{'callback' attribute requires exactly 6 arguments}} + +__attribute__((callback(1, __, callback))) void self_arg_1b(void (*callback)(int, ...)) {} // expected-error {{'callback' attribute requires exactly 2 arguments}} +__attribute__((callback(callback, __, callback, __, __, callback))) void self_arg_2b(void (*callback)(int, ...)); // expected-error {{'callback' attribute requires exactly 5 arguments}} diff --git a/test/Sema/attr-callback.c b/test/Sema/attr-callback.c new file mode 100644 index 0000000000..ec12b1650a --- /dev/null +++ b/test/Sema/attr-callback.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only + +// expected-no-diagnostics + +__attribute__((callback(1))) void no_args(void (*callback)(void)); +__attribute__((callback(1, 2, 3))) void args_1(void (*callback)(int, double), int a, double b); +__attribute__((callback(2, 3, 3))) void args_2(int a, void (*callback)(double, double), double b); +__attribute__((callback(2, -1, -1))) void args_3(int a, void (*callback)(double, double), double b); + +__attribute__((callback(callback))) void no_argsb(void (*callback)(void)); +__attribute__((callback(callback, a, 3))) void args_1b(void (*callback)(int, double), int a, double b); +__attribute__((callback(callback, b, b))) void args_2b(int a, void (*callback)(double, double), double b); +__attribute__((callback(2, __, __))) void args_3b(int a, void (*callback)(double, double), double b); +__attribute__((callback(callback, -1, __))) void args_3c(int a, void (*callback)(double, double), double b); diff --git a/test/Sema/attr-cpuspecific.c b/test/Sema/attr-cpuspecific.c index e87ad4de75..ae86742ca0 100644 --- a/test/Sema/attr-cpuspecific.c +++ b/test/Sema/attr-cpuspecific.c @@ -112,3 +112,6 @@ int __attribute__((cpu_specific(pentium_4))) called_invalid_value(void){ return int use3(void) { return called_invalid_value(); } + +// expected-warning@+1 {{CPU list contains duplicate entries; attribute ignored}} +int __attribute__((cpu_dispatch(pentium_iii, pentium_iii_no_xmm_regs))) dupe_p3(void); diff --git a/test/Sema/attr-mig.c b/test/Sema/attr-mig.c new file mode 100644 index 0000000000..3b16696cd7 --- /dev/null +++ b/test/Sema/attr-mig.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef int kern_return_t; +#define KERN_SUCCESS 0 + +__attribute__((mig_server_routine)) kern_return_t var = KERN_SUCCESS; // expected-warning{{'mig_server_routine' attribute only applies to functions, Objective-C methods, and blocks}} + +__attribute__((mig_server_routine)) void foo_void(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} +__attribute__((mig_server_routine)) int foo_int(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} + +__attribute__((mig_server_routine)) kern_return_t bar_extern(); // no-warning +__attribute__((mig_server_routine)) kern_return_t bar_forward(); // no-warning + +__attribute__((mig_server_routine)) kern_return_t bar_definition() { // no-warning + return KERN_SUCCESS; +} + +kern_return_t bar_forward() { // no-warning + return KERN_SUCCESS; +} + +__attribute__((mig_server_routine(123))) kern_return_t bar_with_argument(); // expected-error{{'mig_server_routine' attribute takes no arguments}} diff --git a/test/Sema/attr-mig.cpp b/test/Sema/attr-mig.cpp new file mode 100644 index 0000000000..5dfc43bc1e --- /dev/null +++ b/test/Sema/attr-mig.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef int kern_return_t; +typedef kern_return_t IOReturn; +#define KERN_SUCCESS 0 +#define kIOReturnSuccess KERN_SUCCESS + +class MyServer { +public: + virtual __attribute__((mig_server_routine)) IOReturn externalMethod(); + virtual __attribute__((mig_server_routine)) void anotherMethod(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} + virtual __attribute__((mig_server_routine)) int yetAnotherMethod(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} + [[clang::mig_server_routine]] virtual IOReturn cppAnnotatedMethod(); + [[clang::mig_server_routine("arg")]] virtual IOReturn cppAnnotatedMethodWithInvalidArgs(); // expected-error{{'mig_server_routine' attribute takes no arguments}} + [[clang::mig_server_routine]] virtual int cppInvalidAnnotatedMethod(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} +}; + +IOReturn MyServer::externalMethod() { + return kIOReturnSuccess; +} diff --git a/test/Sema/attr-mig.m b/test/Sema/attr-mig.m new file mode 100644 index 0000000000..a40a9172e5 --- /dev/null +++ b/test/Sema/attr-mig.m @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s + +typedef int kern_return_t; +#define KERN_SUCCESS 0 + +@interface NSObject +@end + +@interface I: NSObject +- (kern_return_t)foo __attribute__((mig_server_routine)); // no-warning +- (void) bar_void __attribute__((mig_server_routine)); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} +- (int) bar_int __attribute__((mig_server_routine)); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} +@end + +@implementation I +- (kern_return_t)foo { + kern_return_t (^block)() = ^ __attribute__((mig_server_routine)) { // no-warning + return KERN_SUCCESS; + }; + + // FIXME: Warn that this block doesn't return a kern_return_t. + void (^invalid_block)() = ^ __attribute__((mig_server_routine)) {}; + + return block(); +} +- (void)bar_void { +} +- (int)bar_int { + return 0; +} +@end diff --git a/test/Sema/attr-mode.c b/test/Sema/attr-mode.c index c0e0426e00..c89cb65241 100644 --- a/test/Sema/attr-mode.c +++ b/test/Sema/attr-mode.c @@ -6,6 +6,12 @@ // RUN: -verify %s // RUN: %clang_cc1 -triple x86_64-pc-linux-gnux32 -DTEST_64BIT_X86 -fsyntax-only \ // RUN: -verify %s +// RUN: %clang_cc1 -triple mips-linux-gnu -DTEST_MIPS_32 -fsyntax-only \ +// RUN: -verify %s +// RUN: %clang_cc1 -triple mips64-linux-gnuabin32 -DTEST_MIPS_N32 -fsyntax-only \ +// RUN: -verify %s +// RUN: %clang_cc1 -triple mips64-linux-gnu -DTEST_MIPS_64 -fsyntax-only \ +// RUN: -verify %s typedef int i16_1 __attribute((mode(HI))); int i16_1_test[sizeof(i16_1) == 2 ? 1 : -1]; @@ -33,7 +39,7 @@ typedef _Complex double c32 __attribute((mode(SC))); int c32_test[sizeof(c32) == 8 ? 1 : -1]; typedef _Complex float c64 __attribute((mode(DC))); -#ifndef TEST_64BIT_PPC64 // Note, 'XC' mode is illegal for PPC64 machines. +#if !defined(__ppc__) && !defined(__mips__) // Note, 'XC' mode is illegal for PPC64 and MIPS machines. typedef _Complex float c80 __attribute((mode(XC))); #endif @@ -84,6 +90,15 @@ void f_ft128_arg(long double *x); void f_ft128_complex_arg(_Complex long double *x); void test_TFtype(f128ibm *a) { f_ft128_arg (a); } void test_TCtype(c128ibm *a) { f_ft128_complex_arg (a); } +#elif TEST_MIPS_32 +typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word))); +int foo[sizeof(gcc_unwind_word) == 4 ? 1 : -1]; +#elif TEST_MIPS_N32 +typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word))); +int foo[sizeof(gcc_unwind_word) == 8 ? 1 : -1]; +#elif TEST_MIPS_64 +typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word))); +int foo[sizeof(gcc_unwind_word) == 8 ? 1 : -1]; #else #error Unknown test architecture. #endif diff --git a/test/Sema/attr-msp430.c b/test/Sema/attr-msp430.c index 26b2d8fcfd..4b38d09b86 100644 --- a/test/Sema/attr-msp430.c +++ b/test/Sema/attr-msp430.c @@ -1,6 +1,13 @@ // RUN: %clang_cc1 -triple msp430-unknown-unknown -fsyntax-only -verify %s +__attribute__((interrupt(1))) int t; // expected-warning {{'interrupt' attribute only applies to functions}} + int i; -void f(void) __attribute__((interrupt(i))); /* expected-error {{'interrupt' attribute requires an integer constant}} */ +__attribute__((interrupt(i))) void f(void); // expected-error {{'interrupt' attribute requires an integer constant}} +__attribute__((interrupt(1, 2))) void f2(void); // expected-error {{'interrupt' attribute takes one argument}} +__attribute__((interrupt(1))) int f3(void); // expected-warning {{MSP430 'interrupt' attribute only applies to functions that have a 'void' return type}} +__attribute__((interrupt(1))) void f4(int a); // expected-warning {{MSP430 'interrupt' attribute only applies to functions that have no parameters}} +__attribute__((interrupt(64))) void f5(void); // expected-error {{'interrupt' attribute parameter 64 is out of bounds}} -void f2(void) __attribute__((interrupt(12))); +__attribute__((interrupt(0))) void f6(void); +__attribute__((interrupt(63))) void f7(void); diff --git a/test/Sema/builtin-object-size.c b/test/Sema/builtin-object-size.c index fcf86f3e34..fa66d2e9c0 100644 --- a/test/Sema/builtin-object-size.c +++ b/test/Sema/builtin-object-size.c @@ -1,29 +1,36 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin9 -verify %s +// RUN: %clang_cc1 -DDYNAMIC -fsyntax-only -triple x86_64-apple-darwin9 -verify %s + +#ifndef DYNAMIC +#define OBJECT_SIZE_BUILTIN __builtin_object_size +#else +#define OBJECT_SIZE_BUILTIN __builtin_dynamic_object_size +#endif int a[10]; int f0() { - return __builtin_object_size(&a); // expected-error {{too few arguments to function}} + return OBJECT_SIZE_BUILTIN(&a); // expected-error {{too few arguments to function}} } int f1() { - return (__builtin_object_size(&a, 0) + - __builtin_object_size(&a, 1) + - __builtin_object_size(&a, 2) + - __builtin_object_size(&a, 3)); + return (OBJECT_SIZE_BUILTIN(&a, 0) + + OBJECT_SIZE_BUILTIN(&a, 1) + + OBJECT_SIZE_BUILTIN(&a, 2) + + OBJECT_SIZE_BUILTIN(&a, 3)); } int f2() { - return __builtin_object_size(&a, -1); // expected-error {{argument value -1 is outside the valid range [0, 3]}} + return OBJECT_SIZE_BUILTIN(&a, -1); // expected-error {{argument value -1 is outside the valid range [0, 3]}} } int f3() { - return __builtin_object_size(&a, 4); // expected-error {{argument value 4 is outside the valid range [0, 3]}} + return OBJECT_SIZE_BUILTIN(&a, 4); // expected-error {{argument value 4 is outside the valid range [0, 3]}} } // 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 has size 11, but size argument is 42}} + __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); // expected-warning {{'vsnprintf' will always overflow; destination buffer has size 11, but size argument is 42}} } // rdar://18334276 @@ -31,9 +38,9 @@ typedef __typeof__(sizeof(int)) size_t; void * memcset(void *restrict dst, int src, size_t n); void * memcpy(void *restrict dst, const void *restrict src, size_t n); -#define memset(dest, src, len) __builtin___memset_chk(dest, src, len, __builtin_object_size(dest, 0)) -#define memcpy(dest, src, len) __builtin___memcpy_chk(dest, src, len, __builtin_object_size(dest, 0)) -#define memcpy1(dest, src, len) __builtin___memcpy_chk(dest, src, len, __builtin_object_size(dest, 4)) +#define memset(dest, src, len) __builtin___memset_chk(dest, src, len, OBJECT_SIZE_BUILTIN(dest, 0)) +#define memcpy(dest, src, len) __builtin___memcpy_chk(dest, src, len, OBJECT_SIZE_BUILTIN(dest, 0)) +#define memcpy1(dest, src, len) __builtin___memcpy_chk(dest, src, len, OBJECT_SIZE_BUILTIN(dest, 4)) #define NULL ((void *)0) void f5(void) @@ -49,8 +56,8 @@ 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 has size 5, but size argument is 10}} + __builtin___memccpy_chk (buf, b, '\0', sizeof(b), OBJECT_SIZE_BUILTIN (buf, 0)); + __builtin___memccpy_chk (b, buf, '\0', sizeof(buf), OBJECT_SIZE_BUILTIN (b, 0)); // expected-warning {{'memccpy' will always overflow; destination buffer has size 5, but size argument is 10}} } int pr28314(void) { @@ -70,10 +77,10 @@ int pr28314(void) { } *p3; int a = 0; - a += __builtin_object_size(&p->a, 0); - a += __builtin_object_size(p->b, 0); - a += __builtin_object_size(p2->b, 0); - a += __builtin_object_size(p3->b, 0); + a += OBJECT_SIZE_BUILTIN(&p->a, 0); + a += OBJECT_SIZE_BUILTIN(p->b, 0); + a += OBJECT_SIZE_BUILTIN(p2->b, 0); + a += OBJECT_SIZE_BUILTIN(p3->b, 0); return a; } @@ -82,12 +89,12 @@ int pr31843() { struct { int f; } a; int b; - n += __builtin_object_size(({&(b ? &a : &a)->f; pr31843;}), 0); // expected-warning{{expression result unused}} + n += OBJECT_SIZE_BUILTIN(({&(b ? &a : &a)->f; pr31843;}), 0); // expected-warning{{expression result unused}} struct statfs { char f_mntonname[1024];}; struct statfs *outStatFSBuf; - n += __builtin_object_size(outStatFSBuf->f_mntonname ? "" : "", 1); // expected-warning{{address of array}} - n += __builtin_object_size(outStatFSBuf->f_mntonname ?: "", 1); + n += OBJECT_SIZE_BUILTIN(outStatFSBuf->f_mntonname ? "" : "", 1); // expected-warning{{address of array}} + n += OBJECT_SIZE_BUILTIN(outStatFSBuf->f_mntonname ?: "", 1); return n; } @@ -104,7 +111,7 @@ typedef struct { void rd36094951_IAS_builtin_object_size_assertion(IncompleteArrayStruct *p) { #define rd36094951_CHECK(mode) \ __builtin___strlcpy_chk(p->session[0].string, "ab", 2, \ - __builtin_object_size(p->session[0].string, mode)) + OBJECT_SIZE_BUILTIN(p->session[0].string, mode)) rd36094951_CHECK(0); rd36094951_CHECK(1); rd36094951_CHECK(2); diff --git a/test/Sema/builtins-arm64-mte.c b/test/Sema/builtins-arm64-mte.c new file mode 100644 index 0000000000..4f87eb000b --- /dev/null +++ b/test/Sema/builtins-arm64-mte.c @@ -0,0 +1,136 @@ +// RUN: %clang_cc1 -triple arm64-arm-eabi %s -target-feature +mte -fsyntax-only -verify +// RUN: %clang_cc1 -triple arm64-arm-eabi %s -target-feature +mte -x c++ -fsyntax-only -verify +#include <stddef.h> +#include <arm_acle.h> + +int *create_tag1(int a, unsigned b) { + // expected-error@+1 {{first argument of MTE builtin function must be a pointer ('int' invalid)}} + return __arm_mte_create_random_tag(a,b); +} + +int *create_tag2(int *a, unsigned *b) { + // expected-error@+1 {{second argument of MTE builtin function must be an integer type ('unsigned int *' invalid)}} + return __arm_mte_create_random_tag(a,b); +} + +int *create_tag3(const int *a, unsigned b) { +#ifdef __cplusplus + // expected-error@+1 {{cannot initialize return object of type 'int *' with an rvalue of type 'const int *'}} + return __arm_mte_create_random_tag(a,b); +#else + // expected-warning@+1 {{returning 'const int *' from a function with result type 'int *' discards qualifiers}} + return __arm_mte_create_random_tag(a,b); +#endif +} + +int *create_tag4(volatile int *a, unsigned b) { +#ifdef __cplusplus + // expected-error@+1 {{cannot initialize return object of type 'int *' with an rvalue of type 'volatile int *'}} + return __arm_mte_create_random_tag(a,b); +#else + // expected-warning@+1 {{returning 'volatile int *' from a function with result type 'int *' discards qualifiers}} + return __arm_mte_create_random_tag(a,b); +#endif +} + +int *increment_tag1(int *a, unsigned b) { + // expected-error@+1 {{argument to '__builtin_arm_addg' must be a constant integer}} + return __arm_mte_increment_tag(a,b); +} + +int *increment_tag2(int *a) { + // expected-error@+1 {{argument value 16 is outside the valid range [0, 15]}} + return __arm_mte_increment_tag(a,16); +} + +int *increment_tag3(int *a) { + // expected-error@+1 {{argument value -1 is outside the valid range [0, 15]}} + return __arm_mte_increment_tag(a,-1); +} + +int *increment_tag4(const int *a) { +#ifdef __cplusplus + // expected-error@+1 {{cannot initialize return object of type 'int *' with an rvalue of type 'const int *'}} + return __arm_mte_increment_tag(a,5); +#else + // expected-warning@+1 {{returning 'const int *' from a function with result type 'int *' discards qualifiers}} + return __arm_mte_increment_tag(a,5); +#endif +} + +int *increment_tag5(const volatile int *a) { +#ifdef __cplusplus + // expected-error@+1 {{cannot initialize return object of type 'int *' with an rvalue of type 'const volatile int *'}} + return __arm_mte_increment_tag(a,5); +#else + // expected-warning@+1 {{returning 'const volatile int *' from a function with result type 'int *' discards qualifiers}} + return __arm_mte_increment_tag(a,5); +#endif +} + +unsigned exclude_tag1(int *ptr, unsigned m) { + // expected-error@+1 {{first argument of MTE builtin function must be a pointer ('int' invalid)}} + return __arm_mte_exclude_tag(*ptr, m); +} + +unsigned exclude_tag2(int *ptr, int *m) { + // expected-error@+1 {{second argument of MTE builtin function must be an integer type ('int *' invalid)}} + return __arm_mte_exclude_tag(ptr, m); +} + +void get_tag1() { + // expected-error@+1 {{too few arguments to function call, expected 1, have 0}} + __arm_mte_get_tag(); +} + +int *get_tag2(int ptr) { + // expected-error@+1 {{first argument of MTE builtin function must be a pointer ('int' invalid)}} + return __arm_mte_get_tag(ptr); +} + +int *get_tag3(const volatile int *ptr) { +#ifdef __cplusplus + // expected-error@+1 {{cannot initialize return object of type 'int *' with an rvalue of type 'const volatile int *'}} + return __arm_mte_get_tag(ptr); +#else + // expected-warning@+1 {{returning 'const volatile int *' from a function with result type 'int *' discards qualifiers}} + return __arm_mte_get_tag(ptr); +#endif +} + +void set_tag1() { + // expected-error@+1 {{too few arguments to function call, expected 1, have 0}} + __arm_mte_set_tag(); +} + +void set_tag2(int ptr) { + // expected-error@+1 {{first argument of MTE builtin function must be a pointer ('int' invalid)}} + __arm_mte_set_tag(ptr); +} + +ptrdiff_t subtract_pointers1(int a, int *b) { + // expected-error@+1 {{first argument of MTE builtin function must be a null or a pointer ('int' invalid)}} + return __arm_mte_ptrdiff(a, b); +} + +ptrdiff_t subtract_pointers2(int *a, int b) { + // expected-error@+1 {{second argument of MTE builtin function must be a null or a pointer ('int' invalid)}} + return __arm_mte_ptrdiff(a, b); +} + +ptrdiff_t subtract_pointers3(char *a, int *b) { + // expected-error@+1 {{'char *' and 'int *' are not pointers to compatible types}} + return __arm_mte_ptrdiff(a, b); +} + +ptrdiff_t subtract_pointers4(int *a, char *b) { + // expected-error@+1 {{'int *' and 'char *' are not pointers to compatible types}} + return __arm_mte_ptrdiff(a, b); +} + +#ifdef __cplusplus +ptrdiff_t subtract_pointers5() { + // expected-error@+1 {{at least one argument of MTE builtin function must be a pointer ('nullptr_t', 'nullptr_t' invalid)}} + return __arm_mte_ptrdiff(nullptr, nullptr); +} +#endif diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c index 62992c0a47..1d41bcf9f0 100644 --- a/test/Sema/builtins.c +++ b/test/Sema/builtins.c @@ -230,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 has size 20, but size argument is 40}} + // expected-warning {{'strlcpy' 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 has size 20, but size argument is 40}} + // expected-warning {{'strlcat' will always overflow; destination buffer has size 20, but size argument is 40}} } // rdar://11076881 @@ -245,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 has size 4, but size argument is 5}} + __builtin___memcpy_chk (&buf[6], in, 5, __builtin_object_size (&buf[6], 0)); // expected-warning {{'memcpy' will always overflow; destination buffer has size 4, but size argument is 5}} __builtin___memcpy_chk (p, "abcde", n, __builtin_object_size (p, 0)); @@ -253,7 +253,7 @@ 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 has size 4, but size argument is 5}} + __builtin___memcpy_chk (&buf[6], "abcde", 5, __builtin_object_size (&buf[6], 0)); // expected-warning {{'memcpy' will always overflow; destination buffer has size 4, but size argument is 5}} return buf; } @@ -312,5 +312,11 @@ 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}} + my_memcpy(buf, src, 11); // expected-warning{{'memcpy' will always overflow; destination buffer has size 10, but size argument is 11}} +} + +// Test that __builtin_is_constant_evaluated() is not allowed in C +int test_cxx_builtin() { + // expected-error@+1 {{use of unknown builtin '__builtin_is_constant_evaluated'}} + return __builtin_is_constant_evaluated(); } diff --git a/test/Sema/callingconv-iamcu.c b/test/Sema/callingconv-iamcu.c index b66320ecf8..2c99b029b6 100644 --- a/test/Sema/callingconv-iamcu.c +++ b/test/Sema/callingconv-iamcu.c @@ -1,35 +1,35 @@ // RUN: %clang_cc1 %s -fsyntax-only -triple i686-intel-elfiamcu -verify -void __attribute__((fastcall)) foo(float *a) { // expected-warning {{calling convention 'fastcall' ignored for this target}} +void __attribute__((fastcall)) foo(float *a) { // expected-warning {{'fastcall' calling convention ignored for this target}} } -void __attribute__((stdcall)) bar(float *a) { // expected-warning {{calling convention 'stdcall' ignored for this target}} +void __attribute__((stdcall)) bar(float *a) { // expected-warning {{'stdcall' calling convention ignored for this target}} } void __attribute__((fastcall(1))) baz(float *a) { // expected-error {{'fastcall' attribute takes no arguments}} } -void __attribute__((fastcall)) test2(int a, ...) { // expected-warning {{calling convention 'fastcall' ignored for this target}} +void __attribute__((fastcall)) test2(int a, ...) { // expected-warning {{'fastcall' calling convention ignored for this target}} } -void __attribute__((stdcall)) test3(int a, ...) { // expected-warning {{calling convention 'stdcall' ignored for this target}} +void __attribute__((stdcall)) test3(int a, ...) { // expected-warning {{'stdcall' calling convention ignored for this target}} } -void __attribute__((thiscall)) test4(int a, ...) { // expected-warning {{calling convention 'thiscall' ignored for this target}} +void __attribute__((thiscall)) test4(int a, ...) { // expected-warning {{'thiscall' calling convention ignored for this target}} } void __attribute__((cdecl)) ctest0() {} void __attribute__((cdecl(1))) ctest1(float x) {} // expected-error {{'cdecl' attribute takes no arguments}} -void (__attribute__((fastcall)) *pfoo)(float*) = foo; // expected-warning {{calling convention 'fastcall' ignored for this target}} +void (__attribute__((fastcall)) *pfoo)(float*) = foo; // expected-warning {{'fastcall' calling convention ignored for this target}} -void (__attribute__((stdcall)) *pbar)(float*) = bar; // expected-warning {{calling convention 'stdcall' ignored for this target}} +void (__attribute__((stdcall)) *pbar)(float*) = bar; // expected-warning {{'stdcall' calling convention ignored for this target}} void (*pctest0)() = ctest0; void ctest2() {} void (__attribute__((cdecl)) *pctest2)() = ctest2; -typedef void (__attribute__((fastcall)) *Handler) (float *); // expected-warning {{calling convention 'fastcall' ignored for this target}} +typedef void (__attribute__((fastcall)) *Handler) (float *); // expected-warning {{'fastcall' calling convention ignored for this target}} Handler H = foo; int __attribute__((pcs("aapcs", "aapcs"))) pcs1(void); // expected-error {{'pcs' attribute takes one argument}} @@ -38,16 +38,16 @@ int __attribute__((pcs(pcs1))) pcs3(void); // expected-error {{'pcs' attribute r // expected-error {{invalid PCS type}} int __attribute__((pcs(0))) pcs4(void); // expected-error {{'pcs' attribute requires a string}} /* These are ignored because the target is i386 and not ARM */ -int __attribute__((pcs("aapcs"))) pcs5(void); // expected-warning {{calling convention 'pcs' ignored for this target}} -int __attribute__((pcs("aapcs-vfp"))) pcs6(void); // expected-warning {{calling convention 'pcs' ignored for this target}} +int __attribute__((pcs("aapcs"))) pcs5(void); // expected-warning {{'pcs' calling convention ignored for this target}} +int __attribute__((pcs("aapcs-vfp"))) pcs6(void); // expected-warning {{'pcs' calling convention ignored for this target}} int __attribute__((pcs("foo"))) pcs7(void); // expected-error {{invalid PCS type}} void ctest3(); void __attribute__((cdecl)) ctest3() {} -typedef __attribute__((stdcall)) void (*PROC)(); // expected-warning {{calling convention 'stdcall' ignored for this target}} +typedef __attribute__((stdcall)) void (*PROC)(); // expected-warning {{'stdcall' calling convention ignored for this target}} PROC __attribute__((cdecl)) ctest4(const char *x) {} -void __attribute__((intel_ocl_bicc)) inteloclbifunc(float *a) {} // expected-warning {{calling convention 'intel_ocl_bicc' ignored for this target}} +void __attribute__((intel_ocl_bicc)) inteloclbifunc(float *a) {} // expected-warning {{'intel_ocl_bicc' calling convention ignored for this target}} -struct type_test {} __attribute__((stdcall)); // expected-warning {{calling convention 'stdcall' ignored for this target}} expected-warning {{'stdcall' attribute only applies to functions and methods}} +struct type_test {} __attribute__((stdcall)); // expected-warning {{'stdcall' calling convention ignored for this target}} expected-warning {{'stdcall' attribute only applies to functions and methods}} diff --git a/test/Sema/callingconv.c b/test/Sema/callingconv.c index 8b64bee047..e6d6ad2c12 100644 --- a/test/Sema/callingconv.c +++ b/test/Sema/callingconv.c @@ -47,11 +47,11 @@ int __attribute__((pcs(pcs1))) pcs3(void); // expected-error {{'pcs' attribute r // expected-error {{invalid PCS type}} int __attribute__((pcs(0))) pcs4(void); // expected-error {{'pcs' attribute requires a string}} /* These are ignored because the target is i386 and not ARM */ -int __attribute__((pcs("aapcs"))) pcs5(void); // expected-warning {{calling convention 'pcs' ignored for this target}} -int __attribute__((pcs("aapcs-vfp"))) pcs6(void); // expected-warning {{calling convention 'pcs' ignored for this target}} +int __attribute__((pcs("aapcs"))) pcs5(void); // expected-warning {{'pcs' calling convention ignored for this target}} +int __attribute__((pcs("aapcs-vfp"))) pcs6(void); // expected-warning {{'pcs' calling convention 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}} +int __attribute__((aarch64_vector_pcs)) aavpcs(void); // expected-warning {{'aarch64_vector_pcs' calling convention ignored for this target}} // PR6361 void ctest3(); @@ -68,3 +68,5 @@ typedef_fun_t typedef_fun; // expected-note {{previous declaration is here}} void __attribute__((stdcall)) typedef_fun(int x) { } // expected-error {{function declared 'stdcall' here was previously declared without calling convention}} struct type_test {} __attribute__((stdcall)); // expected-warning {{'stdcall' attribute only applies to functions and methods}} + +void __vectorcall __builtin_unreachable(); // expected-warning {{vectorcall calling convention ignored on builtin function}} diff --git a/test/Sema/compare.c b/test/Sema/compare.c index b2b486f59f..25aa13f6ba 100644 --- a/test/Sema/compare.c +++ b/test/Sema/compare.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtautological-constant-in-range-compare %s -Wno-unreachable-code +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtype-limits %s -Wno-unreachable-code int test(char *C) { // nothing here should warn. return C != ((void*)0); diff --git a/test/Sema/conversion-target-dep.c b/test/Sema/conversion-target-dep.c new file mode 100644 index 0000000000..e16685fa06 --- /dev/null +++ b/test/Sema/conversion-target-dep.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -Wdouble-promotion -Wimplicit-float-conversion %s -triple x86_64-apple-macosx10.12 -verify=x86,expected +// RUN: %clang_cc1 -Wdouble-promotion -Wimplicit-float-conversion %s -triple armv7-apple-ios9.0 -verify=arm,expected + +// On ARM, long double and double both map to double precision 754s, so there +// isn't any reason to warn on conversions back and forth. + +long double ld; +double d; +_Float16 f16; // x86-error {{_Float16 is not supported on this target}} + +int main() { + ld = d; // x86-warning {{implicit conversion increases floating-point precision: 'double' to 'long double'}} + d = ld; // x86-warning {{implicit conversion loses floating-point precision: 'long double' to 'double'}} + + ld += d; // x86-warning {{implicit conversion increases floating-point precision: 'double' to 'long double'}} + d += ld; // x86-warning {{implicit conversion when assigning computation result loses floating-point precision: 'long double' to 'double'}} + + f16 = ld; // expected-warning {{implicit conversion loses floating-point precision: 'long double' to '_Float16'}} + ld = f16; // expected-warning {{implicit conversion increases floating-point precision: '_Float16' to 'long double'}} + + f16 += ld; // expected-warning {{implicit conversion when assigning computation result loses floating-point precision: 'long double' to '_Float16'}} + ld += f16; // expected-warning {{implicit conversion increases floating-point precision: '_Float16' to 'long double'}} +} + diff --git a/test/Sema/crash-deduction-guide-access.cpp b/test/Sema/crash-deduction-guide-access.cpp new file mode 100644 index 0000000000..c0203ef8c5 --- /dev/null +++ b/test/Sema/crash-deduction-guide-access.cpp @@ -0,0 +1,11 @@ +// RUN: not %clang_cc1 -x c++ -std=c++17 -fsyntax-only %s +template <typename U> +class Imp { + template <typename F> + explicit Imp(F f); +}; + +template <typename T> +class Cls { + explicit Imp() : f() {} +}; diff --git a/test/Sema/dllexport-1.cpp b/test/Sema/dllexport-1.cpp new file mode 100644 index 0000000000..6180d35669 --- /dev/null +++ b/test/Sema/dllexport-1.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -fms-extensions -verify %s +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsyntax-only -fms-extensions -verify %s -DMSVC + +// Export const variable initialization. + +#ifdef MSVC +// expected-no-diagnostics +#endif + +#ifndef MSVC +// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}} +#endif +__declspec(dllexport) int const x = 3; + +namespace { +namespace named { +#ifndef MSVC +// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}} +#endif +__declspec(dllexport) int const x = 3; +} +} // namespace + +namespace named1 { +namespace { +namespace named { +#ifndef MSVC +// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}} +#endif +__declspec(dllexport) int const x = 3; +} +} // namespace +} // namespace named1 diff --git a/test/Sema/dllexport-2.cpp b/test/Sema/dllexport-2.cpp new file mode 100644 index 0000000000..41d96cc4e6 --- /dev/null +++ b/test/Sema/dllexport-2.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -fms-extensions -verify %s +// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsyntax-only -fms-extensions -verify %s -DMSVC + +// Export const variable. + +#ifdef MSVC +// expected-error@+4 {{'j' must have external linkage when declared 'dllexport'}} +#else +// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}} +#endif +__declspec(dllexport) int const j; // expected-error {{default initialization of an object of const type 'const int'}} + +// With typedef +typedef const int CInt; + +#ifdef MSVC +// expected-error@+4 {{'j2' must have external linkage when declared 'dllexport'}} +#else +// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}} +#endif +__declspec(dllexport) CInt j2; //expected-error {{default initialization of an object of const type 'CInt'}} + +#ifndef MSVC +// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}} +#endif +__declspec(dllexport) CInt j3 = 3; diff --git a/test/Sema/enable_if.c b/test/Sema/enable_if.c index 9125bfaf0f..b4bb2ecd0d 100644 --- a/test/Sema/enable_if.c +++ b/test/Sema/enable_if.c @@ -21,12 +21,12 @@ void test1() { size_t __strnlen_chk(const char *s, size_t requested_amount, size_t s_len); -size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate function}} +size_t strnlen(const char *s, size_t maxlen) __attribute__((overloadable)) __asm__("strnlen_real1"); __attribute__((always_inline)) -inline size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate function}} +inline size_t strnlen(const char *s, size_t maxlen) __attribute__((overloadable)) __attribute__((enable_if(__builtin_object_size(s, 0) != -1, "chosen when target buffer size is known"))) @@ -34,7 +34,7 @@ inline size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate return __strnlen_chk(s, maxlen, __builtin_object_size(s, 0)); } -size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate disabled: chosen when 'maxlen' is known to be less than or equal to the buffer size}} +size_t strnlen(const char *s, size_t maxlen) __attribute__((overloadable)) __attribute__((enable_if(__builtin_object_size(s, 0) != -1, "chosen when target buffer size is known"))) @@ -42,7 +42,7 @@ size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate disabl "chosen when 'maxlen' is known to be less than or equal to the buffer size"))) __asm__("strnlen_real2"); -size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate function has been explicitly made unavailable}} +size_t strnlen(const char *s, size_t maxlen) // expected-note {{'strnlen' has been explicitly marked unavailable here}} __attribute__((overloadable)) __attribute__((enable_if(__builtin_object_size(s, 0) != -1, "chosen when target buffer size is known"))) @@ -62,12 +62,12 @@ void test2(const char *s, int i) { strnlen(c, i); // CHECK: call {{.*}}strnlen_chk #ifndef CODEGEN - strnlen(c, 999); // expected-error{{call to unavailable function 'strnlen': 'maxlen' is larger than the buffer size}} + strnlen(c, 999); // expected-error{{'strnlen' is unavailable: 'maxlen' is larger than the buffer size}} #endif } -int isdigit(int c) __attribute__((overloadable)); // expected-note{{candidate function}} -int isdigit(int c) __attribute__((overloadable)) // expected-note{{candidate function has been explicitly made unavailable}} +int isdigit(int c) __attribute__((overloadable)); +int isdigit(int c) __attribute__((overloadable)) // expected-note {{'isdigit' has been explicitly marked unavailable here}} __attribute__((enable_if(c <= -1 || c > 255, "'c' must have the value of an unsigned char or EOF"))) __attribute__((unavailable("'c' must have the value of an unsigned char or EOF"))); @@ -75,13 +75,13 @@ void test3(int c) { isdigit(c); // expected-warning{{ignoring return value of function declared with pure attribute}} isdigit(10); // expected-warning{{ignoring return value of function declared with pure attribute}} #ifndef CODEGEN - isdigit(-10); // expected-error{{call to unavailable function 'isdigit': 'c' must have the value of an unsigned char or EOF}} + isdigit(-10); // expected-error{{'isdigit' is unavailable: 'c' must have the value of an unsigned char or EOF}} #endif } // Verify that the alternate spelling __enable_if__ works as well. -int isdigit2(int c) __attribute__((overloadable)); // expected-note{{candidate function}} -int isdigit2(int c) __attribute__((overloadable)) // expected-note{{candidate function has been explicitly made unavailable}} +int isdigit2(int c) __attribute__((overloadable)); +int isdigit2(int c) __attribute__((overloadable)) // expected-note {{'isdigit2' has been explicitly marked unavailable here}} __attribute__((__enable_if__(c <= -1 || c > 255, "'c' must have the value of an unsigned char or EOF"))) __attribute__((unavailable("'c' must have the value of an unsigned char or EOF"))); @@ -89,7 +89,7 @@ void test4(int c) { isdigit2(c); isdigit2(10); #ifndef CODEGEN - isdigit2(-10); // expected-error{{call to unavailable function 'isdigit2': 'c' must have the value of an unsigned char or EOF}} + isdigit2(-10); // expected-error{{'isdigit2' is unavailable: 'c' must have the value of an unsigned char or EOF}} #endif } diff --git a/test/Sema/fixed-enum.c b/test/Sema/fixed-enum.c index 60a4bc474f..c77f5b0cbe 100644 --- a/test/Sema/fixed-enum.c +++ b/test/Sema/fixed-enum.c @@ -2,6 +2,7 @@ // 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 -pedantic -std=c11 -xc -DC11 -verify %s // RUN: %clang_cc1 -Weverything -std=c11 -xc -fms-extensions -DMS -verify %s enum X : int {e}; @@ -10,9 +11,29 @@ enum X : int {e}; #elif defined(CXX03) // expected-warning@-4{{enumeration types with a fixed underlying type are a C++11 extension}} #elif defined(OBJC) -// expected-no-diagnostics +// No diagnostic #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 + +// Don't warn about the forward declaration in any language mode. +enum Fwd : int; +enum Fwd : int { e2 }; +#ifndef OBJC +// expected-warning@-3 {{enumeration types with a fixed underlying type}} +// expected-warning@-3 {{enumeration types with a fixed underlying type}} +#endif + +// Always error on the incompatible redeclaration. +enum BadFwd : int; +#ifndef OBJC +// expected-warning@-2 {{enumeration types with a fixed underlying type}} +#endif +// expected-note@-4 {{previous declaration is here}} +enum BadFwd : char { e3 }; +#ifndef OBJC +// expected-warning@-2 {{enumeration types with a fixed underlying type}} +#endif +// expected-error@-4 {{enumeration redeclared with different underlying type 'char' (was 'int')}} diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index a9af8ce5de..e8acd40c8d 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -617,6 +617,8 @@ 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'}} + printf("%hlf", x); // expected-warning{{invalid conversion specifier 'l'}} + printf("%hld", x); // expected-warning{{invalid conversion specifier 'l'}} } // Test that we correctly merge the format in both orders. diff --git a/test/Sema/inline-asm-validate-x86.c b/test/Sema/inline-asm-validate-x86.c index f21ef6940a..c6fa2e1b4f 100644 --- a/test/Sema/inline-asm-validate-x86.c +++ b/test/Sema/inline-asm-validate-x86.c @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -triple i686 -fsyntax-only -verify %s -// RUN: %clang_cc1 -triple x86_64 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64 -fsyntax-only -verify -DAMD64 %s void I(int i, int j) { static const int BelowMin = -1; @@ -55,6 +55,8 @@ void K(int i, int j) { void L(int i, int j) { static const int Invalid1 = 1; static const int Invalid2 = 42; + static const int Invalid3 = 0; + static const long long Invalid4 = 0x1000000ff; static const int Valid1 = 0xff; static const int Valid2 = 0xffff; static const int Valid3 = 0xffffffff; @@ -69,6 +71,12 @@ void L(int i, int j) { : "0"(i), "L"(Invalid2)); // expected-error{{value '42' out of range for constraint 'L'}} __asm__("xorl %0,%2" : "=r"(i) + : "0"(i), "L"(Invalid3)); // expected-error{{value '0' out of range for constraint 'L'}} + __asm__("xorl %0,%2" + : "=r"(i) + : "0"(i), "L"(Invalid4)); // expected-error{{value '4294967551' out of range for constraint 'L'}} + __asm__("xorl %0,%2" + : "=r"(i) : "0"(i), "L"(Valid1)); // expected-no-error __asm__("xorl %0,%2" : "=r"(i) @@ -129,3 +137,21 @@ void O(int i, int j) { : "0"(i), "O"(64)); // expected-no-error } +void pr40890(void) { + struct s { + int a, b; + }; + static struct s s; + // This null pointer can be used as an integer constant expression. + __asm__ __volatile__("\n#define S_A abcd%0\n" : : "n"(&((struct s*)0)->a)); + // This offset-from-null pointer can be used as an integer constant expression. + __asm__ __volatile__("\n#define S_B abcd%0\n" : : "n"(&((struct s*)0)->b)); + // This pointer cannot be used as an integer constant expression. + __asm__ __volatile__("\n#define GLOBAL_A abcd%0\n" : : "n"(&s.a)); // expected-error{{constraint 'n' expects an integer constant expression}} + // Floating-point is also not okay. + __asm__ __volatile__("\n#define PI abcd%0\n" : : "n"(3.14f)); // expected-error{{constraint 'n' expects an integer constant expression}} +#ifdef AMD64 + // This arbitrary pointer is fine. + __asm__ __volatile__("\n#define BEEF abcd%0\n" : : "n"((int*)0xdeadbeeeeeef)); +#endif +} diff --git a/test/Sema/overloadable.c b/test/Sema/overloadable.c index 4bdec85f9c..61ef3fddaf 100644 --- a/test/Sema/overloadable.c +++ b/test/Sema/overloadable.c @@ -41,16 +41,15 @@ void test_struct(struct X x, struct Y y) { double *f(int) __attribute__((overloadable)); // expected-error{{conflicting types for 'f'}} -double promote(float) __attribute__((__overloadable__)); // expected-note {{candidate}} -double promote(double) __attribute__((__overloadable__)); // expected-note {{candidate}} -long double promote(long double) __attribute__((__overloadable__)); // expected-note {{candidate}} +double promote(float) __attribute__((__overloadable__)); +double promote(double) __attribute__((__overloadable__)); +long double promote(long double) __attribute__((__overloadable__)); -void promote(...) __attribute__((__overloadable__, __unavailable__)); // \ - // expected-note{{candidate function}} +void promote(...) __attribute__((__overloadable__, __unavailable__)); // expected-note {{marked unavailable here}} void test_promote(short* sp) { promote(1.0); - promote(sp); // expected-error{{call to unavailable function 'promote'}} + promote(sp); // expected-error{{'promote' is unavailable}} } // PR6600 diff --git a/test/Sema/pass-object-size.c b/test/Sema/pass-object-size.c index 0745105df8..445d20ba6f 100644 --- a/test/Sema/pass-object-size.c +++ b/test/Sema/pass-object-size.c @@ -17,6 +17,9 @@ void h(char *p __attribute__((pass_object_size(0)))) {} //expected-error{{pass_o void i(char *p __attribute__((pass_object_size(0)))); // OK -- const is only necessary on definitions, not decls. void j(char *p __attribute__((pass_object_size(0), pass_object_size(1)))); //expected-error{{'pass_object_size' attribute can only be applied once per parameter}} +void k(char *p __attribute__((pass_dynamic_object_size))); // expected-error {{'pass_dynamic_object_size' attribute takes one argument}} +void l(int p __attribute__((pass_dynamic_object_size(0)))); // expected-error {{'pass_dynamic_object_size' attribute only applies to constant pointer arguments}} + #define PS(N) __attribute__((pass_object_size(N))) #define overloaded __attribute__((overloadable)) void Overloaded(void *p PS(0)) overloaded; //expected-note{{previous declaration is here}} @@ -32,14 +35,17 @@ void TakeFnOvl(void (*)(void *)) overloaded; void TakeFnOvl(void (*)(int *)) overloaded; void NotOverloaded(void *p PS(0)); -void IsOverloaded(void *p PS(0)) overloaded; -void IsOverloaded(char *p) overloaded; // char* inestead of void* is intentional +void IsOverloaded(void *p PS(0)) overloaded; // expected-note 2 {{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} + +// char* inestead of void* is intentional +void IsOverloaded(char *p) overloaded; // expected-note{{passing argument to parameter 'p' here}} expected-note 2 {{type mismatch}} + void FunctionPtrs() { void (*p)(void *) = NotOverloaded; //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}} void (*p2)(void *) = &NotOverloaded; //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}} - void (*p3)(void *) = IsOverloaded; //expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}} expected-note@-6{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@-5{{type mismatch}} - void (*p4)(void *) = &IsOverloaded; //expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}} expected-note@-7{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@-6{{type mismatch}} + void (*p3)(void *) = IsOverloaded; //expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}} + void (*p4)(void *) = &IsOverloaded; //expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}} void (*p5)(char *) = IsOverloaded; void (*p6)(char *) = &IsOverloaded; @@ -52,5 +58,11 @@ void FunctionPtrs() { int P; (&NotOverloaded)(&P); //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}} - (&IsOverloaded)(&P); //expected-warning{{incompatible pointer types passing 'int *' to parameter of type 'char *'}} expected-note@36{{passing argument to parameter 'p' here}} + (&IsOverloaded)(&P); //expected-warning{{incompatible pointer types passing 'int *' to parameter of type 'char *'}} } + +void mismatch(void *p __attribute__((pass_object_size(0)))); // expected-note {{previous declaration is here}} +void mismatch(void *p __attribute__((pass_dynamic_object_size(0)))); // expected-error {{conflicting pass_object_size attributes on parameters}} + +void mismatch2(void *p __attribute__((pass_dynamic_object_size(0)))); // expected-note {{previous declaration is here}} +void mismatch2(void *p __attribute__((pass_dynamic_object_size(1)))); // expected-error {{conflicting pass_object_size attributes on parameters}} diff --git a/test/Sema/pr25786.c b/test/Sema/pr25786.c index 2ce65311a2..bfc2b35ede 100644 --- a/test/Sema/pr25786.c +++ b/test/Sema/pr25786.c @@ -2,8 +2,8 @@ // RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fsyntax-only -verify %s #if TEST -void (__attribute__((regparm(3), stdcall)) *pf) (); //expected-warning {{calling convention 'stdcall' ignored for this target}} -void (__attribute__((regparm(2), stdcall)) foo)(int a) { //expected-warning {{calling convention 'stdcall' ignored for this target}} +void (__attribute__((regparm(3), stdcall)) *pf) (); //expected-warning {{'stdcall' calling convention ignored for this target}} +void (__attribute__((regparm(2), stdcall)) foo)(int a) { //expected-warning {{'stdcall' calling convention ignored for this target}} } #else //expected-no-diagnostics diff --git a/test/Sema/pragma-attribute-strict-subjects.c b/test/Sema/pragma-attribute-strict-subjects.c index a84e2bde38..42e3e20e76 100644 --- a/test/Sema/pragma-attribute-strict-subjects.c +++ b/test/Sema/pragma-attribute-strict-subjects.c @@ -56,7 +56,8 @@ #pragma clang attribute pop #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(enum_constant, function, record(unless(is_union)), variable, variable(is_parameter))) -// expected-error@-1 {{attribute 'abi_tag' can't be applied to 'variable(is_parameter)', and 'enum_constant'}} +// FIXME: comma in this diagnostic is wrong. +// expected-error@-2 {{attribute 'abi_tag' can't be applied to 'enum_constant', and 'variable(is_parameter)'}} #pragma clang attribute pop #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), enum)) diff --git a/test/Sema/shift.c b/test/Sema/shift.c index 47744fb049..63c9538249 100644 --- a/test/Sema/shift.c +++ b/test/Sema/shift.c @@ -20,6 +20,9 @@ void test() { c = 1 >> -0; c = 1 << -1; // expected-warning {{shift count is negative}} c = 1 >> -1; // expected-warning {{shift count is negative}} + c = 1 << (unsigned)-1; // expected-warning {{shift count >= width of type}} + // expected-warning@-1 {{implicit conversion}} + c = 1 >> (unsigned)-1; // expected-warning {{shift count >= width of type}} c = 1 << c; c <<= 0; c >>= 0; diff --git a/test/Sema/static-array.c b/test/Sema/static-array.c index 304485d5af..cc1043fe9c 100644 --- a/test/Sema/static-array.c +++ b/test/Sema/static-array.c @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -fsyntax-only -fblocks -verify %s void cat0(int a[static 0]) {} // expected-warning {{'static' has no effect on zero-length arrays}} -void cat(int a[static 3]) {} // expected-note 2 {{callee declares array parameter as static here}} +void cat(int a[static 3]) {} // expected-note 4 {{callee declares array parameter as static here}} expected-note 2 {{passing argument to parameter 'a' here}} void vat(int i, int a[static i]) {} // expected-note {{callee declares array parameter as static here}} @@ -19,6 +19,14 @@ void f(int *p) { vat(1, 0); // expected-warning {{null passed to a callee that requires a non-null argument}} vat(3, b); + + char d[4]; + cat((int *)d); // expected-warning {{array argument is too small; is of size 4, callee requires at least 12}} + cat(d); // expected-warning {{array argument is too small; is of size 4, callee requires at least 12}} expected-warning {{incompatible pointer types}} + + char e[12]; + cat((int *)e); + cat(e); // expected-warning {{incompatible pointer types}} } diff --git a/test/Sema/stdcall-fastcall-x64.c b/test/Sema/stdcall-fastcall-x64.c index d2a475eda1..e2e39e434f 100644 --- a/test/Sema/stdcall-fastcall-x64.c +++ b/test/Sema/stdcall-fastcall-x64.c @@ -5,16 +5,16 @@ int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' only applies t int __attribute__((fastcall)) var2; // expected-warning{{'fastcall' only applies to function types; type here is 'int'}} // Different CC qualifiers are not compatible -void __attribute__((stdcall, fastcall)) foo3(void); // expected-warning{{calling convention 'stdcall' ignored for this target}} expected-warning {{calling convention 'fastcall' ignored for this target}} -void __attribute__((stdcall)) foo4(); // expected-warning{{calling convention 'stdcall' ignored for this target}} -void __attribute__((fastcall)) foo4(void); // expected-warning {{calling convention 'fastcall' ignored for this target}} +void __attribute__((stdcall, fastcall)) foo3(void); // expected-warning{{'stdcall' calling convention ignored for this target}} expected-warning {{'fastcall' calling convention ignored for this target}} +void __attribute__((stdcall)) foo4(); // expected-warning{{'stdcall' calling convention ignored for this target}} +void __attribute__((fastcall)) foo4(void); // expected-warning {{'fastcall' calling convention ignored for this target}} // rdar://8876096 -void rdar8876096foo1(int i, int j) __attribute__((fastcall, cdecl)); // expected-warning{{calling convention 'fastcall' ignored for this target}} -void rdar8876096foo2(int i, int j) __attribute__((fastcall, stdcall)); // expected-warning{{calling convention 'stdcall' ignored for this target}} expected-warning {{calling convention 'fastcall' ignored for this target}} -void rdar8876096foo3(int i, int j) __attribute__((fastcall, regparm(2))); // expected-warning {{calling convention 'fastcall' ignored for this target}} -void rdar8876096foo4(int i, int j) __attribute__((stdcall, cdecl)); // expected-warning{{calling convention 'stdcall' ignored for this target}} -void rdar8876096foo5(int i, int j) __attribute__((stdcall, fastcall)); // expected-warning{{calling convention 'stdcall' ignored for this target}} expected-warning {{calling convention 'fastcall' ignored for this target}} -void rdar8876096foo6(int i, int j) __attribute__((cdecl, fastcall)); // expected-warning {{calling convention 'fastcall' ignored for this target}} -void rdar8876096foo7(int i, int j) __attribute__((cdecl, stdcall)); // expected-warning{{calling convention 'stdcall' ignored for this target}} -void rdar8876096foo8(int i, int j) __attribute__((regparm(2), fastcall)); // expected-warning {{calling convention 'fastcall' ignored for this target}} +void rdar8876096foo1(int i, int j) __attribute__((fastcall, cdecl)); // expected-warning{{'fastcall' calling convention ignored for this target}} +void rdar8876096foo2(int i, int j) __attribute__((fastcall, stdcall)); // expected-warning{{'stdcall' calling convention ignored for this target}} expected-warning {{'fastcall' calling convention ignored for this target}} +void rdar8876096foo3(int i, int j) __attribute__((fastcall, regparm(2))); // expected-warning {{'fastcall' calling convention ignored for this target}} +void rdar8876096foo4(int i, int j) __attribute__((stdcall, cdecl)); // expected-warning{{'stdcall' calling convention ignored for this target}} +void rdar8876096foo5(int i, int j) __attribute__((stdcall, fastcall)); // expected-warning{{'stdcall' calling convention ignored for this target}} expected-warning {{'fastcall' calling convention ignored for this target}} +void rdar8876096foo6(int i, int j) __attribute__((cdecl, fastcall)); // expected-warning {{'fastcall' calling convention ignored for this target}} +void rdar8876096foo7(int i, int j) __attribute__((cdecl, stdcall)); // expected-warning{{'stdcall' calling convention ignored for this target}} +void rdar8876096foo8(int i, int j) __attribute__((regparm(2), fastcall)); // expected-warning {{'fastcall' calling convention ignored for this target}} diff --git a/test/Sema/tautological-constant-compare.c b/test/Sema/tautological-constant-compare.c index b242f35dc6..4f9b43b9f8 100644 --- a/test/Sema/tautological-constant-compare.c +++ b/test/Sema/tautological-constant-compare.c @@ -2,6 +2,8 @@ // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtautological-constant-in-range-compare -DTEST -verify -x c++ %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtautological-type-limit-compare -DTEST -verify %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtautological-type-limit-compare -DTEST -verify -x c++ %s +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtype-limits -DTEST -verify %s +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtype-limits -DTEST -verify -x c++ %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra -Wno-sign-compare -verify %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra -Wno-sign-compare -verify -x c++ %s // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wall -verify %s diff --git a/test/Sema/tautological-constant-enum-compare.c b/test/Sema/tautological-constant-enum-compare.c index 99481c7adb..dcac245738 100644 --- a/test/Sema/tautological-constant-enum-compare.c +++ b/test/Sema/tautological-constant-enum-compare.c @@ -2,6 +2,8 @@ // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -Wtautological-constant-in-range-compare -verify %s // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -DSILENCE -Wno-tautological-constant-compare -verify %s // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -DSILENCE -Wno-tautological-constant-compare -verify %s +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -Wtype-limits -verify %s +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -DSILENCE -Wno-type-limits -verify %s int main() { enum A { A_a = 2 }; diff --git a/test/Sema/transpose-memset.c b/test/Sema/transpose-memset.c index 6112fde340..daad3f02c1 100644 --- a/test/Sema/transpose-memset.c +++ b/test/Sema/transpose-memset.c @@ -10,7 +10,7 @@ int *ptr; int main() { memset(array, sizeof(array), 0); // expected-warning{{'size' argument to memset is '0'; did you mean to transpose the last two arguments?}} expected-note{{parenthesize the third argument to silence}} - memset(array, sizeof(array), 0xff); // expected-warning{{setting buffer to a 'sizeof' expression; did you mean to transpose the last two arguments?}} expected-note{{cast the second argument to 'int' to silence}} + memset(array, sizeof(array), 0xff); // expected-warning{{setting buffer to a 'sizeof' expression; did you mean to transpose the last two arguments?}} expected-note{{cast the second argument to 'int' to silence}} expected-warning{{'memset' will always overflow; destination buffer has size 40, but size argument is 255}} memset(ptr, sizeof(ptr), 0); // expected-warning{{'size' argument to memset is '0'; did you mean to transpose the last two arguments?}} expected-note{{parenthesize the third argument to silence}} memset(ptr, sizeof(*ptr) * 10, 1); // expected-warning{{setting buffer to a 'sizeof' expression; did you mean to transpose the last two arguments?}} expected-note{{cast the second argument to 'int' to silence}} memset(ptr, 10 * sizeof(int *), 1); // expected-warning{{setting buffer to a 'sizeof' expression; did you mean to transpose the last two arguments?}} expected-note{{cast the second argument to 'int' to silence}} diff --git a/test/Sema/typo-correction.c b/test/Sema/typo-correction.c index e7992ac90b..73ba265509 100644 --- a/test/Sema/typo-correction.c +++ b/test/Sema/typo-correction.c @@ -100,3 +100,18 @@ void rdar38642201_caller() { structVar1.fieldName1.member1, //expected-error{{use of undeclared identifier 'structVar1'}} structVar2.fieldName2.member2); //expected-error{{use of undeclared identifier 'structVar2'}} } + +void PR40286_g(int x, int y); +void PR40286_h(int x, int y, int z); +void PR40286_1(int the_value) { + PR40286_g(the_walue); // expected-error {{use of undeclared identifier 'the_walue'}} +} +void PR40286_2(int the_value) { + PR40286_h(the_value, the_walue); // expected-error {{use of undeclared identifier 'the_walue'}} +} +void PR40286_3(int the_value) { + PR40286_h(the_walue); // expected-error {{use of undeclared identifier 'the_walue'}} +} +void PR40286_4(int the_value) { // expected-note {{'the_value' declared here}} + PR40286_h(the_value, the_value, the_walue); // expected-error {{use of undeclared identifier 'the_walue'; did you mean 'the_value'?}} +} diff --git a/test/Sema/varargs-aix.c b/test/Sema/varargs-aix.c new file mode 100644 index 0000000000..5aaa209069 --- /dev/null +++ b/test/Sema/varargs-aix.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -triple powerpc-ibm-aix +// RUN: %clang_cc1 -fsyntax-only -verify %s -triple powerpc64-ibm-aix +// expected-no-diagnostics + +extern __builtin_va_list ap; +extern char *ap; diff --git a/test/Sema/warn-double-promotion.c b/test/Sema/warn-double-promotion.c index 0cf33e84b4..5742a4fb3c 100644 --- a/test/Sema/warn-double-promotion.c +++ b/test/Sema/warn-double-promotion.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only %s -Wdouble-promotion +// RUN: %clang_cc1 -triple x86_64-apple-darwin -verify -fsyntax-only %s -Wdouble-promotion float ReturnFloatFromDouble(double d) { return d; diff --git a/test/Sema/warn-fortify-source.c b/test/Sema/warn-fortify-source.c new file mode 100644 index 0000000000..d9c21c0842 --- /dev/null +++ b/test/Sema/warn-fortify-source.c @@ -0,0 +1,119 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_PASS_OBJECT_SIZE +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS +// RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify +// RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_PASS_OBJECT_SIZE +// RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS + +typedef unsigned long size_t; + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(USE_PASS_OBJECT_SIZE) +void *memcpy(void *dst, const void *src, size_t c); +static void *memcpy(void *dst __attribute__((pass_object_size(1))), const void *src, size_t c) __attribute__((overloadable)) __asm__("merp"); +static void *memcpy(void *const dst __attribute__((pass_object_size(1))), const void *src, size_t c) __attribute__((overloadable)) { + return 0; +} +#elif defined(USE_BUILTINS) +#define memcpy(x,y,z) __builtin_memcpy(x,y,z) +#else +void *memcpy(void *dst, const void *src, size_t c); +#endif + +#ifdef __cplusplus +} +#endif + +void call_memcpy() { + char dst[10]; + char src[20]; + memcpy(dst, src, 20); // expected-warning {{memcpy' will always overflow; destination buffer has size 10, but size argument is 20}} + + if (sizeof(dst) == sizeof(src)) + memcpy(dst, src, 20); // no warning, unreachable +} + +void call_memcpy_type() { + struct pair { + int first; + int second; + }; + struct pair p; + char buf[20]; + memcpy(&p.first, buf, 20); +#ifdef USE_PASS_OBJECT_SIZE + // Use the more strict checking mode on the pass_object_size attribute: + // expected-warning@-3 {{memcpy' will always overflow; destination buffer has size 4, but size argument is 20}} +#else + // Or just fallback to type 0: + // expected-warning@-6 {{memcpy' will always overflow; destination buffer has size 8, but size argument is 20}} +#endif +} + +void call_strncat() { + char s1[10], s2[20]; + __builtin_strncat(s2, s1, 20); + __builtin_strncat(s1, s2, 20); // expected-warning {{'strncat' size argument is too large; destination buffer has size 10, but size argument is 20}} +} + +void call_strncpy() { + char s1[10], s2[20]; + __builtin_strncpy(s2, s1, 20); + __builtin_strncpy(s1, s2, 20); // expected-warning {{'strncpy' size argument is too large; destination buffer has size 10, but size argument is 20}} +} + +void call_stpncpy() { + char s1[10], s2[20]; + __builtin_stpncpy(s2, s1, 20); + __builtin_stpncpy(s1, s2, 20); // expected-warning {{'stpncpy' size argument is too large; destination buffer has size 10, but size argument is 20}} +} + +void call_memmove() { + char s1[10], s2[20]; + __builtin_memmove(s2, s1, 20); + __builtin_memmove(s1, s2, 20); // expected-warning {{'memmove' will always overflow; destination buffer has size 10, but size argument is 20}} +} + +void call_memset() { + char buf[10]; + __builtin_memset(buf, 0xff, 10); + __builtin_memset(buf, 0xff, 11); // expected-warning {{'memset' will always overflow; destination buffer has size 10, but size argument is 11}} +} + +void call_snprintf() { + char buf[10]; + __builtin_snprintf(buf, 10, "merp"); + __builtin_snprintf(buf, 11, "merp"); // expected-warning {{'snprintf' size argument is too large; destination buffer has size 10, but size argument is 11}} +} + +void call_vsnprintf() { + char buf[10]; + __builtin_va_list list; + __builtin_vsnprintf(buf, 10, "merp", list); + __builtin_vsnprintf(buf, 11, "merp", list); // expected-warning {{'vsnprintf' size argument is too large; destination buffer has size 10, but size argument is 11}} +} + +#ifdef __cplusplus +template <class> struct S { + void mf() const { + __builtin_memset(const_cast<char *>(mv), 0, 0); + } + + char mv[10]; +}; + +template <int A, int B> +void call_memcpy_dep() { + char bufferA[A]; + char bufferB[B]; + memcpy(bufferA, bufferB, 10); // expected-warning{{'memcpy' will always overflow; destination buffer has size 9, but size argument is 10}} +} + +void call_call_memcpy() { + call_memcpy_dep<10, 9>(); + call_memcpy_dep<9, 10>(); // expected-note {{in instantiation of function template specialization 'call_memcpy_dep<9, 10>' requested here}} +} +#endif diff --git a/test/Sema/warn-strict-prototypes.c b/test/Sema/warn-strict-prototypes.c index 0c23b3b2c2..5565a09060 100644 --- a/test/Sema/warn-strict-prototypes.c +++ b/test/Sema/warn-strict-prototypes.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -verify %s +// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -Wno-implicit-function-declaration -verify %s // RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s // function declaration with unspecified params @@ -71,3 +71,9 @@ void __attribute__((cdecl)) foo12(d) // expected-warning {{this old-style functi // rdar://problem/33251668 void foo13(...) __attribute__((overloadable)); void foo13(...) __attribute__((overloadable)) {} + +// We should not generate a strict-prototype warning for an implicit +// declaration. Leave that up to the implicit-function-declaration warning. +void foo14(void) { + foo14_call(); // no-warning +} diff --git a/test/Sema/warn-strncat-size.c b/test/Sema/warn-strncat-size.c index dcc3367e94..c050dd1299 100644 --- a/test/Sema/warn-strncat-size.c +++ b/test/Sema/warn-strncat-size.c @@ -39,7 +39,7 @@ void test(char *src) { strncat(dest, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", sizeof(dest) - strlen(dest)); // expected-warning{{the value of the size argument in 'strncat' is too large, might lead to a buffer overflow}} expected-note {{change the argument to be the free space in the destination buffer minus the terminating null byte}} strncat((*s5)->f2[x], s2, sizeof(s2)); // expected-warning {{size argument in 'strncat' call appears to be size of the source}} expected-note {{change the argument to be the free space in the destination buffer minus the terminating null byte}} - strncat(s1+3, s2, sizeof(s2)); // expected-warning {{size argument in 'strncat' call appears to be size of the source}} + strncat(s1+3, s2, sizeof(s2)); // expected-warning {{size argument in 'strncat' call appears to be size of the source}} expected-warning {{strncat' size argument is too large; destination buffer has size 97, but size argument is 200}} strncat(s4.f1, s2, sizeof(s2)); // expected-warning {{size argument in 'strncat' call appears to be size of the source}} expected-note {{change the argument to be the free space in the destination buffer minus the terminating null byte}} } diff --git a/test/Sema/warn-thread-safety-analysis.c b/test/Sema/warn-thread-safety-analysis.c index 0a375b873e..11b314008c 100644 --- a/test/Sema/warn-thread-safety-analysis.c +++ b/test/Sema/warn-thread-safety-analysis.c @@ -77,7 +77,7 @@ int main() { Foo_fun1(1); // expected-warning{{calling function 'Foo_fun1' requires holding mutex 'mu2'}} \ expected-warning{{calling function 'Foo_fun1' requires holding mutex 'mu1' exclusively}} - mutex_exclusive_lock(&mu1); + mutex_exclusive_lock(&mu1); // expected-note{{mutex acquired here}} mutex_shared_lock(&mu2); Foo_fun1(1); @@ -117,11 +117,11 @@ int main() { (void)(*d_ == 1); mutex_unlock(foo_.mu_); - mutex_exclusive_lock(&mu1); + mutex_exclusive_lock(&mu1); // expected-note {{mutex acquired here}} mutex_shared_unlock(&mu1); // expected-warning {{releasing mutex 'mu1' using shared access, expected exclusive access}} mutex_exclusive_unlock(&mu1); // expected-warning {{releasing mutex 'mu1' that was not held}} - mutex_shared_lock(&mu1); + mutex_shared_lock(&mu1); // expected-note {{mutex acquired here}} mutex_exclusive_unlock(&mu1); // expected-warning {{releasing mutex 'mu1' using exclusive access, expected shared access}} mutex_shared_unlock(&mu1); // expected-warning {{releasing mutex 'mu1' that was not held}} diff --git a/test/Sema/warn-unsequenced.c b/test/Sema/warn-unsequenced.c index 70163dc0de..9654cda924 100644 --- a/test/Sema/warn-unsequenced.c +++ b/test/Sema/warn-unsequenced.c @@ -93,4 +93,13 @@ void test() { _Generic(++a, default: 0) + ++a; // ok sizeof(++a) + ++a; // ok _Alignof(++a) + ++a; // expected-warning {{extension}} + + __builtin_constant_p(f(++a, 0)) ? f(f(++a, 0), f(++a, 0)) : 0; + + if (0) ++a + ++a; // ok, unreachable +} + +void g(const char *p, int n) { + // This resembles code produced by some macros in glibc's <string.h>. + __builtin_constant_p(p) && __builtin_constant_p(++n) && (++n + ++n); } |