The loop in the example is incorrectly replaced with endless loop when compiling with -Os, -O2 or -O3. It is compiled correctly with -O0 or -O1.
uint16 sum=0; uint16 *i; /*sum all words in inspected area*/ i = (uint16 *)0x0FFE; do { --i; sum = sum + *(i); } while ( i != 0 ); (see the full source in the attachment) Target: i686-pc-cygwin Configured with: ../gcc-4.3.2/configure Thread model: single gcc version 4.3.2 (GCC) (the same problem occurs with earlier versions of GCC (e.g. 3.4.3) and G++ ) -- Summary: Loop incorrectly optimized to endless loop with -Os/- O2/-O3 Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ppr at melexis dot com GCC host triplet: i686-pc-cygwin http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37569