Forum: ARM programming with GCC/GNU tools GCC bug ?

von Kees S. (kees)

Attached files:

Rate this post
0 useful
not useful
Hi Everyone,

I have a bit of a problem with the arm-elf-gcc compiler (latest WinARM,
version 4.1.1, but also in previous versions) when I compile the
following code fragement:

typedef struct _block
  struct _block *nptr;
  int data[100];

void FreeBlocks(block *p)
  block *bptr,*fptr;

  bptr = p;
  fptr = p->nptr;

    if (bptr == (block *)NULL)

    bptr = fptr;
    fptr = bptr->nptr;

Somehow the compiler 'optimizes' the bptr check to NULL out of the way
when I set the optimize flags to -Os. The resulting assembly code is :

6005016c <FreeBlocks>:
6005016c:  b510        push  {r4, lr}
6005016e:  6804        ldr  r4, [r0, #0]
60050170:  4b02        ldr  r3, [pc, #8]  (6005017c <PROGRAM+0x10>)
60050172:  f000 f823   bl  600501bc <PROGRAM+0x50>
60050176:  1c20        adds  r0, r4, #0
60050178:  6824        ldr  r4, [r4, #0]
6005017a:  e7f9        b.n  60050170 <_eappstart+0x4>
6005017c:  f3b8 6004   undefined

However, when I set the optimize flags to -O1, the code is compiled as
6005016c <FreeBlocks>:
6005016c:  b530        push  {r4, r5, lr}
6005016e:  6804        ldr  r4, [r0, #0]
60050170:  2800        cmp  r0, #0
60050172:  d008        beq.n  60050186 <_eappstart+0x1a>
60050174:  4d04        ldr  r5, [pc, #16]  (60050188 <PROGRAM+0x1c>)
60050176:  f000 f82a   bl  600501ce <PROGRAM+0x62>
6005017a:  6823        ldr  r3, [r4, #0]
6005017c:  1c20        adds  r0, r4, #0
6005017e:  2c00        cmp  r4, #0
60050180:  d001        beq.n  60050186 <_eappstart+0x1a>
60050182:  1c1c        adds  r4, r3, #0
60050184:  e7f7        b.n  60050176 <_eappstart+0xa>
60050186:  bd30        pop  {r4, r5, pc}
60050188:  f3b8 6004   undefined

It is clear to see that the second time, the compiler generates a cmp
r0,#0 instruction, and hence the program works as expected, but the
resulting code is a lot bigger.

So, my question is, do I do something wrong, or is this indeed a bug in
the compiler. In that case, where can I submit a bug report, or is there
an updated version of arm-gcc that I can use.

Any suggestions are welcome,


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.