From 92ef7fb19a5111b98e86eb7c59d1a1d759ac1ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= Date: Sat, 18 Apr 2009 09:24:45 +0000 Subject: re PR middle-end/36902 (Array bound warning with dead code after optimization) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2009-04-18 Manuel López-Ibáñez PR middle-end/36902 * tree-vrp.c (check_array_ref): Pass a location_t instead of a pointer. Use warning_at instead of warning. (search_for_addr_array): Likewise. (check_array_bounds): Likewise. (check_all_array_refs): Check that the incoming edge is not in the list of edges to be removed. (check_all_array_refs): Avoid the temporal pointer. (vrp_visit_cond_stmt): Fix typo. (simplify_switch_using_ranges): Handle the case where the switch index is an integer constant. testsuite/ * gcc.dg/pr36902.c: New. From-SVN: r146305 --- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/pr36902.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr36902.c (limited to 'gcc/testsuite') diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c4269123..a2449e8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-04-18 Manuel López-Ibáñez + + PR middle-end/36902 + * gcc.dg/pr36902.c: New. + 2009-04-17 Diego Novillo * gcc.c-torture/execute/builtins/strlen-3.c: Fix ODR diff --git a/gcc/testsuite/gcc.dg/pr36902.c b/gcc/testsuite/gcc.dg/pr36902.c new file mode 100644 index 0000000..43a2d14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr36902.c @@ -0,0 +1,61 @@ +/* PR middle-end/36902 Array bound warning with dead code after optimization */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Warray-bounds -Wall -Wextra" } */ +typedef unsigned char __u8; +typedef unsigned short __u16; + +static inline unsigned char * +foo(unsigned char * to, const unsigned char * from, int n) +{ + switch ( n ) + { + case 3: + *to = *from; + break; + case 5: + to[4] = from [4]; + break; + } + return to; +} + +struct { + int size_of_select; + unsigned char pcr_select[4]; +} sel; + +int bar(void) +{ + static unsigned char buf[64]; + + sel.size_of_select = 3; + foo(buf, sel.pcr_select, sel.size_of_select); + + return 1; +} + + +static inline unsigned char * +foo2(unsigned char * to, const unsigned char * from, int n) +{ + switch ( n ) + { + case 3: + *to = *from; + break; + case 5: + to[4] = from [4]; /* { dg-warning "array subscript is above array bounds" } */ + break; + } + return to; +} + +int baz(void) +{ + static unsigned char buf[64]; + + sel.size_of_select = 5; + foo2(buf, sel.pcr_select, sel.size_of_select); + + return 1; +} -- cgit v1.1