From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19706 invoked by alias); 23 Nov 2010 10:04:59 -0000 Received: (qmail 19691 invoked by uid 22791); 23 Nov 2010 10:04:58 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mms3.broadcom.com (HELO MMS3.broadcom.com) (216.31.210.19) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 23 Nov 2010 10:04:52 +0000 Received: from [10.9.200.133] by MMS3.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Tue, 23 Nov 2010 02:05:03 -0800 X-Server-Uuid: B55A25B1-5D7D-41F8-BC53-C57E7AD3C201 Received: from mail-irva-13.broadcom.com (10.11.16.103) by IRVEXCHHUB02.corp.ad.broadcom.com (10.9.200.133) with Microsoft SMTP Server id 8.2.247.2; Tue, 23 Nov 2010 02:04:45 -0800 Received: from [10.177.69.119] (unknown [10.177.69.119]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 0DFA274D03 for ; Tue, 23 Nov 2010 02:04:43 -0800 (PST) Message-ID: <4CEB91BB.3010104@broadcom.com> Date: Tue, 23 Nov 2010 10:04:00 -0000 From: "Andrew Burgess" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101027 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Re: [PATCH] Multi-dimensional Fortran arrays issue PR11104 References: <89AE14E37D740B4796DC14566DF6325ECB7E173182@SJEXCHCCR02.corp.ad.broadcom.com> <89AE14E37D740B4796DC14566DF6325ECB7F0C2B39@SJEXCHCCR02.corp.ad.broadcom.com> <20101018211952.GA16206@host1.dyn.jankratochvil.net> <89AE14E37D740B4796DC14566DF6325ECB7F1F6E81@SJEXCHCCR02.corp.ad.broadcom.com> <89AE14E37D740B4796DC14566DF6325ECB7F8F140B@SJEXCHCCR02.corp.ad.broadcom.com> <20101123080203.GA9228@host0.dyn.jankratochvil.net> In-Reply-To: <20101123080203.GA9228@host0.dyn.jankratochvil.net> Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-11/txt/msg00346.txt.bz2 On 23/11/2010 08:02, Jan Kratochvil wrote: > On Wed, 17 Nov 2010 09:44:56 +0100, Andrew Burgess wrote: >> I'm happy to make any changes requested. > > I find there a problem it does not check all the bounds like the compiler does. > I did not try to fix it up myself to say more. Sorry for so late review. Thanks for taking the time to review this patch. The previous regression you pointed out (relating to the python interface) already led me to this same issue. Below is a revised patch that I think should solve this issue. I've not had time to look at the tests yet, but will try to do that in the next day or so. Thanks, Andrew --- gdb-7.2.50.20101122_clean/gdb/eval.c 2010-11-05 14:31:27.000000000 +0000 +++ gdb-7.2.50.20101122/gdb/eval.c 2010-11-23 09:57:57.703480325 +0000 @@ -2324,15 +2324,12 @@ multi_f77_subscript: { int subscript_array[MAX_FORTRAN_DIMS]; - int array_size_array[MAX_FORTRAN_DIMS]; int ndimensions = 1, i; - struct type *tmp_type; - int offset_item; /* The array offset where the item lives */ + struct value *array = arg1; if (nargs > MAX_FORTRAN_DIMS) error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS); - tmp_type = check_typedef (value_type (arg1)); ndimensions = calc_f77_array_dims (type); if (nargs != ndimensions) @@ -2343,59 +2340,34 @@ /* Now that we know we have a legal array subscript expression let us actually find out where this element exists in the array. */ - offset_item = 0; /* Take array indices left to right */ for (i = 0; i < nargs; i++) { /* Evaluate each subscript, It must be a legal integer in F77 */ arg2 = evaluate_subexp_with_coercion (exp, pos, noside); - /* Fill in the subscript and array size arrays */ - + /* Fill in the subscript array */ subscript_array[i] = value_as_long (arg2); } /* Internal type of array is arranged right to left */ - for (i = 0; i < nargs; i++) + for (i = nargs; i > 0; i--) { - upper = f77_get_upperbound (tmp_type); - lower = f77_get_lowerbound (tmp_type); + struct type* array_type = check_typedef (value_type (array)); + int offset = subscript_array[i - 1]; + upper = f77_get_upperbound (array_type); + lower = f77_get_lowerbound (array_type); - array_size_array[nargs - i - 1] = upper - lower + 1; + if ( (offset < lower) || (offset > upper) ) + error (_("Subscript number %d out of bounds, range %d to %d"), i, lower, upper); /* Zero-normalize subscripts so that offsetting will work. */ + offset -= lower; - subscript_array[nargs - i - 1] -= lower; - - /* If we are at the bottom of a multidimensional - array type then keep a ptr to the last ARRAY - type around for use when calling value_subscript() - below. This is done because we pretend to value_subscript - that we actually have a one-dimensional array - of base element type that we apply a simple - offset to. */ - - if (i < nargs - 1) - tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type)); + array = value_subscripted_rvalue (array, offset, 0); } - /* Now let us calculate the offset for this item */ - - offset_item = subscript_array[ndimensions - 1]; - - for (i = ndimensions - 1; i > 0; --i) - offset_item = - array_size_array[i - 1] * offset_item + subscript_array[i - 1]; - - /* Let us now play a dirty trick: we will take arg1 - which is a value node pointing to the topmost level - of the multidimensional array-set and pretend - that it is actually a array of the final element - type, this will ensure that value_subscript() - returns the correct type value */ - - deprecated_set_value_type (arg1, tmp_type); - return value_subscripted_rvalue (arg1, offset_item, 0); + return array; } case BINOP_LOGICAL_AND: