This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR27384: ICE in size_binop, at fold-const.c:1736
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 11 May 2006 09:08:40 +0200 (CEST)
- Subject: [patch] Fix PR27384: ICE in size_binop, at fold-const.c:1736
The C++ frontend ICEs on the following code snippet:
struct A
{
static const int i = i;
int x[i];
};
bug.cc:3: error: 'i' was not declared in this scope
bug.cc:4: internal compiler error: in size_binop, at fold-const.c:1736
Please submit a full bug report, [etc]
The assert at the beginning of size_binop triggers because one of the
arguments is an error_mark_node:
gcc_assert (TREE_CODE (type) == INTEGER_TYPE && TYPE_IS_SIZETYPE (type)
&& type == TREE_TYPE (arg1));
The function already has appropriate sanity checking for the arguments,
but alas this is located after the assert:
if (arg0 == error_mark_node || arg1 == error_mark_node)
return error_mark_node;
The patch below fixes the ICE by moving this check before the assert.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?
Regards,
Volker
:ADDPATCH middle-end:
2006-05-11 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR middle-end/27384
* fold-const.c (size_binop): Move sanity check for arguments to
the beginning of the function.
===================================================================
--- gcc/gcc/fold-const.c (revision 113669)
+++ gcc/gcc/fold-const.c (working copy)
@@ -1732,6 +1732,9 @@ size_binop (enum tree_code code, tree arg0,
{
tree type = TREE_TYPE (arg0);
+ if (arg0 == error_mark_node || arg1 == error_mark_node)
+ return error_mark_node;
+
gcc_assert (TREE_CODE (type) == INTEGER_TYPE && TYPE_IS_SIZETYPE (type)
&& type == TREE_TYPE (arg1));
@@ -1751,9 +1754,6 @@ size_binop (enum tree_code code, tree arg0,
return int_const_binop (code, arg0, arg1, 0);
}
- if (arg0 == error_mark_node || arg1 == error_mark_node)
- return error_mark_node;
-
return fold_build2 (code, type, arg0, arg1);
}
===================================================================
2006-05-11 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR middle-end/27384
* g++.dg/other/fold1.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/other/fold1.C 2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/other/fold1.C 2006-05-10 18:47:18 +0200
@@ -0,0 +1,8 @@
+// PR middle-end/27384
+// { dg-do compile }
+
+struct A
+{
+ static const int i = i; // { dg-error "not declared" }
+ int x[i]; // { dg-error "variable-size array" }
+};
===================================================================