From: "Andrew Burgess" <aburgess@broadcom.com>
To: gdb-patches@sourceware.org
Subject: Re: [PATCH] Multi-dimensional Fortran arrays issue PR11104
Date: Tue, 23 Nov 2010 10:04:00 -0000 [thread overview]
Message-ID: <4CEB91BB.3010104@broadcom.com> (raw)
In-Reply-To: <20101123080203.GA9228@host0.dyn.jankratochvil.net>
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:
next prev parent reply other threads:[~2010-11-23 10:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-16 17:26 Andrew Burgess
2010-10-18 7:53 ` Andrew Burgess
2010-10-18 21:20 ` Jan Kratochvil
2010-10-19 16:23 ` Andrew Burgess
2010-11-17 8:45 ` Andrew Burgess
2010-11-22 7:10 ` Jan Kratochvil
2010-11-23 8:02 ` Jan Kratochvil
2010-11-23 10:04 ` Andrew Burgess [this message]
2010-11-23 17:23 ` Jan Kratochvil
2010-11-23 19:10 ` Jan Kratochvil
2010-10-18 21:21 ` Jan Kratochvil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CEB91BB.3010104@broadcom.com \
--to=aburgess@broadcom.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox