diff options
Diffstat (limited to 'gcc/testsuite/c-c++-common')
20 files changed, 324 insertions, 5 deletions
diff --git a/gcc/testsuite/c-c++-common/cilk-plus/AN/pr57490.c b/gcc/testsuite/c-c++-common/cilk-plus/AN/pr57490.c new file mode 100644 index 00000000000..db38b30b5f3 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cilk-plus/AN/pr57490.c @@ -0,0 +1,28 @@ +/* { dg-do run } */ +/* { dg-options "-fcilkplus" } */ + +const int n = 8; +float x[8], y[8], z[8]; +int main() { + int i = 0; + float x_sum =0; + for(i=1; i<=5; i+=4 ) { + x[0:n] = 3; + y[0:n] = i; + z[0:n] = 0; + (void)((__sec_reduce_add(x[0:n])==3*n) || (__builtin_abort (), 0)); + (void)((__sec_reduce_add(y[0:n])==i*n) || (__builtin_abort (), 0)); + (void)((__sec_reduce_add(z[0:n])==0) || (__builtin_abort (), 0)); + + if (x[0:n] >= y[0:n]) { + z[0:n] = x[0:n] - y[0:n]; + } else { + z[0:n] = x[0:n] + y[0:n]; + } + (void)((__sec_reduce_add(x[0:n])==3*n) || (__builtin_abort (), 0)); + (void)((__sec_reduce_add(y[0:n])==i*n) || (__builtin_abort (), 0)); + (void)((__sec_reduce_add(z[0:n])==(3>=i?3-i:3+i)*n) + || (__builtin_abort (), 0)); + } + return 0; +} diff --git a/gcc/testsuite/c-c++-common/gomp/pr58257.c b/gcc/testsuite/c-c++-common/gomp/pr58257.c new file mode 100644 index 00000000000..8f8d24a998a --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pr58257.c @@ -0,0 +1,15 @@ +/* PR middle-end/58257 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fopenmp -Wall" } */ + +int +foo (int n) +{ + int a[10][10]; + int x, y; +#pragma omp parallel for collapse(2) /* { dg-bogus "may be used uninitialized in this function" } */ + for (x = 0; x < n; x++) /* { dg-bogus "may be used uninitialized in this function" } */ + for (y = 0; y < n; y++) + a[x][y] = x + y * y; + return a[0][0]; +} diff --git a/gcc/testsuite/c-c++-common/opaque-vector.c b/gcc/testsuite/c-c++-common/opaque-vector.c new file mode 100644 index 00000000000..cad266e893b --- /dev/null +++ b/gcc/testsuite/c-c++-common/opaque-vector.c @@ -0,0 +1,22 @@ +#define B_TEST(TYPE) { TYPE v __attribute__((vector_size(16))); (void)((v < v) < v); } +#ifdef __cplusplus +#define T_TEST(TYPE) { TYPE s; TYPE v __attribute__((vector_size(16))); __typeof((v<v)[0]) iv __attribute__((vector_size(16))); (void)((iv ? s : s) < v); } +#else +#define T_TEST(TYPE) +#endif +#define T(TYPE) B_TEST(TYPE) T_TEST(TYPE) + +void f () +{ + T(short) + T(int) + T(long) + T(long long) + + T_TEST(float) + T_TEST(double) + /* Avoid trouble with non-power-of-two sizes. */ +#if !defined(__i386__) && !defined(__x86_64__) && !defined(__m68k__) && !defined(__ia64__) + T_TEST(long double) +#endif +} diff --git a/gcc/testsuite/c-c++-common/scal-to-vec1.c b/gcc/testsuite/c-c++-common/scal-to-vec1.c index beb450db624..52cc2e39af7 100644 --- a/gcc/testsuite/c-c++-common/scal-to-vec1.c +++ b/gcc/testsuite/c-c++-common/scal-to-vec1.c @@ -26,13 +26,13 @@ int main (int argc, char *argv[]) { int i = 12; double d = 3.; - v1 = i + v0; /* { dg-error "conversion of scalar \[^\\n\]* to vector" } */ + v1 = i + v0; /* { dg-error "conversion of scalar \[^\\n\]* to vector" "scalar to vector" { target { ! int16 } } } */ v1 = 99999 + v0; /* { dg-error "conversion of scalar \[^\\n\]* to vector" } */ - f1 = d + f0; /* { dg-error "conversion of scalar \[^\\n\]* to vector" } */ - f1 = 1.3 + f0; /* { dg-error "conversion of scalar \[^\\n\]* to vector" } */ + f1 = d + f0; /* { dg-error "conversion of scalar \[^\\n\]* to vector" "scalar to vector" { target { large_double } } } */ + f1 = 1.3 + f0; /* { dg-error "conversion of scalar \[^\\n\]* to vector" "scalar to vector" { target { large_double } } } */ f1 = sll + f0; /* { dg-error "conversion of scalar \[^\\n\]* to vector" } */ - f1 = ((int)998769576) + f0; /* { dg-error "conversion of scalar \[^\\n\]* to vector" } */ + f1 = ((int)998769576) + f0; /* { dg-error "conversion of scalar \[^\\n\]* to vector" "scalar to vector" { target { ! int16 } } } */ /* convert.c should take care of this. */ i1 = sfl + i0; /* { dg-error "can't convert value to a vector|invalid operands" } */ diff --git a/gcc/testsuite/c-c++-common/simulate-thread/bitfields-2.c b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-2.c index 392f779bad5..0b29ffb68d4 100644 --- a/gcc/testsuite/c-c++-common/simulate-thread/bitfields-2.c +++ b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-2.c @@ -1,4 +1,4 @@ -/* { dg-do link } */ +/* { dg-do link { target { ! int16 } } } */ /* { dg-options "--param allow-store-data-races=0" } */ /* { dg-final { simulate-thread } } */ diff --git a/gcc/testsuite/c-c++-common/ubsan/const-char-1.c b/gcc/testsuite/c-c++-common/ubsan/const-char-1.c new file mode 100644 index 00000000000..6c2c3f8c3aa --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/const-char-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=shift" } */ + +void +foo (void) +{ + int y = 1 << 2; + __builtin_printf ("%d\n", y); +} diff --git a/gcc/testsuite/c-c++-common/ubsan/const-expr-1.c b/gcc/testsuite/c-c++-common/ubsan/const-expr-1.c new file mode 100644 index 00000000000..f474ec64ef5 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/const-expr-1.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=shift -w" } */ + +enum e { A = 1 << 1, B, }; +const int arr[] = { + 1 << 2, + 1 << 3, +}; + +int +bar (int a, int b) +{ + return a >> b; +} + +int +foo (void) +{ + int i = 1; + int vla[B << 3]; + return bar (A, (i <<= 6, i + 2)); +} diff --git a/gcc/testsuite/c-c++-common/ubsan/div-by-zero-1.c b/gcc/testsuite/c-c++-common/ubsan/div-by-zero-1.c new file mode 100644 index 00000000000..4e2a2b92749 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/div-by-zero-1.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=integer-divide-by-zero -Wno-div-by-zero" } */ + +int +main (void) +{ + volatile int a = 0; + volatile long long int b = 0; + volatile unsigned int c = 1; + + a / b; + 0 / 0; + a / 0; + 0 / b; + 2 / --c; + + return 0; +} + +/* { dg-output "division by zero(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */ diff --git a/gcc/testsuite/c-c++-common/ubsan/div-by-zero-2.c b/gcc/testsuite/c-c++-common/ubsan/div-by-zero-2.c new file mode 100644 index 00000000000..ee9673800d3 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/div-by-zero-2.c @@ -0,0 +1,23 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=integer-divide-by-zero -Wno-div-by-zero" } */ + +int +main (void) +{ + volatile const unsigned long int o = 1UL; + int zero = 0; + + o / 0; + 1UL / 0; + 1UL / zero; + o / zero; + o / (++zero - 1); + + return 0; +} + +/* { dg-output "division by zero(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division by zero(\n|\r\n|\r)" } */ diff --git a/gcc/testsuite/c-c++-common/ubsan/div-by-zero-3.c b/gcc/testsuite/c-c++-common/ubsan/div-by-zero-3.c new file mode 100644 index 00000000000..719e6c98634 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/div-by-zero-3.c @@ -0,0 +1,21 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=integer-divide-by-zero -Wno-overflow" } */ + +#include <limits.h> + +int +main (void) +{ + volatile int min = INT_MIN; + volatile int zero = 0; + + INT_MIN / -1; + min / -1; + min / (10 * zero - (2 - 1)); + + return 0; +} + +/* { dg-output "division of -2147483648 by -1 cannot be represented in type int(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division of -2147483648 by -1 cannot be represented in type int(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*division of -2147483648 by -1 cannot be represented in type int(\n|\r\n|\r)" } */ diff --git a/gcc/testsuite/c-c++-common/ubsan/div-by-zero-4.c b/gcc/testsuite/c-c++-common/ubsan/div-by-zero-4.c new file mode 100644 index 00000000000..295f624dc34 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/div-by-zero-4.c @@ -0,0 +1,11 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=integer-divide-by-zero -Wno-overflow" } */ + +#include <limits.h> + +int +main (void) +{ + /* This should not fail. */ + return (unsigned int) INT_MIN / -1; +} diff --git a/gcc/testsuite/c-c++-common/ubsan/save-expr-1.c b/gcc/testsuite/c-c++-common/ubsan/save-expr-1.c new file mode 100644 index 00000000000..24532e80761 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/save-expr-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=shift -Wall -Werror -O" } */ + +static int x; +int +main (void) +{ + int o = 1; + int y = x << o; + return y; +} diff --git a/gcc/testsuite/c-c++-common/ubsan/save-expr-2.c b/gcc/testsuite/c-c++-common/ubsan/save-expr-2.c new file mode 100644 index 00000000000..14ac17def9c --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/save-expr-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=shift -Wall -Werror -O" } */ + +int +foo (int i, unsigned int u) +{ + return u / i; +} + +int +bar (int i, unsigned int u) +{ + return u % i; +} diff --git a/gcc/testsuite/c-c++-common/ubsan/save-expr-3.c b/gcc/testsuite/c-c++-common/ubsan/save-expr-3.c new file mode 100644 index 00000000000..dd2903bd682 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/save-expr-3.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=shift -Wall -Werror -O" } */ + +int x; + +int +foo (int i, int u) +{ + return (i << u) << x; +} + +int +bar (int i, int u) +{ + return (i >> u) >> x; +} diff --git a/gcc/testsuite/c-c++-common/ubsan/save-expr-4.c b/gcc/testsuite/c-c++-common/ubsan/save-expr-4.c new file mode 100644 index 00000000000..aa34a70ede7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/save-expr-4.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=shift -Wall -Werror -O" } */ + +int x; + +int +foo (int i, unsigned int u) +{ + return (i % u) << (x / u); +} + +int +bar (int i, unsigned int u) +{ + return (((x % u) << (u / i)) >> x); +} diff --git a/gcc/testsuite/c-c++-common/ubsan/shift-1.c b/gcc/testsuite/c-c++-common/ubsan/shift-1.c new file mode 100644 index 00000000000..48cf3cd7bff --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/shift-1.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=shift -w" } */ + +typedef const unsigned long long int CULLI; +typedef volatile int VI; +struct s { signed long int a; }; + +int +main (void) +{ + int a = 1; + struct s s = { .a = 400 }; + CULLI culli = 42; + VI vi = 370; + volatile int shiftcount = 153; + + a <<= 152; + 1 << shiftcount; + 1 << 154; + culli << 524; + 1 << vi++; + (long) 1 << (s.a + 2); + + return 0; +} +/* { dg-output "shift exponent 152 is too large for \[^\n\r]*-bit type int(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent 153 is too large for \[^\n\r]*-bit type int(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent 154 is too large for \[^\n\r]*-bit type int(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent 524 is too large for \[^\n\r]*-bit type long long unsigned int(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent 370 is too large for \[^\n\r]*-bit type int(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent 402 is too large for \[^\n\r]*-bit type long int(\n|\r\n|\r)" } */ diff --git a/gcc/testsuite/c-c++-common/ubsan/shift-2.c b/gcc/testsuite/c-c++-common/ubsan/shift-2.c new file mode 100644 index 00000000000..68a7d136f43 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/shift-2.c @@ -0,0 +1,23 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=shift -w" } */ + +int +main (void) +{ + int a = 1; + volatile int b = -5; + long long int c = -6; + + a << -3; + 1 << -4; + 1 << b; + a << c; + a << (b + c); + + return 0; +} +/* { dg-output "shift exponent -3 is negative(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent -4 is negative(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent -5 is negative(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent -6 is negative(\n|\r\n|\r)" } */ +/* { dg-output "\[^\n\r]*shift exponent -11 is negative(\n|\r\n|\r)" } */ diff --git a/gcc/testsuite/c-c++-common/ubsan/shift-3.c b/gcc/testsuite/c-c++-common/ubsan/shift-3.c new file mode 100644 index 00000000000..c639d171184 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/shift-3.c @@ -0,0 +1,11 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=shift -w" } */ + +int +main (void) +{ + unsigned int a = 1; + a <<= 31; + a <<= 1; + return 0; +} diff --git a/gcc/testsuite/c-c++-common/ubsan/typedef-1.c b/gcc/testsuite/c-c++-common/ubsan/typedef-1.c new file mode 100644 index 00000000000..8dcf451c348 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/typedef-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined" } */ + +typedef int V; +int +foo (void) +{ + V v = 9; + int a = 3; + v += v % a; + return v / 3; +} diff --git a/gcc/testsuite/c-c++-common/ubsan/unreachable-1.c b/gcc/testsuite/c-c++-common/ubsan/unreachable-1.c new file mode 100644 index 00000000000..336240c96cb --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/unreachable-1.c @@ -0,0 +1,10 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=unreachable" } */ +/* { dg-shouldfail "ubsan" } */ + +int +main (void) +{ + __builtin_unreachable (); +} + /* { dg-output "execution reached a __builtin_unreachable\\(\\) call" } */ |