As one data-point to consider when making up our mind about how to implement volatile accesses we make a survey of how other compilers (old GCC versions and different compilers) implement them. In particular we are interested in when exactly a volatile object is re-read even though it's the LHS of an assignment. See http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02001.html for the thread which started this. We use this testprogram:
volatile int vobj1, vobj2, vobj3, vobj4, vobj5, vobj6, vobj7, vobj8, vobj9;
int x, y, z;
void f1 (int i)
{
vobj1 = y;
x = vobj2 = y;
x ? vobj3 = y : z;
x = y ? vobj4 = z : i;
vobj5;
vobj6 = 42;
x = vobj7 = 43;
x ? vobj8 = 44 : z;
x = y ? vobj9 = 45 : i;
}The following table shows which variables are re-read for which compilers (and possibly with which options).
Compiler |
vojb1 |
vobj2 |
vobj3 |
vobj4 |
vobj5 |
vobj6 |
vobj7 |
vobj8 |
vobj9 |
Notes |
GCC 3.3 |
|
x |
|
x |
x |
|
x |
|
|
same behaviour of C and C++, optimization options don't matter |
GCC 4.3.3 |
|
x |
x |
x |
x |
|
x |
|
|
|
G++ 4.3.3 |
|
x |
|
x |
x |
|
x |
|
x |
|
r161389 (pre 4.6) |
|
x |
x |
x |
x |
|
x |
x |
x |
same behaviour of C and C++, options don't matter |
ICC (C) |
|
|
|
|
x |
|
|
|
|
options don't matter, version 11.0 and 11.1 behave the same |
ICC (C++) |
|
|
|
|
|
|
|
|
|
options don't matter, version 11.1 and 11.1 behave the same |
RealView 3.1 (C) |
|
|
|
|
x |
|
|
|
|
options don't matter |
RealView 3.1 (C++) |
|
|
|
|
|
|
|
|
|
options don't matter |
RealView 4.0 (C) |
|
|
|
|
x |
|
|
|
|
options don't matter |
RealView 4.0 (C++) |
|
|
|
|
|
|
|
|
|
options don't matter |
VC++ 2010 (C++) |
|
x |
x |
x |
x |
|
x |
x |
x |
options don't matter |