This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 2/3] Avoid creating an initializer for a flexible array member
- From: Patrick Palka <patrick at parcs dot ath dot cx>
- To: gcc-patches at gcc dot gnu dot org
- Cc: jakub at redhat dot com, jason at redhat dot com, Patrick Palka <patrick at parcs dot ath dot cx>
- Date: Thu, 31 Dec 2015 10:40:16 -0500
- Subject: [PATCH 2/3] Avoid creating an initializer for a flexible array member
- Authentication-results: sourceware.org; auth=none
- References: <1451576417-8710-1-git-send-email-patrick at parcs dot ath dot cx>
If we do create such an initializer, we end up with an error_mark_node
during gimplification, because in cp-gimplify.c we pass this
VEC_INIT_EXPR of the flexible array member to build_vec_init, for which
it spits on an error_mark_node. This happens in e.g. the test case
g++.dg/ext/array1.C.
This patch makes it so that we avoid generating an initializer for a
flexible array member, thus avoiding to end up with an error_mark_node
during gimplification. The same kind of thing is done ~90 lines down
from the code I changed.
gcc/cp/ChangeLog:
* init.c (perform_member_init): Avoid creating an initializer
for a flexible array member.
---
gcc/cp/init.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 09c1183..0011178 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -645,9 +645,14 @@ perform_member_init (tree member, tree init)
/* mem() means value-initialization. */
if (TREE_CODE (type) == ARRAY_TYPE)
{
- init = build_vec_init_expr (type, init, tf_warning_or_error);
- init = build2 (INIT_EXPR, type, decl, init);
- finish_expr_stmt (init);
+ /* Initialize the array only if it's not a flexible
+ array member (i.e., if it has an upper bound). */
+ if (TYPE_DOMAIN (type) && TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
+ {
+ init = build_vec_init_expr (type, init, tf_warning_or_error);
+ init = build2 (INIT_EXPR, type, decl, init);
+ finish_expr_stmt (init);
+ }
}
else
{
--
2.7.0.rc3.56.g64157c6.dirty