aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gcc-interface/decl.cc
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2024-10-15 10:53:47 +0200
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-11-04 16:58:00 +0100
commit899b5be8b9720e381c7ea99ba27a4cbb165c003b (patch)
tree70236ce32dbaf3ef72d78298d388ce69c48d65d5 /gcc/ada/gcc-interface/decl.cc
parent023a5dd187b1b08979bc0654334e75e7b2c15eaa (diff)
downloadgcc-899b5be8b9720e381c7ea99ba27a4cbb165c003b.zip
gcc-899b5be8b9720e381c7ea99ba27a4cbb165c003b.tar.gz
gcc-899b5be8b9720e381c7ea99ba27a4cbb165c003b.tar.bz2
ada: Move special case for null string literal from frontend to backend
Previously the lower bound of string literals indexed by non-static integer types was artificially set to 1 in the frontend. This was to avoid an overflow in calculation of a null string size by the GCC backend, which was causing an excessively large binary object file. However, setting the lower bound to 1 was problematic for GNATprove, which could not easily retrieve the lower bound of string literals. This patch avoids the overflow in GCC by recognizing null string literal subtypes in Gigi. gcc/ada/ChangeLog: * gcc-interface/decl.cc (gnat_to_gnu_entity): Recognize null string literal subtypes and set their bounds to 1 .. 0.
Diffstat (limited to 'gcc/ada/gcc-interface/decl.cc')
-rw-r--r--gcc/ada/gcc-interface/decl.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index f5188dd..32e476c 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -3110,14 +3110,24 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
tree gnu_string_index_type
= get_base_type (TREE_TYPE (TYPE_INDEX_TYPE
(TYPE_DOMAIN (gnu_string_array_type))));
+
+ /* For a null string literal we set the bounds to 1 .. 0, to
+ avoid a possible overflow when calculating the upper bound
+ as LOWER_BOUND + LENGTH - 1. */
+ const bool is_null_string
+ = String_Literal_Length (gnat_entity) == Uint_0;
tree gnu_lower_bound
- = convert (gnu_string_index_type,
+ = is_null_string ?
+ build_int_cst (gnu_string_index_type, 1) :
+ convert (gnu_string_index_type,
gnat_to_gnu (String_Literal_Low_Bound (gnat_entity)));
tree gnu_length
= UI_To_gnu (String_Literal_Length (gnat_entity),
gnu_string_index_type);
tree gnu_upper_bound
- = build_binary_op (PLUS_EXPR, gnu_string_index_type,
+ = is_null_string ?
+ build_int_cst (gnu_string_index_type, 0) :
+ build_binary_op (PLUS_EXPR, gnu_string_index_type,
gnu_lower_bound,
int_const_binop (MINUS_EXPR, gnu_length,
convert (gnu_string_index_type,