This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] fix c++/68308 - [6 Regression] ICE: tree check: expected integer_cst
- From: Martin Sebor <msebor at gmail dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Cc: Jason Merrill <jason at redhat dot com>
- Date: Tue, 17 Nov 2015 11:06:27 -0700
- Subject: [PATCH] fix c++/68308 - [6 Regression] ICE: tree check: expected integer_cst
- Authentication-results: sourceware.org; auth=none
Attached is a patch fixing the ICE caused by a prior change of mine:
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=230081
Tested on x86_64, committing to trunk as per Jason via IRC.
Martin
gcc/ChangeLog:
2015-11-17 Martin Sebor <msebor@redhat.com>
PR c++/68308
* cp/init.c (build_new_1): Check for expression constness
the right way.
testsuite/ChangeLog:
2015-11-17 Martin Sebor <msebor@redhat.com>
PR c++/68308
* g++.dg/init/new46.C: New test.
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c (revision 230463)
+++ gcc/cp/init.c (working copy)
@@ -2715,7 +2715,7 @@
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 @@
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");
Index: gcc/testsuite/g++.dg/init/new46.C
===================================================================
--- gcc/testsuite/g++.dg/init/new46.C (revision 0)
+++ gcc/testsuite/g++.dg/init/new46.C (working copy)
@@ -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 <class T> void inst_check ();
+
+// Not instantiated (must not be diagnosed).
+template <class T>
+char* fn1_x () {
+ const size_t a = sizeof (T);
+ return inst_check<T>() ? new char [a] : 0;
+}
+
+// Not instantiated (must not be diagnosed).
+template <size_t N>
+char* fn2_1_x () {
+ return inst_check<char [N]>() ? new char [N] : 0;
+}
+
+template <size_t N>
+char* fn2_1 () {
+ return new char [N];
+}
+
+// Not instantiated (must not be diagnosed).
+template <size_t M, size_t N>
+char* fn2_2_x () {
+ return inst_check<char [M][N]>() ? new char [M][N] : 0;
+}
+
+template <size_t M, size_t N>
+char* fn2_2 () {
+ return new char [M][N]; // { dg-error "size of array is too large" }
+}
+
+// Not instantiated (must not be diagnosed).
+template <class T>
+T* fn3_x () {
+ const size_t a = sizeof (T);
+ return inst_check<T>() ? new T [a] : 0;
+}
+
+template <class T>
+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<S>();
+}