This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Code optimization: warning for code that hangs


On 24/06/12 23:54, Robert Dewar wrote:
On 6/24/2012 12:09 PM, Ángel González wrote:
"Peter A. Felvegi" writes:
My question is: wouldn't it be possible to print a warning when a jmp
to itself or trivial infinite recursion is generated? The code
compiled fine w/ -Wall -Wextra -Werror w/ 4.6 and 4.7.
Note that if the target architecture is a microcontroller, an endless
loop can be a legitimate way to finish / abort the program.


But not an infinite recursion! And an endless loop is such a rare case that it deserves a warning, it's a false positive in this case, so what?


An endless loop is not rare - as Ángel says, it is standard practice in embedded systems. Typical systems can have more than one such loop - the main loop is usually endless, and you often have some sort of "halt" or "wait for watchdog reset" endless loop.


Most such loops are not simple "jump to yourself" instructions - but some are (with other actions being triggered by interrupts).

In the majority of cases, however, it should be possible to mark the function in question as "noreturn".

In fact, when I think about it, perhaps a "-Wsuggest-attribute=noreturn" will give people the warning they want? After all, if the compiler can work out that the best code is a "jump to yourself" instruction, it should also have noted that the function does not return.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]