|
From: | David Brown |
Subject: | [avr-gcc-list] Re: optimizer removes volatile pin access code. why? |
Date: | Thu, 29 Oct 2009 11:14:34 +0100 |
User-agent: | Thunderbird 2.0.0.23 (Windows/20090812) |
Stu Bell wrote:
David Brown wrote:And an __attribute_((always_inline)) function will be inlined, regardless of the optimisation levels.Sorry, compiler breath -- this is not always true. If you call an "always_inline" function from inside another "always_inline" function,with optimization turned off, the compiler throws a fit.Example -- WinAVR 20090313, file compiled with -O0. Inline function is: static void FcsStartUtilTimer( uint16_t Wait ) __attribute__((always_inline)); static voidFcsStartUtilTimer( uint16_t Wait ) {
<snip>
Returns the following error: CmdFocus.c: In function 'FcsAcquireLookForSumOKDeassert': CmdFocus.c:4020: sorry, unimplemented: inlining failed in call to 'FcsStartUtilTimer': function body not available CmdFocus.c:4152: sorry, unimplemented: called from here ...
That's hardly "throwing a fit" - it's simply telling you it can't obey the "always_inline" attribute.
However, I think the problem stems from a misunderstanding about "always_inline" - it's an /additional/ request to the compiler that you can use for /inline/ functions. From the gcc documentation:
always_inlineGenerally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level was specified.
If you declare your functions "inline", it should work as you desire even with -O0:
static inline void FcsStartUtilTimer( uint16_t Wait ) __attribute__((always_inline)); static inline void FcsStartUtilTimer( uint16_t Wait ) mvh., David
The above code compiles fine if the optimizer is turned on (-Os). Of course, I guess the real question (which I have not investigated) is whether it compiles *correctly* with -Os. :-/ It functions correctly, so I presume it is inlining correctly.Best regards, Stu Bell DataPlay (DPHI, Inc.)
[Prev in Thread] | Current Thread | [Next in Thread] |