On Fri, Apr 29, 2011 at 9:43 AM, Jakub Jelinek <ja...@redhat.com> wrote: > Hi! > > The following patch fixes a bug in tree-switch-conversion.c with > signed index_expr's. build_arrays would compute index_expr - range_min > in index_expr's type and use that as index into CSWTCH.N array, > which is wrong, because in this case index_expr 98 - (-62) computed > in signed char type results in signed overflow and we end up > loading from CSWTCH.2[-96]. Apparently for the bounds checking > we perform the same index_expr - range_min computation, but in > corresponding unsigned type. This patch computes it just once in > unsigned type, so that overflow isn't undefined. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for > trunk/4.6/4.5/4.4? > > 2011-04-29 Jakub Jelinek <ja...@redhat.com> > > PR tree-optimization/48809 > * tree-switch-conversion.c (build_arrays): Compute tidx in unsigned > type. > (gen_inbound_check): Don't compute index_expr - range_min in utype > again, instead reuse SSA_NAME initialized in build_arrays. > Remove two useless gsi_for_stmt calls. > > * gcc.c-torture/execute/pr48809.c: New test.
This caused: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48849 -- H.J.