llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.77k stars 10.97k forks source link

[clang][libc++] std::addressof silences -Waddress-of-packed-member diagnostics. #96726

Open BlamKiwi opened 1 week ago

BlamKiwi commented 1 week ago

We recently had a bug where we were inadvertently taking an address of a packed member inside some template code. std::addressof appears to prevent -Waddress-of-packed-member diagnostics. It would be good if clang somehow treated std::addressof(x) as equivalent to &a for the purposes of providing diagnostics for -Waddress-of-packed-member.

Godbolt minimal example

In general, it looks like clang doesn't diagnose when an lvalue reference is taken to an unaligned member. For our use-case, it would be nice if -Waddress-of-packed-member would diagnose all lvalue references to unaligned members. Although I could understand if just adding a heuristic for std::addressof is more palatable.

philnik777 commented 1 week ago

This is definitely something that has to be addressed in clang. It should probably be fairly simple though, since addressof is already a builtin.