At optimization levels -Os, -O1, and -O2, the attached program generates incorrect loop code. It appears that when optimizing, the loop termination is checking array end address versus current pointer. The array end address contains all address bits while the current pointer is just the lower (16?) bits. m32c-elf-gcc -O1 -mcpu=m32cm -msim m1.c && m32c-elf-run a.out NULL pointer dereference Attaching test program.
Created attachment 16417 [details] small test program test program demonstrating problem
Joel, could you check if this bug still is present and if it affects RTEMS? From what I can gather from looking at the asm gcc generates, this bug might be fixed in gcc-4.5.x (rtems-4.11)
(In reply to comment #2) > Joel, could you check if this bug still is present and if it affects RTEMS? > > From what I can gather from looking at the asm gcc generates, this bug might be > fixed in gcc-4.5.x (rtems-4.11) The program does run to completion now. This was hanging m32c during RTEMS initialization of the priority chains. So now I should test that side of the world.