r278483 - This patch implements PR#22821.

Joerg Sonnenberger via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 1 23:24:20 PDT 2016

On Sat, Oct 01, 2016 at 11:28:39PM +0200, Joerg Sonnenberger via cfe-commits wrote:
> On Fri, Aug 12, 2016 at 08:04:13AM -0000, Roger Ferrer Ibanez via cfe-commits wrote:
> > Author: rogfer01
> > Date: Fri Aug 12 03:04:13 2016
> > New Revision: 278483
> > 
> > URL: http://llvm.org/viewvc/llvm-project?rev=278483&view=rev
> > Log:
> > This patch implements PR#22821.
> > 
> > Taking the address of a packed member is dangerous since the reduced
> > alignment of the pointee is lost. This can lead to memory alignment
> > faults in some architectures if the pointer value is dereferenced.
> This triggers on LVM in a rather obvious false positive:
>     (uintptr_t) &lh->offset_xl
> Given that one correct use case is to take the address and cast it to
> void * (or uintptr_t) for use without caring about alignment, the
> warning clearly needs to be refined.

Looking more at it, I request this warning to be disabled by default. In
the current form it is useless and just makes it impossible to use
packed structures at all. Before reenabling, it should handling:
(1) Assignment to pointer with reduced alignment
(2) Casts to pointer with reduced alignment
(3) Use as function argument with implicit cast like (2).

at the very least to cover normal use of packed member pointers.


More information about the cfe-commits mailing list