From 3c17e16e318408f9f4dd6a7a8d2f4a567bb85c93 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Mon, 2 Oct 2006 22:21:02 +0000 Subject: [PATCH] re PR c++/29226 (ICE in make_decl_rtl, at varasm.c:886) PR c++/29226 * typeck.c (cxx_sizeof_or_alignof_type): Tidy. In templates, do not try to actually evaluate sizeof for a VLA type. PR c++/29226 * g++.dg/template/vla1.C: New test. From-SVN: r117375 --- gcc/cp/ChangeLog | 6 ++++ gcc/cp/typeck.c | 41 ++++++++++++++-------------- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/template/vla1.C | 9 ++++++ 4 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/vla1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d21bf43836b..3c2ff365f9d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2006-10-02 Mark Mitchell + + PR c++/29226 + * typeck.c (cxx_sizeof_or_alignof_type): Tidy. In templates, do + not try to actually evaluate sizeof for a VLA type. + 2006-10-01 Mark Mitchell PR c++/29105 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 4713f05809c..9f8d5e4fad9 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1241,38 +1241,39 @@ compparms (tree parms1, tree parms2) tree cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain) { - enum tree_code type_code; tree value; - const char *op_name; gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR); if (type == error_mark_node) return error_mark_node; - if (dependent_type_p (type)) - { - value = build_min (op, size_type_node, type); - TREE_READONLY (value) = 1; - return value; - } - - op_name = operator_name_info[(int) op].name; - type = non_reference (type); - type_code = TREE_CODE (type); - - if (type_code == METHOD_TYPE) + if (TREE_CODE (type) == METHOD_TYPE) { if (complain && (pedantic || warn_pointer_arith)) - pedwarn ("invalid application of %qs to a member function", op_name); + pedwarn ("invalid application of %qs to a member function", + operator_name_info[(int) op].name); value = size_one_node; } - else - value = c_sizeof_or_alignof_type (complete_type (type), - op == SIZEOF_EXPR, - complain); - return value; + if (dependent_type_p (type) + /* VLA types will have a non-constant size. In the body of an + uninstantiated template, we don't need to try to compute the + value, because the sizeof expression is not an integral + constant expression in that case. And, if we do try to + compute the value, we'll likely end up with SAVE_EXPRs, which + the template substitution machinery does not expect to see. */ + || (processing_template_decl && + TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)) + { + value = build_min (op, size_type_node, type); + TREE_READONLY (value) = 1; + return value; + } + + return c_sizeof_or_alignof_type (complete_type (type), + op == SIZEOF_EXPR, + complain); } /* Process a sizeof expression where the operand is an expression. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b4c70d2df5c..2b1bcadafdb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-10-02 Mark Mitchell + + PR c++/29226 + * g++.dg/template/vla1.C: New test. + 2006-10-02 Francois-Xavier Coudert PR fortran/29210 diff --git a/gcc/testsuite/g++.dg/template/vla1.C b/gcc/testsuite/g++.dg/template/vla1.C new file mode 100644 index 00000000000..fe93440f1f2 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/vla1.C @@ -0,0 +1,9 @@ +// PR c++/29226 +// { dg-options "" } + +template +static int label (int w) +{ + sizeof(int[w]); +} +int a = label(1); -- 2.30.2