On 04/17/19 20:31, Andrew Fish wrote: > I was actually writing a mail to some people that sit on the C/C++ > standards committee that are UB experts to get some clarification when > you sent this mail. [...] > > I'm basically asking if this code pedantic conforms to C99 and C11: > > EFI_COMMON_SECTION_HEADER gSec = { { 0x01, 0x02, 0x3 }, 0x10 }; > > return *(UINT32 *)gSec.Size & 0x00ffffff;
I'm really interested as to how they will respond! (Because I think (see up-thread) that the code doesn't conform.) > I ran the clang static analyzer and runtime ubsan on the above code > and it did not complain (I force strict aliasing via > -fstrict-aliasing, and I'm using the Sys V ABI since this is just the > command line compiler on my Mac). Yesterday I tried something similar with both gcc and clang (not recent versions of them, unfortunately), and they were all too happy with the code as well, when I thought they should have flagged it. The options I used were: -fsyntax-only -Wall -Wextra -std=c99 -pedantic \ -fstrict-aliasing -Wstrict-aliasing Beyond that, I checked the documentation of "-fstrict-aliasing" in the gcc manual at <https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/Optimize-Options.html>. It provides several examples; one of them is: > Similarly, access by taking the address, casting the resulting pointer > and dereferencing the result has undefined behavior, even if the cast > uses a union type, e.g.: > > union a_union { > int i; > double d; > }; > > int f() { > double d = 3.0; > return ((union a_union *) &d)->i; > } I think the access in this example is well defined (I seem able to deduce it using the effective type rules), and so I consider this a bug in the gcc docs. I reached out to someone in the toolchain team at Red Hat to confirm or disprove. Thanks Laszlo -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#39289): https://edk2.groups.io/g/devel/message/39289 Mute This Topic: https://groups.io/mt/31070304/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-