arphaman removed rL LLVM as the repository for this revision.
arphaman updated this revision to Diff 73076.
arphaman added a comment.

I had to reuploaded the diff as Phabricator seemed to have removed the 'lib' 
and 'test' paths prefixes from the filenames in the original diff.


https://reviews.llvm.org/D25106

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


Index: test/Sema/address-packed.c
===================================================================
--- test/Sema/address-packed.c
+++ test/Sema/address-packed.c
@@ -161,3 +161,27 @@
 {
     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'}}
+}
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11279,8 +11279,13 @@
 
 void Sema::DiagnoseMisalignedMembers() {
   for (MisalignedMember &m : MisalignedMembers) {
+    const NamedDecl *ND = m.RD;
+    if (ND->getName().empty()) {
+      if (const auto *TypedefDecl = m.RD->getTypedefNameForAnonDecl())
+        ND = TypedefDecl;
+    }
     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();
 }


Index: test/Sema/address-packed.c
===================================================================
--- test/Sema/address-packed.c
+++ test/Sema/address-packed.c
@@ -161,3 +161,27 @@
 {
     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'}}
+}
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11279,8 +11279,13 @@
 
 void Sema::DiagnoseMisalignedMembers() {
   for (MisalignedMember &m : MisalignedMembers) {
+    const NamedDecl *ND = m.RD;
+    if (ND->getName().empty()) {
+      if (const auto *TypedefDecl = m.RD->getTypedefNameForAnonDecl())
+        ND = TypedefDecl;
+    }
     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();
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to