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

Roger Ferrer Ibanez via cfe-commits cfe-commits at lists.llvm.org
Tue May 24 00:47:47 PDT 2016


rogfer01 created this revision.
rogfer01 added a reviewer: rsmith.
rogfer01 added a subscriber: cfe-commits.

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 change adds a new warning to clang emitted when taking the address
of a packed member. A packed member is either a field/data member
declared as __attribute__((packed)) or belonging to a struct/class
declared as such. The associated flag is -Waddress-of-packed-member

http://reviews.llvm.org/D20561

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/Sema/address-packed.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20561.58198.patch
Type: text/x-patch
Size: 6920 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160524/a3ab354b/attachment.bin>


More information about the cfe-commits mailing list