From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 503 invoked by alias); 9 Apr 2011 11:22:49 -0000 Received: (qmail 495 invoked by uid 22791); 9 Apr 2011 11:22:49 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,FSL_RU_URL X-Spam-Check-By: sourceware.org Received: from matups.math.u-psud.fr (HELO matups.math.u-psud.fr) (129.175.50.4) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 09 Apr 2011 11:22:44 +0000 Received: from barah.math.u-psud.fr (barah.math.u-psud.fr [129.175.52.24]) by matups.math.u-psud.fr (Postfix) with ESMTP id 8916872F9 for ; Sat, 9 Apr 2011 13:22:42 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by barah.math.u-psud.fr (Postfix) with ESMTP id 8609A474062 for ; Sat, 9 Apr 2011 13:22:42 +0200 (CEST) Received: from barah.math.u-psud.fr ([127.0.0.1]) by localhost (barah.math.u-psud.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2gnjmVePEyY6 for ; Sat, 9 Apr 2011 13:22:40 +0200 (CEST) Received: from [IPv6:::1] (topodyn-ng.math.u-psud.fr [129.175.50.33]) by barah.math.u-psud.fr (Postfix) with ESMTP id DDA01474061 for ; Sat, 9 Apr 2011 13:22:40 +0200 (CEST) Message-ID: <4DA04180.9040404@free.fr> Date: Sat, 09 Apr 2011 11:22:00 -0000 From: Duncan Sands User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110406 Thunderbird/3.1.9 MIME-Version: 1.0 To: gcc-patches Subject: [PATCH] Do not crash in array_type_nelts if TYPE_MIN_VALUE is null Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-04/txt/msg00682.txt.bz2 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 + + * tree.c (array_type_nelts): Bail out if TYPE_MAX_VALUE not set. + 2011-04-08 Anatoly Sokolov * doc/tm.texi.in (ASM_OUTPUT_BSS): Remove documentation.