[arm-gnu] some questions about gcc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[arm-gnu] some questions about gcc
- To: arm-gnu@xxxxxxxxxxxxxxxx
- Subject: [arm-gnu] some questions about gcc
- From: yann.poupet@xxxxxxx
- Date: Tue, 2 Jun 2009 13:52:37 +0200 (CEST)
Hi,
I used CS Q12009 to compile some files and I have some questions.
Consider the following C code:
int a(int b)
{
int c = c;
return c + b;
}
With the following command:
arm-none-eabi-gcc -Wall -c -o uninit -Os uninit.c
it compiles fine without any warning.
Whereas with the following:
int a(int b)
{
int c;
c = c;
return b + c;
}
I have a warning : "'c' is used uninitialized in this function"
Is there a reason ?
Also, in both case, compiled code is :
00000000 <a>:
0: e12fff1e bx lr
0: R_ARM_V4BX *ABS*
which is the same binary that would be produced by compiling the following:
int a(int b)
{
return b;
}
I guess this is a "normal" behaviour since c is not initialized gcc considers it is zero (it's only a guess).
Consider this other c code:
int a(int b)
{
register int c __asm__("r4");
return (b + c);
}
This one compiles fine and does what I want, which is return r0 + r4.
However, objdump shows r4 is saved then restored from the stack :
0: e52d4004 push {r4} ; (str r4, [sp, #-4]!)
4: e0800004 add r0, r0, r4
8: e8bd0010 pop {r4}
c: e12fff1e bx lr
which is useless since r4 is not modified. Is there a reason ?
Note that if using r3 instead of r4, push/pop does not happen, probably because according to the ABI {r0-r3,ip} don't need to be saved/restored. But still I wonder why r4 is saved/restored.
Thank you.
Regards,
Yann Poupet.