From f091ee191c503faa298df9410159b90cf3bde03a Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 17 Nov 2015 18:09:36 +0000 Subject: [PATCH] PR c++/68308 - [6 Regression] ICE: tree check: expected integer_cst, have var_decl in decompose, at tree.h:5105 gcc/ * cp/init.c (build_new_1): Check for expression constness the right way. testsuite/ * g++.dg/init/new46.C: New test. From-SVN: r230468 --- gcc/ChangeLog | 6 +++ gcc/cp/init.c | 5 ++- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/g++.dg/init/new46.C | 65 +++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/new46.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b9bb07c07ce..747dea3bc26 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-11-17 Martin Sebor + + PR c++/68308 + * cp/init.c (build_new_1): Check for expression constness + the right way. + 2015-11-17 Sandra Loosemore PR target/56036 diff --git a/gcc/cp/init.c b/gcc/cp/init.c index fccd2896a87..5ecf9fb1cad 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2715,7 +2715,7 @@ build_new_1 (vec **placement, tree type, tree nelts, size = size_binop (MULT_EXPR, size, fold_convert (sizetype, nelts)); - if (TREE_CONSTANT (outer_nelts)) + if (INTEGER_CST == TREE_CODE (outer_nelts)) { if (tree_int_cst_lt (max_outer_nelts_tree, outer_nelts)) { @@ -3330,7 +3330,8 @@ build_new (vec **placement, tree type, tree nelts, non-class type and its value before converting to std::size_t is less than zero. ... If the expression is a constant expression, the program is ill-fomed. */ - if (TREE_CONSTANT (cst_nelts) && tree_int_cst_sgn (cst_nelts) == -1) + if (INTEGER_CST == TREE_CODE (cst_nelts) + && tree_int_cst_sgn (cst_nelts) == -1) { if (complain & tf_error) error ("size of array is negative"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 850758b45d6..69adb07627e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-17 Martin Sebor + + PR c++/68308 + * g++.dg/init/new46.C: New test. + 2015-11-17 Dominique d'Humieres PR fortran/65751 diff --git a/gcc/testsuite/g++.dg/init/new46.C b/gcc/testsuite/g++.dg/init/new46.C new file mode 100644 index 00000000000..9fd747e98d2 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/new46.C @@ -0,0 +1,65 @@ +// { dg-do compile } +// { dg-options "-Wall" } + +// Test for c++/68308 - [6 Regression] ICE: tree check: expected integer_cst, +// have var_decl in decompose, at tree.h:5105 + +typedef __typeof__ (sizeof 0) size_t; + +// Not defined, only referenced in templates that aren't expected +// to be instantiated to make sure they really aren't to verify +// verify c++/68308. +template void inst_check (); + +// Not instantiated (must not be diagnosed). +template +char* fn1_x () { + const size_t a = sizeof (T); + return inst_check() ? new char [a] : 0; +} + +// Not instantiated (must not be diagnosed). +template +char* fn2_1_x () { + return inst_check() ? new char [N] : 0; +} + +template +char* fn2_1 () { + return new char [N]; +} + +// Not instantiated (must not be diagnosed). +template +char* fn2_2_x () { + return inst_check() ? new char [M][N] : 0; +} + +template +char* fn2_2 () { + return new char [M][N]; // { dg-error "size of array is too large" } +} + +// Not instantiated (must not be diagnosed). +template +T* fn3_x () { + const size_t a = sizeof (T); + return inst_check() ? new T [a] : 0; +} + +template +T* fn3 () { + const size_t a = sizeof (T); + return new T [a]; // { dg-error "size of array is too large" } +} + + +struct S { char a [__SIZE_MAX__ / 8]; }; + +void foo () +{ + fn2_1<1>(); + fn2_1<__SIZE_MAX__ / 4>(); + fn2_2<__SIZE_MAX__ / 4, 4>(); + fn3(); +} -- 2.30.2