aboutsummaryrefslogtreecommitdiff
path: root/gcc/varasm.cc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2023-05-19 09:00:11 +0200
committerEric Botcazou <ebotcazou@adacore.com>2023-05-19 09:02:17 +0200
commit24dcf65dabf48b4d33b7f2d4c68f369627b61bdc (patch)
treeaa4e72cfdb2332f23a458ac253431724e8003b6e /gcc/varasm.cc
parentc3db10967411be9c17f0ef01f13e82a947b7e12f (diff)
downloadgcc-24dcf65dabf48b4d33b7f2d4c68f369627b61bdc.zip
gcc-24dcf65dabf48b4d33b7f2d4c68f369627b61bdc.tar.gz
gcc-24dcf65dabf48b4d33b7f2d4c68f369627b61bdc.tar.bz2
Fix internal error on small array with negative lower bound
Ada supports arrays with negative indices, although the internal index type is sizetype like in other languages, which is unsigned. This means that negative values are represented by very large numbers, which works with a bit of care. This plugs a small loophole in output_constructor_bitfield. gcc/ * varasm.cc (output_constructor_bitfield): Call tree_to_uhwi instead of tree_to_shwi on array indices. Minor tweaks. gcc/testsuite/ * gnat.dg/specs/array6.ads: New test.
Diffstat (limited to 'gcc/varasm.cc')
-rw-r--r--gcc/varasm.cc17
1 files changed, 8 insertions, 9 deletions
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 2e1dee4..571bb2e 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -5564,19 +5564,18 @@ output_constructor_bitfield (oc_local_state *local, unsigned int bit_offset)
/* Relative index of this element if this is an array component. */
HOST_WIDE_INT relative_index
- = (!local->field
- ? (local->index
- ? (tree_to_shwi (local->index)
- - tree_to_shwi (local->min_index))
- : local->last_relative_index + 1)
- : 0);
+ = (local->field
+ ? 0
+ : (local->index
+ ? tree_to_uhwi (local->index) - tree_to_uhwi (local->min_index)
+ : local->last_relative_index + 1));
/* Bit position of this element from the start of the containing
constructor. */
HOST_WIDE_INT constructor_relative_ebitpos
- = (local->field
- ? int_bit_position (local->field)
- : ebitsize * relative_index);
+ = (local->field
+ ? int_bit_position (local->field)
+ : ebitsize * relative_index);
/* Bit position of this element from the start of a possibly ongoing
outer byte buffer. */