Don't inherit range-type signed-ness from underlying type
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index 43c05d344d0b5b8265c5a065d277ab6c0951f047..0940fa597fbcd58640aeaa11de787a1a0fb2728a 100644 (file)
@@ -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
@@ -3292,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,
This page took 0.024365 seconds and 4 git commands to generate.