I've made a small example where a for-loop never exits when it should. I have tried gcc 4.2.1, 4.2.4 and 4.3.1 with the same result. Gcc 4.1.1 works. GCC is configured with: ../configure --prefix=/opt/arm-linux/arm --host=i686-linux-gnu --target=arm-linux-gnu --build=i686-linux-gnu --includedir=/opt/arm-linux/arm/arm-linux-gnu/usr/include --enable-multilib --enable-threads --disable-nls --enable-shared --enable-languages=c,c++ --enable-__cxa_atexit --enable-c99 --enable-long-long The example is compiled with: arm-linux-gnu-gcc -O1 -Wall -march=armv5 -o bug main.c main.c: --- #include <stdio.h> #include <stdlib.h> #include <unistd.h> struct dummy { unsigned short count; unsigned short options; }; unsigned foo (unsigned x) { return x << 1; } int main (int argc, char* argv[]) { struct dummy *d; unsigned count; unsigned i; unsigned short* w; unsigned phase; unsigned long long val; d = malloc (sizeof(struct dummy)); d->count = 1; d->options = 0; count = d->count; w = malloc (sizeof(unsigned short)); for (i=0; i<count; i++) { phase = (unsigned)((long long)(0xFFFFFFFF) * i / count); val = foo (phase); w[i] = (unsigned short)val; fprintf (stderr, "i: %u, count: %u\n", i, count); } return 0; } ---
I'm unable to reproduce this with any of svn-trunk, gcc-4.1.3 (debian), gcc-4.3.3 (SVN) or gcc-4.3.2 (debian). The loop essentially reads as mov r7, #1 mov r6, #0 L5: ... add r6, r6, #1 cmp r7, r6 bhi L5 This will iterate only while r7 is larger than r6 -- that is, exactly once, when r6 is 0.