This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Do not crash in array_type_nelts if TYPE_MIN_VALUE is null
- From: Duncan Sands <baldrick at free dot fr>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 09 Apr 2011 13:22:40 +0200
- Subject: [PATCH] Do not crash in array_type_nelts if TYPE_MIN_VALUE is null
I recently changed the dragonegg plugin to use array_type_nelts, and just got
sent a Fortran testcase that shows that array_type_nelts can crash on array
types coming from Fortran. The array type in question has TYPE_DOMAIN set,
with TYPE_MIN_VALUE equal to 1 (because the array is indexed from 1) but no
TYPE_MAX_VALUE (because the array length is not known). Here's a patch that
fixes array_type_nelts. Unfortunately I don't have a testcase that shows the
issue without the use of the dragonegg plugin.
Tested by bootstrapping mainline and running the testsuite with gcc-4.5. OK to
apply on mainline and the 4.5 and 4.6 branches?
Ciao, Duncan.
Index: gcc/tree.c
===================================================================
--- gcc/tree.c (revision 172166)
+++ gcc/tree.c (working copy)
@@ -2462,6 +2462,10 @@
min = TYPE_MIN_VALUE (index_type);
max = TYPE_MAX_VALUE (index_type);
+ /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
+ if (!max)
+ return error_mark_node;
+
return (integer_zerop (min)
? max
: fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
Index: gcc/ChangeLog
===================================================================
--- gcc/ChangeLog (revision 172166)
+++ gcc/ChangeLog (working copy)
@@ -1,3 +1,7 @@
+2011-04-08 Duncan Sands <baldrick@free.fr>
+
+ * tree.c (array_type_nelts): Bail out if TYPE_MAX_VALUE not set.
+
2011-04-08 Anatoly Sokolov <aesok@post.ru>
* doc/tm.texi.in (ASM_OUTPUT_BSS): Remove documentation.