avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Incorrect code by gcc?


From: Andy H
Subject: Re: [avr-gcc-list] Incorrect code by gcc?
Date: Wed, 02 Apr 2008 19:15:18 -0400
User-agent: Thunderbird 2.0.0.12 (Windows/20080213)

Ok you should not be using naked.

If function never returns (I mean never!) then it should be something like this :

void main(void) __attribute__((noreturn));

-fomit-frame-pointer  will work if gcc can really omit it.

Frame pointer will be used to store "local" variables that are to big to fit in 
registers and/or need to be saved around calls.
It may also use R2-R17 to save values. Many factors determine which it will 
use, such as loops - speed -size - overhead of saving registers etc.
It is not always perfect.

If you find situation where it could omit frame pointer - but does not, that 
might be a bug
(gcc is not perfect - I know several parts that could be better).

By all means post "bug" here first if you are not sure.

I know gcc bugs should have pre-processed sources (.i files) - but as first 
look it is easier to just look at c code.
I think Eric and others would have spotted it sooner.


best regards and hope tulips look good.

Andy




Ruud Vlaming wrote:
On Thursday 03 April 2008 00:27, Andy H wrote:
Not a bug
Very good spotting. Andy! Thank you!

Thats the reason i wanted it to post here before sending in a bug report.
Unfortunately i already did so, so i marked the bug as INVALID now.
The bugnumber was 35807
According to the sources you posted,
privQueuRequestBody
void privQueuRequestBody(uint8_t uiSlot, int8_t siFreeFilling, uint16_t 
uiTicksToWait) __attribute__ ( ( naked ) );

The relevant part being "naked"

That means gcc will omit prolog - which is where stack and frame pointer are 
setup.
R28/29 is the frame pointer. What you see in assembler is gcc saving the register around a call. Depending on optimization, it may choose to do this rather than use a register (as the register would need to be saved on the stack).
If you use naked, you must replace all of prolog/epilog by hand. (its normal 
use is for assembler only functions)

OK, naked is a "dangerous" attribute. I must use it for i do a context save 
just before the
body function is called, but must preserve all registers so the function parameters are left alone. Is there a way to prohibit the compiler to do so? In other words can i somehow forbid to make use of the frame pointer? -fomit-frame-pointer seems not to do the trick.

Since i know on beforehand i will not return from privQueuRequestBody there is 
no
need to save the stack or so.
Ideas?

Ruud.


_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list




reply via email to

[Prev in Thread] Current Thread [Next in Thread]