[cfe-dev] Spurious register spill with volatile function argument
Florian Weimer via cfe-dev
cfe-dev at lists.llvm.org
Mon Mar 28 05:11:58 PDT 2016
* Andrew Haley:
> "volatile" doesn't really mean very much, formally speaking. Sure, the
> standard says "accesses to volatile objects are evaluated
> strictly according to the rules of the abstract machine," but nowhere
> is it specified exactly what constitutes an access.
Reading or modifying an object is defined as “access”.
The problem is that “reading” is either not defined, or the existing
flatly contradicts existing practice.
For example, if p is a pointer to a struct, will the expression &p->m
Previously, this wasn't very interesting. But under the model memory,
it's suddenly quite relevant. If reading p->m implies a read of the
entire object *p, you cannot use a member to synchronize access to
other members of the struct. For example, if m is a mutex, and
carefully acquire the mutex before you read or write other members,
you still have data race between a write to some other member and the
acquisition of the mutex because the mutex acquisition reads the
entire struct (including the member written to ).
One possible cure is to take the address of the mutex and keep track
of it separately. Or you could construct a pointer using offsetof.
But no one is doing that, obviously.
This is not entirely hypothetical. Even today, GCC's aliasing
analysis requires that those implicit whole-object reads take place,
to make certain forms of type-punning invalid which would otherwise be
well-defined (and for which GCC would generate invalid code).
More information about the cfe-dev