Warn when taking address of a packed member
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 Differential Revision: http://reviews.llvm.org/D20561 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272552 91177308-0d34-0410-b5e6-96231b3b80d8
Showing
- include/clang/Basic/DiagnosticSemaKinds.td 3 additions, 0 deletionsinclude/clang/Basic/DiagnosticSemaKinds.td
- lib/Sema/SemaExpr.cpp 24 additions, 0 deletionslib/Sema/SemaExpr.cpp
- test/Sema/address-packed.c 126 additions, 0 deletionstest/Sema/address-packed.c
- test/SemaCXX/address-packed.cpp 100 additions, 0 deletionstest/SemaCXX/address-packed.cpp
test/Sema/address-packed.c
0 → 100644
test/SemaCXX/address-packed.cpp
0 → 100644
Please register or sign in to comment