mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-19 15:11:08 +08:00
re PR middle-end/37861 (Bogus array bounds warning)
2008-11-05 Martin Jambor <mjambor@suse.cz> PR middle-end/37861 * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Don't turn pointer arithmetics into array_ref if the array is accessed through an indirect_ref. * testsuite/gcc.dg/Warray-bounds-5.c: New file. * testsuite/gcc.dg/Warray-bounds-6.c: New file. From-SVN: r141613
This commit is contained in:
parent
8df7b2b60e
commit
5e9abf2ce4
@ -1,3 +1,10 @@
|
||||
2008-11-05 Martin Jambor <mjambor@suse.cz>
|
||||
|
||||
PR middle-end/37861
|
||||
* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Don't turn
|
||||
pointer arithmetics into array_ref if the array is accessed
|
||||
through an indirect_ref.
|
||||
|
||||
2008-11-05 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
PR middle-end/37742
|
||||
|
@ -1,3 +1,9 @@
|
||||
2008-11-05 Martin Jambor <mjambor@suse.cz>
|
||||
|
||||
PR middle-end/37861
|
||||
* gcc.dg/Warray-bounds-5.c: New test.
|
||||
* gcc.dg/Warray-bounds-6.c: New test.
|
||||
|
||||
2008-11-05 Fabien Chene <fabien.chene@gmail.com>
|
||||
|
||||
PR c++/32519
|
||||
|
24
gcc/testsuite/gcc.dg/Warray-bounds-5.c
Normal file
24
gcc/testsuite/gcc.dg/Warray-bounds-5.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-O3 -Wall" } */
|
||||
/* based on PR 37861 */
|
||||
|
||||
extern int printf (__const char *__restrict __format, ...);
|
||||
|
||||
static int f2(char formatstr[10][100])
|
||||
{
|
||||
int anz;
|
||||
for( anz = 0; anz < 10; ++anz ) {
|
||||
printf( "%d %s\n", anz, formatstr[anz] );
|
||||
}
|
||||
return anz;
|
||||
}
|
||||
|
||||
|
||||
static char formatstr[10][100];
|
||||
int main( void )
|
||||
{
|
||||
int anz;
|
||||
anz = f2(formatstr);
|
||||
printf( " %d\n",anz);
|
||||
return 0;
|
||||
}
|
29
gcc/testsuite/gcc.dg/Warray-bounds-6.c
Normal file
29
gcc/testsuite/gcc.dg/Warray-bounds-6.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-O3 -Wall" } */
|
||||
/* based on PR 37861 */
|
||||
|
||||
extern int printf (__const char *__restrict __format, ...);
|
||||
|
||||
static int f3(int v)
|
||||
{
|
||||
int i,j = 0;
|
||||
for (i = 0; i <= v; i++)
|
||||
j++;
|
||||
return j;
|
||||
}
|
||||
|
||||
static int f2(char formatstr[10][100]) {
|
||||
printf( "%d %s\n", 0, formatstr[f3(0)] );
|
||||
printf( "%d %s\n", 1, formatstr[f3(1)] );
|
||||
printf( "%d %s\n", 2, formatstr[f3(2)] );
|
||||
printf( "%d %s\n", 3, formatstr[f3(3)] );
|
||||
return 3;
|
||||
}
|
||||
|
||||
static char formatstr[10][100];
|
||||
int main( void ) {
|
||||
int anz;
|
||||
anz = f2(formatstr);
|
||||
printf( " %d\n",anz);
|
||||
return 0;
|
||||
}
|
@ -802,6 +802,9 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
|
||||
array_ref = TREE_OPERAND (def_rhs, 0);
|
||||
if (TREE_CODE (array_ref) != ARRAY_REF
|
||||
|| TREE_CODE (TREE_TYPE (TREE_OPERAND (array_ref, 0))) != ARRAY_TYPE
|
||||
/* Avoid accessing hidden multidimensional arrays in this way or VRP
|
||||
might give out bogus warnings (see PR 37861) */
|
||||
|| TREE_CODE (TREE_OPERAND (array_ref, 0)) == INDIRECT_REF
|
||||
|| !integer_zerop (TREE_OPERAND (array_ref, 1)))
|
||||
return false;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user