From: Eric Botcazou Date: Wed, 7 Dec 2016 11:25:37 +0000 (+0000) Subject: decl.c (gnat_to_gnu_entity): Also call finish_character_type on Character subtypes. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2c1f5c0a344e2f127decf13eb851794401b54e29;p=gcc.git decl.c (gnat_to_gnu_entity): Also call finish_character_type on Character subtypes. * gcc-interface/decl.c (gnat_to_gnu_entity) : Also call finish_character_type on Character subtypes. * gcc-interface/utils.c (finish_character_type): Deal with subtypes. From-SVN: r243336 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 858f8cb5abb..3087a1b72cd 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2016-12-07 Eric Botcazou + + * gcc-interface/decl.c (gnat_to_gnu_entity) : + Also call finish_character_type on Character subtypes. + * gcc-interface/utils.c (finish_character_type): Deal with subtypes. + 2016-12-05 Mikael Pettersson PR ada/48835 diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index 9de85ef8e4b..2412a36d984 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -1859,8 +1859,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) TYPE_BIASED_REPRESENTATION_P (gnu_type) = Has_Biased_Representation (gnat_entity); - /* Set TYPE_STRING_FLAG for Character and Wide_Character subtypes. */ - TYPE_STRING_FLAG (gnu_type) = TYPE_STRING_FLAG (TREE_TYPE (gnu_type)); + /* Do the same processing for Character subtypes as for types. */ + if (TYPE_STRING_FLAG (TREE_TYPE (gnu_type))) + { + TYPE_NAME (gnu_type) = gnu_entity_name; + TYPE_STRING_FLAG (gnu_type) = 1; + TYPE_ARTIFICIAL (gnu_type) = artificial_p; + finish_character_type (gnu_type); + } /* Inherit our alias set from what we're a subtype of. Subtypes are not different types and a pointer can designate any instance diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index cde17fe3b36..c00d1fa78f4 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -1641,10 +1641,7 @@ record_builtin_type (const char *name, tree type, bool artificial_p) character subtypes with RM_Size = Esize = CHAR_TYPE_SIZE into signed types. The idea is to ensure that the bit pattern contained in the Esize'd objects is not changed, even though the numerical value will - be interpreted differently depending on the signedness. - - For character types, the bounds are implicit and, therefore, need to - be adjusted. Morever, the debug info needs the unsigned version. */ + be interpreted differently depending on the signedness. */ void finish_character_type (tree char_type) @@ -1658,11 +1655,32 @@ finish_character_type (tree char_type) ? unsigned_char_type_node : copy_type (gnat_unsigned_type_for (char_type))); + /* Create an unsigned version of the type and set it as debug type. */ TYPE_NAME (unsigned_char_type) = TYPE_NAME (char_type); TYPE_STRING_FLAG (unsigned_char_type) = TYPE_STRING_FLAG (char_type); TYPE_ARTIFICIAL (unsigned_char_type) = TYPE_ARTIFICIAL (char_type); - SET_TYPE_DEBUG_TYPE (char_type, unsigned_char_type); + + /* If this is a subtype, make the debug type a subtype of the debug type + of the base type and convert literal bounds to unsigned. */ + if (TREE_TYPE (char_type)) + { + tree base_unsigned_char_type = TYPE_DEBUG_TYPE (TREE_TYPE (char_type)); + tree min_value = TYPE_MIN_VALUE (char_type); + tree max_value = TYPE_MAX_VALUE (char_type); + + if (TREE_CODE (min_value) == INTEGER_CST) + min_value = fold_convert (base_unsigned_char_type, min_value); + if (TREE_CODE (max_value) == INTEGER_CST) + max_value = fold_convert (base_unsigned_char_type, max_value); + + TREE_TYPE (unsigned_char_type) = base_unsigned_char_type; + SET_TYPE_RM_MIN_VALUE (unsigned_char_type, min_value); + SET_TYPE_RM_MAX_VALUE (unsigned_char_type, max_value); + } + + /* Adjust the bounds of the original type to unsigned; that's especially + important for types since they are implicit in this case. */ SET_TYPE_RM_MIN_VALUE (char_type, TYPE_MIN_VALUE (unsigned_char_type)); SET_TYPE_RM_MAX_VALUE (char_type, TYPE_MAX_VALUE (unsigned_char_type)); }