This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix -Waddress-of-packed-member ICE in unevaluated contexts (PR c++/91925)


On 9/29/19 6:11 AM, Jakub Jelinek wrote:
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?

OK.

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]