[PATCH] D25106: Packed member warning: Use the typedef name for anonymous structures when it is available

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 5 02:36:55 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL283304: [Sema] Packed member warning: Use the typedef name for anonymous structures (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D25106?vs=73338&id=73611#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25106

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/Sema/address-packed.c


Index: cfe/trunk/test/Sema/address-packed.c
===================================================================
--- cfe/trunk/test/Sema/address-packed.c
+++ cfe/trunk/test/Sema/address-packed.c
@@ -161,3 +161,38 @@
 {
     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)'}}
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -11372,8 +11372,13 @@
 
 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();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25106.73611.patch
Type: text/x-patch
Size: 1912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161005/9ae54ebb/attachment-0001.bin>


More information about the cfe-commits mailing list