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

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

Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os


From: David Brown
Subject: Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os
Date: Sat, 17 May 2008 22:02:00 +0200
User-agent: Thunderbird 2.0.0.14 (Windows/20080421)

Loveny Design wrote:
David Brown wrote:
The point is, the compiler is allowed to do this sort of optimisation. It can be a bit annoying during testing and debugging - especially because such reorderings are relatively rare in practice, so that it's easy to think "it worked before, what's wrong now?".


I wouldn't have thought the compiler was allowed to re-order statements
*around* a volatile access. Perhaps someone can help my understanding, given
:-
1: Volatile Statements<sp>
2: Statements<sp>
3: Volatile Statements<sp>
where <sp> is a sequence point.

Line 3 has a volatile access and therefore has side-effects that the
compiler doesn't know about, so surely it must complete all preceeding
statements up to and including the sequence point before the volatile access
occurs?

Jon


No - volatile only enforces ordering with respect to volatile accesses and anything that might affect them. So if the statements in 2 are known not to have side effects or read from memory, then they cannot affect the volatile statements, and thus can be moved around them.

People often think the same thing about embedded assembly statements, and get surprised when gcc re-orders them.





reply via email to

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