Don't inherit range-type signed-ness from underlying type
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index b57353dec3051b6c2cbdc93e88e0cff323c02804..0940fa597fbcd58640aeaa11de787a1a0fb2728a 100644 (file)
@@ -575,12 +575,12 @@ lookup_function_type_with_arguments (struct type *type,
   return fn;
 }
 
-/* Identify address space identifier by name --
-   return the integer flag defined in gdbtypes.h.  */
+/* Identify address space identifier by name -- return a
+   type_instance_flags.  */
 
 type_instance_flags
-address_space_name_to_int (struct gdbarch *gdbarch,
-                          const char *space_identifier)
+address_space_name_to_type_instance_flags (struct gdbarch *gdbarch,
+                                          const char *space_identifier)
 {
   type_instance_flags type_flags;
 
@@ -598,12 +598,12 @@ address_space_name_to_int (struct gdbarch *gdbarch,
     error (_("Unknown address space specifier: \"%s\""), space_identifier);
 }
 
-/* Identify address space identifier by integer flag as defined in 
-   gdbtypes.h -- return the string version of the adress space name.  */
+/* Identify address space identifier by type_instance_flags and return
+   the string version of the adress space name.  */
 
 const char *
-address_space_int_to_name (struct gdbarch *gdbarch,
-                          type_instance_flags space_flag)
+address_space_type_instance_flags_to_name (struct gdbarch *gdbarch,
+                                          type_instance_flags space_flag)
 {
   if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
     return "code";
@@ -630,7 +630,7 @@ make_qualified_type (struct type *type, type_instance_flags new_flags,
   ntype = type;
   do
     {
-      if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
+      if (ntype->instance_flags () == new_flags)
        return ntype;
       ntype = TYPE_CHAIN (ntype);
     }
@@ -753,7 +753,7 @@ struct type *
 make_restrict_type (struct type *type)
 {
   return make_qualified_type (type,
-                             (TYPE_INSTANCE_FLAGS (type)
+                             (type->instance_flags ()
                               | TYPE_INSTANCE_FLAG_RESTRICT),
                              NULL);
 }
@@ -764,7 +764,7 @@ struct type *
 make_unqualified_type (struct type *type)
 {
   return make_qualified_type (type,
-                             (TYPE_INSTANCE_FLAGS (type)
+                             (type->instance_flags ()
                               & ~(TYPE_INSTANCE_FLAG_CONST
                                   | TYPE_INSTANCE_FLAG_VOLATILE
                                   | TYPE_INSTANCE_FLAG_RESTRICT)),
@@ -777,7 +777,7 @@ struct type *
 make_atomic_type (struct type *type)
 {
   return make_qualified_type (type,
-                             (TYPE_INSTANCE_FLAGS (type)
+                             (type->instance_flags ()
                               | TYPE_INSTANCE_FLAG_ATOMIC),
                              NULL);
 }
@@ -825,7 +825,7 @@ replace_type (struct type *ntype, struct type *type)
 
   /* Assert that the two types have equivalent instance qualifiers.
      This should be true for at least all of our debug readers.  */
-  gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
+  gdb_assert (ntype->instance_flags () == type->instance_flags ());
 }
 
 /* Implement direct support for MEMBER_TYPE in GNU C++.
@@ -950,9 +950,15 @@ create_range_type (struct type *result_type, struct type *index_type,
 
   result_type->set_bounds (bounds);
 
+  /* Note that the signed-ness of a range type can't simply be copied
+     from the underlying type.  Consider a case where the underlying
+     type is 'int', but the range type can hold 0..65535, and where
+     the range is further specified to fit into 16 bits.  In this
+     case, if we copy the underlying type's sign, then reading some
+     range values will cause an unwanted sign extension.  So, we have
+     some heuristics here instead.  */
   if (low_bound->kind () == PROP_CONST && low_bound->const_val () >= 0)
     result_type->set_is_unsigned (true);
-
   /* Ada allows the declaration of range types whose upper bound is
      less than the lower bound, so checking the lower bound is not
      enough.  Make sure we do not mark a range type whose upper bound
@@ -2834,9 +2840,7 @@ check_typedef (struct type *type)
             move over any other types NEWTYPE refers to, which could
             be an unbounded amount of stuff.  */
          if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
-           type = make_qualified_type (newtype,
-                                       TYPE_INSTANCE_FLAGS (type),
-                                       type);
+           type = make_qualified_type (newtype, type->instance_flags (), type);
          else
            type = newtype;
        }
@@ -2862,9 +2866,8 @@ check_typedef (struct type *type)
              with the complete type only if they are in the same
              objfile.  */
          if (TYPE_OBJFILE (SYMBOL_TYPE (sym)) == TYPE_OBJFILE (type))
-            type = make_qualified_type (SYMBOL_TYPE (sym),
-                                       TYPE_INSTANCE_FLAGS (type),
-                                       type);
+           type = make_qualified_type (SYMBOL_TYPE (sym),
+                                       type->instance_flags (), type);
          else
            type = SYMBOL_TYPE (sym);
         }
@@ -3197,6 +3200,10 @@ init_integer_type (struct objfile *objfile,
   if (unsigned_p)
     t->set_is_unsigned (true);
 
+  TYPE_SPECIFIC_FIELD (t) = TYPE_SPECIFIC_INT;
+  TYPE_MAIN_TYPE (t)->type_specific.int_stuff.bit_size = bit;
+  TYPE_MAIN_TYPE (t)->type_specific.int_stuff.bit_offset = 0;
+
   return t;
 }
 
@@ -3231,6 +3238,10 @@ init_boolean_type (struct objfile *objfile,
   if (unsigned_p)
     t->set_is_unsigned (true);
 
+  TYPE_SPECIFIC_FIELD (t) = TYPE_SPECIFIC_INT;
+  TYPE_MAIN_TYPE (t)->type_specific.int_stuff.bit_size = bit;
+  TYPE_MAIN_TYPE (t)->type_specific.int_stuff.bit_offset = 0;
+
   return t;
 }
 
@@ -3287,7 +3298,7 @@ init_complex_type (const char *name, struct type *target_type)
 
   if (TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type == nullptr)
     {
-      if (name == nullptr)
+      if (name == nullptr && target_type->name () != nullptr)
        {
          char *new_name
            = (char *) TYPE_ALLOC (target_type,
@@ -4001,7 +4012,7 @@ check_types_equal (struct type *type1, struct type *type2,
       || type1->has_varargs () != type2->has_varargs ()
       || type1->is_vector () != type2->is_vector ()
       || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2)
-      || TYPE_INSTANCE_FLAGS (type1) != TYPE_INSTANCE_FLAGS (type2)
+      || type1->instance_flags () != type2->instance_flags ()
       || type1->num_fields () != type2->num_fields ())
     return false;
 
@@ -5191,6 +5202,16 @@ recursive_dump_type (struct type *type, int spaces)
        gdb_print_host_address (TYPE_SELF_TYPE (type), gdb_stdout);
        puts_filtered ("\n");
        break;
+
+    case TYPE_SPECIFIC_INT:
+      if (type->bit_size_differs_p ())
+       {
+         unsigned bit_size = type->bit_size ();
+         unsigned bit_off = type->bit_offset ();
+         printfi_filtered (spaces, " bit size = %u, bit offset = %u\n",
+                           bit_size, bit_off);
+       }
+      break;
     }
 
   if (spaces == 0)
@@ -5230,13 +5251,13 @@ type_pair_eq (const void *item_lhs, const void *item_rhs)
    types without duplicates.  We use OBJFILE's obstack, because
    OBJFILE is about to be deleted.  */
 
-htab_t
+htab_up
 create_copied_types_hash (struct objfile *objfile)
 {
-  return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
-                              NULL, &objfile->objfile_obstack,
-                              hashtab_obstack_allocate,
-                              dummy_obstack_deallocate);
+  return htab_up (htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
+                                       NULL, &objfile->objfile_obstack,
+                                       hashtab_obstack_allocate,
+                                       dummy_obstack_deallocate));
 }
 
 /* Recursively copy (deep copy) a dynamic attribute list of a type.  */
@@ -5414,6 +5435,12 @@ copy_type_recursive (struct objfile *objfile,
                          copy_type_recursive (objfile, TYPE_SELF_TYPE (type),
                                               copied_types));
       break;
+    case TYPE_SPECIFIC_INT:
+      TYPE_SPECIFIC_FIELD (new_type) = TYPE_SPECIFIC_INT;
+      TYPE_MAIN_TYPE (new_type)->type_specific.int_stuff
+       = TYPE_MAIN_TYPE (type)->type_specific.int_stuff;
+      break;
+
     default:
       gdb_assert_not_reached ("bad type_specific_kind");
     }
This page took 0.028184 seconds and 4 git commands to generate.