This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix -Waddress-of-packed-member ICE in unevaluated contexts (PR c++/91925)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Nathan Sidwell <nathan at acm dot org>, "Joseph S. Myers" <joseph at codesourcery dot com>, Marek Polacek <polacek at redhat dot com>, "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sun, 29 Sep 2019 12:11:31 +0200
- Subject: [PATCH] Fix -Waddress-of-packed-member ICE in unevaluated contexts (PR c++/91925)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
On the following testcase we ICE, because check_alignment_of_packed_member
is called on the decltype expressions and the aggregate has not been laid
out.
The following patch fixes it by not emitting warnings on fields that weren't
laid out yet.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2019-09-28 Jakub Jelinek <jakub@redhat.com>
PR c++/91925
* c-warn.c (check_alignment_of_packed_member): Ignore FIELD_DECLs
with NULL DECL_FIELD_OFFSET.
* g++.dg/conversion/packed2.C: New test.
--- gcc/c-family/c-warn.c.jj 2019-09-20 12:25:06.393034759 +0200
+++ gcc/c-family/c-warn.c 2019-09-28 13:40:12.010732474 +0200
@@ -2798,6 +2798,8 @@ check_alignment_of_packed_member (tree t
/* Check alignment of the data member. */
if (TREE_CODE (field) == FIELD_DECL
&& (DECL_PACKED (field) || TYPE_PACKED (TREE_TYPE (field)))
+ /* Ignore FIELDs not laid out yet. */
+ && DECL_FIELD_OFFSET (field)
&& (!rvalue || TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE))
{
/* Check the expected alignment against the field alignment. */
--- gcc/testsuite/g++.dg/conversion/packed2.C.jj 2019-09-28 13:46:30.650025052 +0200
+++ gcc/testsuite/g++.dg/conversion/packed2.C 2019-09-28 13:41:48.513277844 +0200
@@ -0,0 +1,15 @@
+// PR c++/91925
+// { dg-do compile { target c++11 } }
+// { dg-options "-fpack-struct" }
+
+struct A {};
+int foo (A);
+struct B {
+ A a;
+ decltype (foo (a)) p;
+};
+template <typename T> T bar (T);
+class C {
+ A a;
+ decltype (bar (a)) p;
+};
Jakub