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

Matthias Braun via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 15 15:20:14 PDT 2016

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

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?



More information about the cfe-commits mailing list