From c262f6b77cd8c2ae996109d39324f22a69654a30 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 22 Jan 2019 17:23:21 -0700 Subject: [PATCH] Warray-bounds-2.c: Include headers only if they exist. gcc/testsuite/ChangeLog: * c-c++-common/Warray-bounds-2.c: Include headers only if they exist. * c-c++-common/Warray-bounds-3.c: Make xfails conditional on target non_strict_align. * c-c++-common/Wrestrict-2.c: Include headers only if they exist. * c-c++-common/Wrestrict.c: Make xfails conditional on target non_strict_align. From-SVN: r268175 --- gcc/testsuite/ChangeLog | 39 ++++++++++++-------- gcc/testsuite/c-c++-common/Warray-bounds-2.c | 25 ++++++++++--- gcc/testsuite/c-c++-common/Warray-bounds-3.c | 2 +- gcc/testsuite/c-c++-common/Wrestrict-2.c | 24 +++++++++++- gcc/testsuite/c-c++-common/Wrestrict.c | 13 ++++--- 5 files changed, 76 insertions(+), 27 deletions(-) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 17fad73ab6c..3361da85991 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,21 +1,30 @@ +2019-01-22 Martin Sebor + + * c-c++-common/Warray-bounds-2.c: Include headers only if they exist. + * c-c++-common/Warray-bounds-3.c: Make xfails conditional on target + non_strict_align. + * c-c++-common/Wrestrict-2.c: Include headers only if they exist. + * c-c++-common/Wrestrict.c: Make xfails conditional on target + non_strict_align. + 2018-01-22 Steve Ellcey - c-c++-common/gomp/pr60823-1.c: Change aarch64-*-* target + * c-c++-common/gomp/pr60823-1.c: Change aarch64-*-* target to aarch64*-*-* target. - c-c++-common/gomp/pr60823-3.c: Ditto. - g++.dg/gomp/declare-simd-1.C: Ditto. - g++.dg/gomp/declare-simd-3.C: Ditto. - g++.dg/gomp/declare-simd-4.C: Ditto. - g++.dg/gomp/declare-simd-7.C: Ditto. - g++.dg/gomp/pr88182.C: Ditto. - gcc.dg/gomp/declare-simd-1.c: Ditto. - gcc.dg/gomp/declare-simd-3.c: Ditto. - gcc.dg/gomp/pr59669-2.c: Ditto. - gcc.dg/gomp/pr87895-1.c: Ditto. - gcc.dg/gomp/simd-clones-2.c: Ditto. - gfortran.dg/gomp/declare-simd-2.f90: Ditto. - gfortran.dg/gomp/pr79154-1.f90: Ditto. - gfortran.dg/gomp/pr83977.f90: Ditto. + * c-c++-common/gomp/pr60823-3.c: Ditto. + * g++.dg/gomp/declare-simd-1.C: Ditto. + * g++.dg/gomp/declare-simd-3.C: Ditto. + * g++.dg/gomp/declare-simd-4.C: Ditto. + * g++.dg/gomp/declare-simd-7.C: Ditto. + * g++.dg/gomp/pr88182.C: Ditto. + * gcc.dg/gomp/declare-simd-1.c: Ditto. + * gcc.dg/gomp/declare-simd-3.c: Ditto. + * gcc.dg/gomp/pr59669-2.c: Ditto. + * gcc.dg/gomp/pr87895-1.c: Ditto. + * gcc.dg/gomp/simd-clones-2.c: Ditto. + * gfortran.dg/gomp/declare-simd-2.f90: Ditto. + * gfortran.dg/gomp/pr79154-1.f90: Ditto. + * gfortran.dg/gomp/pr83977.f90: Ditto. 2019-01-22 Jakub Jelinek diff --git a/gcc/testsuite/c-c++-common/Warray-bounds-2.c b/gcc/testsuite/c-c++-common/Warray-bounds-2.c index aee35617bac..ca2d1c98218 100644 --- a/gcc/testsuite/c-c++-common/Warray-bounds-2.c +++ b/gcc/testsuite/c-c++-common/Warray-bounds-2.c @@ -8,12 +8,27 @@ { dg-do compile } { dg-options "-O2 -Warray-bounds -Wno-stringop-overflow" } */ -#include -#include +#if __has_include () +# include +#else +/* For cross-compilers. */ +typedef __PTRDIFF_TYPE__ ptrdiff_t; +typedef __SIZE_TYPE__ size_t; +#endif + +#if __has_include () +# include +# undef memcpy +# undef strcat +# undef strcpy +# undef strncpy +#else +extern void* memcpy (void*, const void*, size_t); +extern char* strcat (char*, const char*); +extern char* strcpy (char*, const char*); +extern char* strncpy (char*, const char*, size_t); +#endif -#undef memcpy -#undef strcpy -#undef strncpy #define MAX (__SIZE_MAX__ / 2) diff --git a/gcc/testsuite/c-c++-common/Warray-bounds-3.c b/gcc/testsuite/c-c++-common/Warray-bounds-3.c index e49d44ad41d..7f2b33b404a 100644 --- a/gcc/testsuite/c-c++-common/Warray-bounds-3.c +++ b/gcc/testsuite/c-c++-common/Warray-bounds-3.c @@ -158,7 +158,7 @@ void test_memcpy_overflow (char *d, const char *s, size_t n) but known access size is detected. This works except with small sizes that are powers of 2 due to bug . */ T (char, 1, arr + SR (DIFF_MAX - 1, DIFF_MAX), s, 1); - T (char, 1, arr + SR (DIFF_MAX - 1, DIFF_MAX), s, 2); /* { dg-warning "pointer overflow between offset \\\[\[0-9\]+, \[0-9\]+] and size 2 accessing array " "bug " { xfail *-*-* } } */ + T (char, 1, arr + SR (DIFF_MAX - 1, DIFF_MAX), s, 2); /* { dg-warning "pointer overflow between offset \\\[\[0-9\]+, \[0-9\]+] and size 2 accessing array " "bug " { xfail non_strict_align } } */ T (char, 1, arr + SR (DIFF_MAX - 2, DIFF_MAX), s, 3); /* { dg-warning "pointer overflow between offset \\\[\[0-9\]+, \[0-9\]+] and size 3 accessing array " "memcpy" } */ T (char, 1, arr + SR (DIFF_MAX - 4, DIFF_MAX), s, 5); /* { dg-warning "pointer overflow between offset \\\[\[0-9\]+, \[0-9\]+] and size 5 accessing array " "memcpy" } */ } diff --git a/gcc/testsuite/c-c++-common/Wrestrict-2.c b/gcc/testsuite/c-c++-common/Wrestrict-2.c index c3e9ac82d64..4d901670519 100644 --- a/gcc/testsuite/c-c++-common/Wrestrict-2.c +++ b/gcc/testsuite/c-c++-common/Wrestrict-2.c @@ -8,7 +8,29 @@ { dg-do compile } { dg-options "-O2 -Wrestrict" } */ -#include +#if __has_include () +# include +#else +/* For cross-compilers. */ +typedef __PTRDIFF_TYPE__ ptrdiff_t; +typedef __SIZE_TYPE__ size_t; +#endif + +#if __has_include () +# include +# undef memcpy +# undef strcat +# undef strcpy +# undef strncat +# undef strncpy +#else +extern void* memcpy (void*, const void*, size_t); +extern char* strcat (char*, const char*); +extern char* strcpy (char*, const char*); +extern char* strncat (char*, const char*, size_t); +extern char* strncpy (char*, const char*, size_t); +#endif + static void wrap_memcpy (void *d, const void *s, size_t n) { diff --git a/gcc/testsuite/c-c++-common/Wrestrict.c b/gcc/testsuite/c-c++-common/Wrestrict.c index d0e3c3411fe..c852b06bbd7 100644 --- a/gcc/testsuite/c-c++-common/Wrestrict.c +++ b/gcc/testsuite/c-c++-common/Wrestrict.c @@ -53,8 +53,11 @@ void test_memcpy_cst (void *d, const void *s) T (a, a, 0); - /* This isn't detected because memcpy calls with small power-of-2 sizes - are intentionally folded into safe copies equivalent to memmove. + /* This isn't detected because memcpy calls with size of 1 are + intentionally folded into safe copies equivalent to memmove, + regardless of the target (larger power-of-2 copies may or + may not be folded depending on the target -- see non_strict_align + below, for example). It's marked xfail only because there is value in detecting such invalid calls for portability, and as a reminder of why it isn't diagnosed. */ @@ -192,19 +195,19 @@ void test_memcpy_range (char *d, size_t sz) T (a + ir, a, 2); T (a + ir, a, 3); /* The following fails because the size is a small power of 2. */ - T (a + ir, a, 4); /* { dg-warning "accessing 4 bytes at offsets \\\[2, 3] and 0 overlaps between 1 and 2 bytes at offset \\\[3, 2]" "memcpy" { xfail *-*-*} } */ + T (a + ir, a, 4); /* { dg-warning "accessing 4 bytes at offsets \\\[2, 3] and 0 overlaps between 1 and 2 bytes at offset \(\\\[3, 2]|\\\[2, 3]\)" "pr79220" { xfail non_strict_align } } */ T (a + ir, a, 5); /* { dg-warning "accessing 5 bytes at offsets \\\[2, 3] and 0 overlaps between 2 and 3 bytes at offset \\\[2, 3]" "memcpy" } */ T (d + ir, d, 0); T (d + ir, d, 1); T (d + ir, d, 2); T (d + ir, d, 3); - T (d + ir, d, 4); /* { dg-warning "accessing 4 bytes at offsets \\\[2, 3] and 0 overlaps 1 byte at offset 3" "bug 79220" { xfail *-*-* } } */ + T (d + ir, d, 4); /* { dg-warning "accessing 4 bytes at offsets \\\[2, 3] and 0 overlaps between 1 and 2 bytes at offset \\\[2, 3]" "pr79220" { xfail non_strict_align } } */ T (d + ir, d, 5); /* { dg-warning "accessing 5 bytes at offsets \\\[2, 3] and 0 overlaps between 2 and 3 bytes at offset \\\[2, 3]" "memcpy" } */ /* Because the size is constant and a power of 2 the following is folded too early to detect the overlap. */ - T (d + ir, d, 4); /* { dg-warning "accessing 4 bytes at offsets \\\[2, 3] and 0 overlaps 2 byte at offset 2" "memcpy" { xfail *-*-* } } */ + T (d + ir, d, 4); /* { dg-warning "accessing 4 bytes at offsets \\\[2, 3] and 0 overlaps between 1 and 2 bytes at offset \\\[2, 3]" "pr79220" { xfail non_strict_align } } */ T (d + ir, d, 5); /* { dg-warning "accessing 5 bytes at offsets \\\[2, 3] and 0 overlaps between 2 and 3 bytes at offset \\\[2, 3]" "memcpy" } */ /* Exercise the full range of size_t. */ -- 2.30.2