https://gcc.gnu.org/g:c0c2a6152c78b54f3cc6737b667bf1aa53929713

commit c0c2a6152c78b54f3cc6737b667bf1aa53929713
Author: Alexandre Oliva <ol...@adacore.com>
Date:   Thu Jun 27 09:11:01 2024 -0300

    make_type_from_size: fix compare for type reuse
    
    When make_type_from_size is called with a biased type, for an entity
    that isn't explicitly biased, we may refrain from reusing the given
    type because it doesn't seem to match, and then proceed to create an
    exact copy of that type.
    
    Compute earlier the biased status of the expected type, early enough
    for the suitability check of the given type.  Modify for_biased
    instead of biased_p, so that biased_p remains with the given type's
    status for the comparison.
    
    
    for  gcc/ada/ChangeLog
    
            * gcc-interface/utils.cc (make_type_from_size): Fix type reuse
            by combining biased_p and for_biased earlier.  Hold the
            combination in for_biased, adjusting later uses.

Diff:
---
 gcc/ada/gcc-interface/utils.cc | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc
index 0eb9af8d4a2..d8d42f57b89 100644
--- a/gcc/ada/gcc-interface/utils.cc
+++ b/gcc/ada/gcc-interface/utils.cc
@@ -1383,6 +1383,11 @@ make_type_from_size (tree type, tree size_tree, bool 
for_biased)
       biased_p = (TREE_CODE (type) == INTEGER_TYPE
                  && TYPE_BIASED_REPRESENTATION_P (type));
 
+      /* FOR_BIASED initially refers to the entity's representation,
+        not to its type's.  The type we're to return must take both
+        into account.  */
+      for_biased |= biased_p;
+
       /* Integer types with precision 0 are forbidden.  */
       if (size == 0)
        size = 1;
@@ -1394,12 +1399,10 @@ make_type_from_size (tree type, tree size_tree, bool 
for_biased)
          || size > (Enable_128bit_Types ? 128 : LONG_LONG_TYPE_SIZE))
        break;
 
-      biased_p |= for_biased;
-
       /* The type should be an unsigned type if the original type is unsigned
         or if the lower bound is constant and non-negative or if the type is
         biased, see E_Signed_Integer_Subtype case of gnat_to_gnu_entity.  */
-      if (type_unsigned_for_rm (type) || biased_p)
+      if (type_unsigned_for_rm (type) || for_biased)
        new_type = make_unsigned_type (size);
       else
        new_type = make_signed_type (size);
@@ -1409,7 +1412,7 @@ make_type_from_size (tree type, tree size_tree, bool 
for_biased)
       /* Copy the name to show that it's essentially the same type and
         not a subrange type.  */
       TYPE_NAME (new_type) = TYPE_NAME (type);
-      TYPE_BIASED_REPRESENTATION_P (new_type) = biased_p;
+      TYPE_BIASED_REPRESENTATION_P (new_type) = for_biased;
       SET_TYPE_RM_SIZE (new_type, bitsize_int (size));
       return new_type;

Reply via email to