[PATCH] D20561: Warn when taking address of packed member

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 15 17:37:59 PDT 2016


On Mon, Aug 15, 2016 at 6:20 PM, Matthias Braun <matze at braunis.de> wrote:
> MatzeB added a subscriber: MatzeB.
> MatzeB added a comment.
>
> The sanitizer code triggers this warning for code that looks conceptually like this:
>
>   typedef struct Bla { char bar; int foo; } __attribute__((packed));
>
>   uintptr_t getu(struct Bla *b) { return (uintptr_t)&b->foo; }
>
> Resulting in:
>
>   taking address of packed member 'foo' of class or structure
>         'Bla' may result in an unaligned pointer value
>         [-Waddress-of-packed-member]
>
> Of course the warning can be silenced with `return (uintptr_t)(char*)&b->foo;` still casting to an int type seems like a benign case for this warning so maybe we should exclude that?

I agree, it seems sensible to silence the warning in that case, yes.

~Aaron

>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D20561
>
>
>


More information about the cfe-commits mailing list