Messages in this thread | | | Subject | Re: [PATCH] [v2] x86: apic: avoid -Wshadow warning in header | From | Paolo Bonzini <> | Date | Fri, 30 Oct 2020 19:16:50 +0100 |
| |
On 29/10/20 23:12, David Laight wrote: >> https://godbolt.org/z/4dzPbM >> >> With -fno-strict-aliasing, the compiler reloads the pointer if you write >> to the start of what it points to, but not if you write to later >> elements. > I guess it assumes that global data doesn't overlap.
Yeah, setting
p = (struct s *) ((char *)&p) - 8;
invokes undefined behavior _for a different reason than strict aliasing_ (it's a pointer that is based on "p" but points before its start or after one byte past its end). So the compiler assumes that only the first few bytes of a global can overlap it.
If you change the size of the fields from long to char in the compiler explorer link above, every field forces a reload of the global.
Paolo
| |