[Bug c/96293] Extraneously noisy "taking address of packed member may result in an unaligned pointer value"

lavr at ncbi dot nlm.nih.gov gcc-bugzilla@gcc.gnu.org
Mon Jul 27 16:08:52 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96293

--- Comment #5 from lavr at ncbi dot nlm.nih.gov ---
My test case is not invalid.  You're talking about base address of a structure,
which would make offsets within it all unaligned, which is why I said "the same
rule should apply for aggregates".  So should "struct S" appear anywhere in an
outer structure at an offset, which would not be its "native offset otherwise
assigned by GCC, as if it wasn't packed", then there's a potential problem. 
Otherwise, the member addresses will still remain well-aligned, and no warnings
would be ever necessary.  As for your example, any structure's address can be
type-cast to any value (it's C, for the sake of it), yet GCC doesn't assume
that happens for non-packed structures, right?

Extra warnings in large projects are disruptive, and if GCC warns about
something, it should be well-warranted and verified.  Applying a bit of an
extra-logic (which does not take a lot of CPU cycles, or additional compilation
time) for those new warnings, and not issuing them just mechanically, would
help a lot.


More information about the Gcc-bugs mailing list