aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-02-14 22:02:43 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-02-14 15:02:43 -0700
commitfba303ed8c190cc2b8695d737efd7af409596398 (patch)
tree002e7f40bf82a0465272aea8e6c554cac2590d82 /gcc
parentee3bb1b7a2f73c9ccc99b0861e8a3408d408ca2d (diff)
downloadgcc-fba303ed8c190cc2b8695d737efd7af409596398.zip
gcc-fba303ed8c190cc2b8695d737efd7af409596398.tar.gz
gcc-fba303ed8c190cc2b8695d737efd7af409596398.tar.bz2
PR middle-end/84108 - incorrect -Wattributes warning for packed/aligned conflict on struct members
gcc/ChangeLog: PR c/84108 * attribs.c (diag_attr_exclusions): Consider the exclusion(s) that correspond to the kind of a declaration. gcc/testsuite/ChangeLog: PR c/84108 * gcc.dg/Wattributes-8.c: New test. From-SVN: r257674
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/attribs.c16
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/Wattributes-8.c38
4 files changed, 65 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 97067a3..e16acd4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2018-02-14 Martin Sebor <msebor@redhat.com>
+
+ PR c/84108
+ * attribs.c (diag_attr_exclusions): Consider the exclusion(s)
+ that correspond to the kind of a declaration.
+
2018-02-14 John David Anglin <danglin@gcc.gnu.org>
PR target/83984
diff --git a/gcc/attribs.c b/gcc/attribs.c
index 2cac9c4..140863b 100644
--- a/gcc/attribs.c
+++ b/gcc/attribs.c
@@ -410,6 +410,22 @@ diag_attr_exclusions (tree last_decl, tree node, tree attrname,
if (!lookup_attribute (excl->name, attrs[i]))
continue;
+ /* An exclusion may apply either to a function declaration,
+ type declaration, or a field/variable declaration, or
+ any subset of the three. */
+ if (TREE_CODE (node) == FUNCTION_DECL
+ && !excl->function)
+ continue;
+
+ if (TREE_CODE (node) == TYPE_DECL
+ && !excl->type)
+ continue;
+
+ if ((TREE_CODE (node) == FIELD_DECL
+ || TREE_CODE (node) == VAR_DECL)
+ && !excl->variable)
+ continue;
+
found = true;
/* Print a note? */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e3d1cec..2044efc 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-02-14 Martin Sebor <msebor@redhat.com>
+
+ PR c/84108
+ * gcc.dg/Wattributes-8.c: New test.
+
2018-02-14 Janus Weil <janus@gcc.gnu.org>
PR fortran/84385
diff --git a/gcc/testsuite/gcc.dg/Wattributes-8.c b/gcc/testsuite/gcc.dg/Wattributes-8.c
new file mode 100644
index 0000000..a4b4c00
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wattributes-8.c
@@ -0,0 +1,38 @@
+/* PR middle-end/84108 - incorrect -Wattributes warning for packed/aligned
+ conflict on struct members
+ { dg-do compile }
+ { dg-options "-Wall -Wattributes" } */
+
+#define ATTR(list) __attribute__ (list)
+#define ASSERT(e) _Static_assert (e, #e)
+
+/* GCC is inconsistent in how it treats attribute aligned between
+ variable and member declarations. Attribute aligned alone is
+ sufficient to reduce a variable's alignment requirement but
+ the attribute must be paired with packed to have the same
+ effect on a member. Worse, declaring a variable both aligned
+ and packed emits a warning. */
+
+/* Avoid exercising this since emitting a warning for these given
+ the requirement for members seems like a misfeature:
+ int a ATTR ((packed, aligned (2))); // -Wattributes
+ int b ATTR ((aligned (2), packed)); // -Wattributes
+ ASSERT (_Alignof (a) == 2);
+ ASSERT (_Alignof (b) == 2); */
+
+int c ATTR ((aligned (2))); // okay (reduces alignment)
+ASSERT (_Alignof (c) == 2);
+
+struct {
+ int a ATTR ((packed, aligned (2))); /* { dg-bogus "\\\[-Wattributes" } */
+ int b ATTR ((aligned (2), packed)); /* { dg-bogus "\\\[-Wattributes" } */
+
+ /* Avoid exercising this since the attribute has no effect yet
+ there is no warning.
+ int c ATTR ((aligned (2))); // missing warning? */
+} s;
+
+ASSERT (_Alignof (s.a) == 2);
+ASSERT (_Alignof (s.b) == 2);
+
+/* ASSERT (_Alignof (s.c) == 4); */