mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-25 21:41:47 +08:00
Don't inherit range-type signed-ness from underlying type
A recent commit changed gdb to inherit the signed-ness of a range type from its underlying type: commit cfabbd351a174406fd5aa063303f5c8bf9266bbc Author: Tom Tromey <tom@tromey.com> Date: Sat Oct 17 11:41:59 2020 -0600 Make range types inherit signed-ness from base type This passed testing -- but unfortunately, additional testing at AdaCore showed that this change was incorrect. GNAT, at least, can emit an unsigned range type whose underlying type is signed. This patch reverts the code change from the above. I chose not to reintroduce the FIXME comments, because now we know that they are incorrect. Instead, this patch also adds a comment to create_range_type. A new test case is included as well. 2020-10-26 Tom Tromey <tromey@adacore.com> * gdbtypes.c (create_range_type): Revert previous patch. Add comment. gdb/testsuite/ChangeLog 2020-10-26 Tom Tromey <tromey@adacore.com> * gdb.ada/unsigned_range/foo.adb: New file. * gdb.ada/unsigned_range/pack.adb: New file. * gdb.ada/unsigned_range/pack.ads: New file. * gdb.ada/unsigned_range.exp: New file.
This commit is contained in:
@ -950,7 +950,22 @@ create_range_type (struct type *result_type, struct type *index_type,
|
||||
|
||||
result_type->set_bounds (bounds);
|
||||
|
||||
result_type->set_is_unsigned (index_type->is_unsigned ());
|
||||
/* 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
|
||||
is negative as unsigned. */
|
||||
if (high_bound->kind () == PROP_CONST && high_bound->const_val () < 0)
|
||||
result_type->set_is_unsigned (false);
|
||||
|
||||
result_type->set_endianity_is_not_default
|
||||
(index_type->endianity_is_not_default ());
|
||||
|
||||
|
Reference in New Issue
Block a user