From the Procedure Call Standard for the ARM architecture (§7.1.5):
a compiler may ignore a volatile qualification of an automatic variable whose address is never taken unless the function calls setjmp().
Is that mean that in following code:
volatile int x = 8;
if (x == 1)
{
printf("can be optimised away??");
}
The whole if scope can be optimised out?
This just contradict the standard, for starters, volatile accesses are part of the observable behaviour and must be performed as in the abstract machine code:
§5.1.2.3:
The least requirements on a conforming implementation are:
Accesses to volatile objects are evaluated strictly according to the rules of the abstract machine.
And also §6.7.3:
An object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine
Is there a contradiction? And if so, how is it legit that a PCS contradict the C standard?
xthrough a pointer, then why does it still need to be treated asvolatile? The C standard says "At sequence points, volatile objects are stable in the sense that previous accesses are complete and subsequent accesses have not yet occurred." This looks like it can be met given the constraints set by the PCS. - John SzakmeisterThe least requirements on a conforming implementation are: Accesses to volatile objects are evaluated strictly according to the rules of the abstract machine...can it get simpler than that? alsoAn object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine,- user2162550How could x be modified in a way unknown to the compiler?<- by an ISR or memory-mapped hardware etc. The compiler is not aware of how the HW works. This happens a lot in embedded software. - Morten Jensenxis not accessed within its world of abstract machines. - chux - Reinstate Monica