r283304 - [Sema] Packed member warning: Use the typedef name for anonymous structures
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 5 02:27:49 PDT 2016
Author: arphaman
Date: Wed Oct 5 04:27:48 2016
New Revision: 283304
URL: http://llvm.org/viewvc/llvm-project?rev=283304&view=rev
Log:
[Sema] Packed member warning: Use the typedef name for anonymous structures
This commit improves the packed member warning by showing the name of the
anonymous structure/union when it was defined within a typedef declaration.
rdar://28498901
Differential Revision: https://reviews.llvm.org/D25106
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/address-packed.c
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=283304&r1=283303&r2=283304&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Oct 5 04:27:48 2016
@@ -11372,8 +11372,13 @@ void Sema::AddPotentialMisalignedMembers
void Sema::DiagnoseMisalignedMembers() {
for (MisalignedMember &m : MisalignedMembers) {
+ const NamedDecl *ND = m.RD;
+ if (ND->getName().empty()) {
+ if (const TypedefNameDecl *TD = m.RD->getTypedefNameForAnonDecl())
+ ND = TD;
+ }
Diag(m.E->getLocStart(), diag::warn_taking_address_of_packed_member)
- << m.MD << m.RD << m.E->getSourceRange();
+ << m.MD << ND << m.E->getSourceRange();
}
MisalignedMembers.clear();
}
Modified: cfe/trunk/test/Sema/address-packed.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address-packed.c?rev=283304&r1=283303&r2=283304&view=diff
==============================================================================
--- cfe/trunk/test/Sema/address-packed.c (original)
+++ cfe/trunk/test/Sema/address-packed.c Wed Oct 5 04:27:48 2016
@@ -161,3 +161,38 @@ struct AlignedTo2Bis* g7(struct AlignedT
{
return (struct AlignedTo2Bis*)&s->x; // no-warning
}
+
+typedef struct {
+ char c;
+ int x;
+} __attribute__((packed)) TypedefStructArguable;
+
+typedef union {
+ char c;
+ int x;
+} __attribute((packed)) TypedefUnionArguable;
+
+typedef TypedefStructArguable TypedefStructArguableTheSecond;
+
+int *typedef1(TypedefStructArguable *s) {
+ return &s->x; // expected-warning {{packed member 'x' of class or structure 'TypedefStructArguable'}}
+}
+
+int *typedef2(TypedefStructArguableTheSecond *s) {
+ return &s->x; // expected-warning {{packed member 'x' of class or structure 'TypedefStructArguable'}}
+}
+
+int *typedef3(TypedefUnionArguable *s) {
+ return &s->x; // expected-warning {{packed member 'x' of class or structure 'TypedefUnionArguable'}}
+}
+
+struct S6 {
+ union {
+ char c;
+ int x;
+ } __attribute__((packed));
+};
+
+int *anonymousInnerUnion(struct S6 *s) {
+ return &s->x; // expected-warning {{packed member 'x' of class or structure 'S6::(anonymous)'}}
+}
More information about the cfe-commits
mailing list