[PATCH] Do not crash in array_type_nelts if TYPE_MIN_VALUE is null

Duncan Sands baldrick@free.fr
Sat Apr 9 16:21:00 GMT 2011


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.
>>



More information about the Gcc-patches mailing list