diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/Warray-bounds.c | |
download | cbb-gcc-4.6.4-upstream.tar.bz2 cbb-gcc-4.6.4-upstream.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/Warray-bounds.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/Warray-bounds.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds.c b/gcc/testsuite/gcc.dg/Warray-bounds.c new file mode 100644 index 000000000..aa154a7e7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds.c @@ -0,0 +1,93 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Warray-bounds" } */ + +int a[10]; + +static inline int n(void) { + __SIZE_TYPE__ strlen(const char *s); + return strlen("12345"); +} + +void g(int *p); +void h(int p); + +int* f(void) { + int b[10]; + int i; + struct { + int c[10]; + } c; + + a[-1] = 0; /* { dg-warning "6:array subscript" } */ + a[ 0] = 0; + a[ 1] = 0; + + + a[ 9] = 0; + a[10] = 0; /* { dg-warning "6:array subscript" } */ + a[11] = 0; /* { dg-warning "6:array subscript" } */ + a[2 * n() - 11] = 1; /* { dg-warning "6:array subscript" } */ + a[2 * n() - 10] = 1; + a[2 * n() - 1] = 1; + a[2 * n() - 0] = 1; /* { dg-warning "6:array subscript" } */ + + b[-1] = 0; /* { dg-warning "6:array subscript" } */ + b[ 0] = 0; + b[ 1] = 0; + b[ 9] = 0; + b[10] = 0; /* { dg-warning "6:array subscript" } */ + b[11] = 0; /* { dg-warning "6:array subscript" } */ + b[2 * n() - 11] = 1; /* { dg-warning "6:array subscript" } */ + b[2 * n() - 10] = 1; + b[2 * n() - 1] = 1; + b[2 * n() - 0] = 1; /* { dg-warning "array subscript" } */ + + c.c[-1] = 0; /* { dg-warning "8:array subscript" } */ + c.c[ 0] = 0; + c.c[ 1] = 0; + c.c[ 9] = 0; + c.c[10] = 0; /* { dg-warning "8:array subscript" } */ + c.c[11] = 0; /* { dg-warning "8:array subscript" } */ + c.c[2 * n() - 11] = 1; /* { dg-warning "8:array subscript" } */ + c.c[2 * n() - 10] = 1; + c.c[2 * n() - 1] = 1; + c.c[2 * n() - 0] = 1; /* { dg-warning "8:array subscript" } */ + + g(&a[8]); + g(&a[9]); + g(&a[10]); + g(&a[11]); /* { dg-warning "array subscript" } */ + g(&a[-30]+10); /* { dg-warning "array subscript" } */ + g(&a[-30]+30); + + g(&b[10]); + g(&c.c[10]); + g(&b[11]); /* { dg-warning "array subscript" } */ + g(&c.c[11]); /* { dg-warning "array subscript" } */ + + g(&a[0]); + g(&b[0]); + g(&c.c[0]); + + g(&a[-1]); /* { dg-warning "array subscript" } */ + g(&b[-1]); /* { dg-warning "array subscript" } */ + h(sizeof a[-1]); + h(sizeof a[10]); + h(sizeof b[-1]); + h(sizeof b[10]); + h(sizeof c.c[-1]); + h(sizeof c.c[10]); + + if (10 < 10) + a[10] = 0; + if (10 < 10) + b[10] = 0; + if (-1 >= 0) + c.c[-1] = 0; + + for (i = 20; i < 30; ++i) + a[i] = 1; /* { dg-warning "15:array subscript" } */ + + return a; +} + |