This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Multi-dimensional Fortran arrays issue PR11104


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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]