http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59999
--- Comment #15 from rguenther at suse dot de <rguenther at suse dot de> --- On Thu, 6 Feb 2014, pa...@matos-sorge.com wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59999 > > --- Comment #14 from Paulo J. Matos <pa...@matos-sorge.com> --- > Something like this which looks much simpler hits the same problem: > extern int arr[]; > > void > foo32 (int limit) > { > short i; > for (i = 0; (int)i < limit; i++) > arr[i] += 1; > } Exactly the same problem. C integral type promotion rules make that i = (short)((int)i + 1) again. Note that (int)i + 1 does not overflow, (short) ((int)i + 1) invokes implementation-defined behavior which in our case is modulo-2 reduction. Nothing guarantees that (short)i + 1 does not overflow.