diff options
author | David Malcolm <dmalcolm@redhat.com> | 2019-04-05 15:15:37 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2019-04-05 15:15:37 +0000 |
commit | 34facf20abc583e66764733263f8412929f9eaf9 (patch) | |
tree | 00d9cefee641ffda0258a78ddcaeb28726ca59f6 /gcc | |
parent | fe7c4fa9818f0e75cf46e95d6117d3f9f73ebb2e (diff) | |
download | gcc-34facf20abc583e66764733263f8412929f9eaf9.zip gcc-34facf20abc583e66764733263f8412929f9eaf9.tar.gz gcc-34facf20abc583e66764733263f8412929f9eaf9.tar.bz2 |
Guard notes for -Waddress-of-packed-member on warning emission (PR c/89985)
gcc/c-family/ChangeLog:
PR c/89985
* c-warn.c (check_address_or_pointer_of_packed_member): Add
auto_diagnostic_group. Guard inform calls by result of
warning_at call.
gcc/testsuite/ChangeLog:
PR c/89985
* c-c++-common/pr89985.c: New test.
From-SVN: r270169
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c-family/c-warn.c | 25 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/pr89985.c | 19 |
4 files changed, 45 insertions, 11 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 5cce5de..f941403 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2019-04-05 David Malcolm <dmalcolm@redhat.com> + + PR c/89985 + * c-warn.c (check_address_or_pointer_of_packed_member): Add + auto_diagnostic_group. Guard inform calls by result of + warning_at call. + 2019-04-05 Marek Polacek <polacek@redhat.com> PR c++/89973 - -Waddress-of-packed-member ICE with invalid conversion. diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c index 05ea2bf..f6acc67 100644 --- a/gcc/c-family/c-warn.c +++ b/gcc/c-family/c-warn.c @@ -2783,18 +2783,21 @@ check_address_or_pointer_of_packed_member (tree type, tree rhs) unsigned int rhs_align = min_align_of_type (rhstype); if (rhs_align < type_align) { + auto_diagnostic_group d; location_t location = EXPR_LOC_OR_LOC (rhs, input_location); - warning_at (location, OPT_Waddress_of_packed_member, - "converting a packed %qT pointer (alignment %d) " - "to a %qT pointer (alignment %d) may result in an " - "unaligned pointer value", - rhstype, rhs_align, type, type_align); - tree decl = TYPE_STUB_DECL (rhstype); - if (decl) - inform (DECL_SOURCE_LOCATION (decl), "defined here"); - decl = TYPE_STUB_DECL (type); - if (decl) - inform (DECL_SOURCE_LOCATION (decl), "defined here"); + if (warning_at (location, OPT_Waddress_of_packed_member, + "converting a packed %qT pointer (alignment %d) " + "to a %qT pointer (alignment %d) may result in " + "an unaligned pointer value", + rhstype, rhs_align, type, type_align)) + { + tree decl = TYPE_STUB_DECL (rhstype); + if (decl) + inform (DECL_SOURCE_LOCATION (decl), "defined here"); + decl = TYPE_STUB_DECL (type); + if (decl) + inform (DECL_SOURCE_LOCATION (decl), "defined here"); + } } } return NULL_TREE; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c188628..83fccaa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-04-05 David Malcolm <dmalcolm@redhat.com> + + PR c/89985 + * c-c++-common/pr89985.c: New test. + 2019-04-05 Christophe Lyon <christophe.lyon@linaro.org> PR c/71598 diff --git a/gcc/testsuite/c-c++-common/pr89985.c b/gcc/testsuite/c-c++-common/pr89985.c new file mode 100644 index 0000000..82a7285 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr89985.c @@ -0,0 +1,19 @@ +/* Ensure that -Waddress-of-packed-member doesn't emit notes when + suppressed via -w, rather than -Wno-address-of-packed-member. */ + +/* { dg-do compile } */ +/* { dg-options "-w" } */ + +struct a { /* { dg-bogus "defined here" } */ + void *ptr; +} __attribute__((packed)); + +struct b { /* { dg-bogus "defined here" } */ + void *ptr; +}; + +void +test (struct a *p) +{ + struct b *q = (struct b *)p; +} |