* dwarf2read.c (struct attribute): Increase sizes of unsnd and snd
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index ac126cd7b13ba637bd898672ba50b414133bb0df..035f630c8495980523581e66a304c1454cb2074e 100644 (file)
@@ -711,7 +711,7 @@ allocate_stub_method (struct type *type)
 
 struct type *
 create_range_type (struct type *result_type, struct type *index_type,
-                  int low_bound, int high_bound)
+                  LONGEST low_bound, LONGEST high_bound)
 {
   if (result_type == NULL)
     result_type = alloc_type_copy (index_type);
@@ -721,10 +721,8 @@ create_range_type (struct type *result_type, struct type *index_type,
     TYPE_TARGET_STUB (result_type) = 1;
   else
     TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
-  TYPE_NFIELDS (result_type) = 2;
-  TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type,
-                                          TYPE_NFIELDS (result_type)
-                                          * sizeof (struct field));
+  TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
+    TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
   TYPE_LOW_BOUND (result_type) = low_bound;
   TYPE_HIGH_BOUND (result_type) = high_bound;
 
@@ -1475,17 +1473,34 @@ check_typedef (struct type *type)
          /* Now recompute the length of the array type, based on its
             number of elements and the target type's length.
             Watch out for Ada null Ada arrays where the high bound
-            is smaller than the low bound.  */
-         const int low_bound = TYPE_LOW_BOUND (range_type);
-         const int high_bound = TYPE_HIGH_BOUND (range_type);
-         int nb_elements;
-       
+            is smaller than the low bound. */
+         const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
+         const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
+         ULONGEST len;
+
          if (high_bound < low_bound)
-           nb_elements = 0;
-         else
-           nb_elements = high_bound - low_bound + 1;
-       
-         TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
+           len = 0;
+         else {
+           /* For now, we conservatively take the array length to be 0
+              if its length exceeds UINT_MAX.  The code below assumes
+              that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
+              which is technically not guaranteed by C, but is usually true
+              (because it would be true if x were unsigned with its
+              high-order bit on). It uses the fact that
+              high_bound-low_bound is always representable in
+              ULONGEST and that if high_bound-low_bound+1 overflows,
+              it overflows to 0.  We must change these tests if we 
+              decide to increase the representation of TYPE_LENGTH
+              from unsigned int to ULONGEST. */
+           ULONGEST ulow = low_bound, uhigh = high_bound;
+           ULONGEST tlen = TYPE_LENGTH (target_type);
+
+           len = tlen * (uhigh - ulow + 1);
+           if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh 
+               || len > UINT_MAX)
+             len = 0;
+         }
+         TYPE_LENGTH (type) = len;
          TYPE_TARGET_STUB (type) = 0;
        }
       else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
@@ -2737,6 +2752,14 @@ recursive_dump_type (struct type *type, int spaces)
          recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
        }
     }
+  if (TYPE_CODE (type) == TYPE_CODE_RANGE)
+    {
+      printfi_filtered (spaces, "low %s%s  high %s%s\n",
+                       plongest (TYPE_LOW_BOUND (type)), 
+                       TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
+                       plongest (TYPE_HIGH_BOUND (type)),
+                       TYPE_HIGH_BOUND_UNDEFINED (type) ? " (undefined)" : "");
+    }
   printfi_filtered (spaces, "vptr_basetype ");
   gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
   puts_filtered ("\n");
@@ -2925,6 +2948,13 @@ copy_type_recursive (struct objfile *objfile,
        }
     }
 
+  /* For range types, copy the bounds information. */
+  if (TYPE_CODE (type) == TYPE_CODE_RANGE)
+    {
+      TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
+      *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
+    }
+
   /* Copy pointers to other types.  */
   if (TYPE_TARGET_TYPE (type))
     TYPE_TARGET_TYPE (new_type) = 
This page took 0.036877 seconds and 4 git commands to generate.