On Wed, Apr 03, 2013 at 10:47:28AM -0700, Ian Lance Taylor wrote: > On Wed, Apr 3, 2013 at 9:33 AM, Paul E. McKenney > <paulmck@xxxxxxxxxxxxxxxxxx> wrote: > > On Wed, Apr 03, 2013 at 06:45:51AM -0700, Ian Lance Taylor wrote: > > > >> The C language standard only describes how access to > >> volatile-qualified objects behave. In this case x is (presumably) not > >> a volatile-qualifed object. The standard never defines the behaviour > >> of volatile-qualified pointers. That might seem like an oversight, > >> but it is not: using a non-volatile-qualified pointer to access a > >> volatile-qualified object is undefined behaviour. > >> > >> In short, casting a pointer to a non-volatile-qualified object to a > >> volatile-qualified pointer has no specific meaning in C. It's true > >> that most compilers will behave as you wish, but there is no > >> guarantee. > > > > But we are not using a non-volatile-qualified pointer to access a > > volatile-qualified object. We are doing the opposite. I therefore > > don't understand the relevance of your comment about undefined behavior. > > That was just a digression to explain why the standard does not need > to define the behaviour of volatile-qualified pointers. > > > >> If using a sufficiently recent version of GCC, you can get the > >> behaviour that I think you want by using > >> __atomic_load(&x, __ATOMIC_RELAXED) > > > > If this maps to the memory_order_relaxed token defined in earlier versions > > of the C11 standard, then this absolutely does -not-, repeat -not-, work > > for ACCESS_ONCE(). > > Yes, I'm sorry, you are right. It will work in practice today but > you're quite right that there is no reason to think that it will work > in principle. > > This need suggests that GCC needs a new builtin function to implement > the functionality that you want. Would you consider opening a request > for that at http://gcc.gnu.org/bugzilla/ ? How about a request for gcc to formally honor the current uses of volatile? Thanx, Paul -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>