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
This commit is contained in:
Martin Sebor 2019-01-22 17:23:21 -07:00
parent e6c26d6406
commit c262f6b77c
5 changed files with 76 additions and 27 deletions

View file

@ -1,21 +1,30 @@
2019-01-22 Martin Sebor <msebor@redhat.com>
* 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 <sellcey@marvell.com>
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 <jakub@redhat.com>

View file

@ -8,12 +8,27 @@
{ dg-do compile }
{ dg-options "-O2 -Warray-bounds -Wno-stringop-overflow" } */
#include <stddef.h>
#include <string.h>
#if __has_include (<stddef.h>)
# include <stddef.h>
#else
/* For cross-compilers. */
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __SIZE_TYPE__ size_t;
#endif
#if __has_include (<string.h>)
# include <string.h>
# 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)

View file

@ -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" } */
}

View file

@ -8,7 +8,29 @@
{ dg-do compile }
{ dg-options "-O2 -Wrestrict" } */
#include <string.h>
#if __has_include (<stddef.h>)
# include <stddef.h>
#else
/* For cross-compilers. */
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __SIZE_TYPE__ size_t;
#endif
#if __has_include (<string.h>)
# include <string.h>
# 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)
{

View file

@ -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. */