This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Don't pass VLA bounds with arbitrary C++ specific trees to build_array_type (PR c++/28879)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 19 Nov 2007 08:41:18 -0500
- Subject: [C++ PATCH] Don't pass VLA bounds with arbitrary C++ specific trees to build_array_type (PR c++/28879)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
Even when TYPE_MAX_VALUE (index_type) is not value_dependent_expression_p,
it can still contain various C++ FE tree nodes, which the middle-end won't
be happy about. Or do I need both v_d_e_p check and the VLA check?
Regtested on x86_64-linux.
This fixes just part of the PR though, the other testcase ICEs in
value_dependent_expression_p, because with VLAs inside of template
function/method bodies size in compute_array_index_type
can be almost arbitrary expression (including e.g. statement expressions,
etc.) and value_dependent_expression_p makes some assumptions on what it
can be fed with. That was introduced by Nathan in PR9043.
I wonder if we could get away without calling it altogether, run
integral_constant_value always and whenever that doesn't yield an
INTEGER_CST, use build_min on the original size rather than the folded.
Alternatively we need value_dependent_expression_p to handle really
arbitrary expressions (or copy/adjust it into a new function which will
do that).
2007-11-19 Jakub Jelinek <jakub@redhat.com>
PR c++/28879
* tree.c (build_cplus_array_type_1): Don't pass any VLA types
when processing_template_decl to build_array_type.
* g++.dg/template/vla2.C: New test.
--- gcc/cp/tree.c.jj 2007-11-10 01:14:58.000000000 +0100
+++ gcc/cp/tree.c 2007-11-19 13:28:16.000000000 +0100
@@ -531,7 +531,8 @@ build_cplus_array_type_1 (tree elt_type,
if (dependent_type_p (elt_type)
|| (index_type
- && value_dependent_expression_p (TYPE_MAX_VALUE (index_type))))
+ && processing_template_decl
+ && !TREE_CONSTANT (TYPE_MAX_VALUE (index_type))))
{
void **e;
cplus_array_info cai;
@@ -570,7 +571,7 @@ build_cplus_array_type_1 (tree elt_type,
TYPE_CANONICAL (t)
= build_cplus_array_type
(TYPE_CANONICAL (elt_type),
- index_type? TYPE_CANONICAL (index_type) : index_type);
+ index_type ? TYPE_CANONICAL (index_type) : index_type);
else
TYPE_CANONICAL (t) = t;
}
--- gcc/testsuite/g++.dg/template/vla2.C.jj 2007-11-19 13:52:29.000000000 +0100
+++ gcc/testsuite/g++.dg/template/vla2.C 2007-11-19 13:52:15.000000000 +0100
@@ -0,0 +1,20 @@
+// PR c++/28879
+// { dg-do compile }
+// { dg-options "" }
+
+struct A
+{
+ static int i;
+ int j;
+};
+
+template<int> void foo ()
+{
+ int x[A::i];
+//int y[A().j];
+}
+
+void bar ()
+{
+ foo<6> ();
+}
Jakub