ACCESS_ONCE()
Posted Aug 9, 2012 3:47 UTC (Thu) by
mmorrow (subscriber, #83845)
In reply to:
ACCESS_ONCE() by daglwn
Parent article:
ACCESS_ONCE()
Take a very simple but common issue: undefined data. There are countless compiler analyses and transformations that mode code around, reallocate stack space, etc. that cause the undefined variable to have different (garbage) values. What might happen to work one day most assuredly will not when compiled with a compiler 2-3 versions newer.
A good example of this can be seen in GCC's constant propagation implem (tree-ssa-ccp.c):
/*
...
- If an argument has an UNDEFINED value, then it does not affect
the outcome of the meet operation. If a variable V_i has an
UNDEFINED value, it means that either its defining statement
hasn't been visited yet or V_i has no defining statement, in
which case the original symbol 'V' is being used
uninitialized. Since 'V' is a local variable, the compiler
may assume any initial value for it.
...
*/
And we can see this in action with e.g.
size_t f(int x){size_t a; if(x) a = 42; return a;}
which gives
f:
movl $42, %eax
ret
.ident "GCC: (GNU) 4.8.0 20120408 (experimental)"
(
Log in to post comments)