* [PATCH] Do not crash in array_type_nelts if TYPE_MIN_VALUE is null
@ 2011-04-09 11:22 Duncan Sands
2011-04-09 15:45 ` Richard Guenther
0 siblings, 1 reply; 3+ messages in thread
From: Duncan Sands @ 2011-04-09 11:22 UTC (permalink / raw)
To: gcc-patches
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Do not crash in array_type_nelts if TYPE_MIN_VALUE is null
2011-04-09 11:22 [PATCH] Do not crash in array_type_nelts if TYPE_MIN_VALUE is null Duncan Sands
@ 2011-04-09 15:45 ` Richard Guenther
2011-04-09 16:21 ` Duncan Sands
0 siblings, 1 reply; 3+ messages in thread
From: Richard Guenther @ 2011-04-09 15:45 UTC (permalink / raw)
To: Duncan Sands; +Cc: gcc-patches
On Sat, Apr 9, 2011 at 1:22 PM, Duncan Sands <baldrick@free.fr> wrote:
> 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?
Ok.
Thanks,
Richard.
> 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.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Do not crash in array_type_nelts if TYPE_MIN_VALUE is null
2011-04-09 15:45 ` Richard Guenther
@ 2011-04-09 16:21 ` Duncan Sands
0 siblings, 0 replies; 3+ messages in thread
From: Duncan Sands @ 2011-04-09 16:21 UTC (permalink / raw)
To: Richard Guenther; +Cc: gcc-patches
On 09/04/11 17:45, Richard Guenther wrote:
> On Sat, Apr 9, 2011 at 1:22 PM, Duncan Sands<baldrick@free.fr> wrote:
>> 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?
>
> Ok.
Thanks - applied (mainline commit 172227).
Ciao, Duncan.
>
> Thanks,
> Richard.
>
>> 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.
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-04-09 16:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-09 11:22 [PATCH] Do not crash in array_type_nelts if TYPE_MIN_VALUE is null Duncan Sands
2011-04-09 15:45 ` Richard Guenther
2011-04-09 16:21 ` Duncan Sands
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).