From: SourceForge.net <no...@so...> - 2003-01-11 02:28:37
|
Bugs item #663539, was opened at 2003-01-06 23:24 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=663539&group_id=599 Category: Icode generator >Group: known bugs Status: Open Resolution: None Priority: 2 Submitted By: Tzvetan Mikov (mikov) Assigned to: Nobody/Anonymous (nobody) Summary: volatile does not work Initial Comment: SDCC version 2.3.0 for 8051: volatile xdata char x; void test ( void ) { x; } This should generate an access to _x_, but it doesn't. It is a problem when _x_ is a hardware register. ---------------------------------------------------------------------- Comment By: Tzvetan Mikov (mikov) Date: 2003-01-10 18:27 Message: Logged In: YES user_id=675109 SDCC is not correct. Relevant abstracts from the standard: 5.1.2.3 Program execution 1 The semantic descriptions in this International Standard describe the behavior of an abstract machine in which issues of optimization are irrelevant. 2 Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects,11) which are changes in the state of the execution environment. Evaluation of an expression may produce side effects. At certain specified points in the execution sequence called sequence points, all side effects of previous evaluations shall be complete and no side effects of subsequent evaluations shall have taken place. (A summary of the sequence points is given in annex C.) 3 In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no needed side effects are produced (including any caused by calling a function or accessing a volatile object). 6.7.3 Type qualifiers 6 An object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. Therefore any expressionreferring to such an object shall be evaluated strictly according to the rules of the abstract machine, as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the object shall agree with that prescribed by the abstract machine, except as modified by the unknown factors mentioned previously.114) What constitutes an access to an object that has volatile-qualified type is implementation-defined. In fact GCC does comply with this. GCC 2.95.3 generates the following *correct* code: volatile int x; void test ( void ) { x; } _test: pushl %ebp movl %esp,%ebp movl _x,%eax movl %ebp,%esp popl %ebp ret If newer versions of GCC behave otherwise, then they are broken. Further on, the proposed solution of using "dummy=x" doesn't actually change anything. If "dummy" is a non-volatile local variable, then it can be optimized out, bringing us back to the same problem. If "dummy" is global variable, then we are changing the desired semantics of the program (which in this case are to read from "x" and ignore the value), which is unacceptable. This bug may be difficult to fix, but there is no other standard way to access memory-mapped hardware registers. I believe this is very important for an embedded compiler. ---------------------------------------------------------------------- Comment By: Johan Knol (johanknol) Date: 2003-01-10 01:31 Message: Logged In: YES user_id=63512 GCC doesn't do that either, so I think this is correct. Use dummy=x instead. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=663539&group_id=599 |