]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Another small adjustment to special resolution of membership test
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 7 Dec 2022 16:54:37 +0000 (17:54 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 3 Jan 2023 09:29:53 +0000 (10:29 +0100)
This goes back to the original implementation but keeps the special size
test with universal_integer to cope with its limited range.

gcc/ada/

* sem_res.adb (Resolve_Membership_Op): Adjust again latest change.

gcc/ada/sem_res.adb

index b54ed93a7f76873c012db3c3738953b8d11b9de2..348d272a399d9a8499289ff5a3defacd184b81cd 100644 (file)
@@ -10105,11 +10105,11 @@ package body Sem_Res is
       then
          T := Etype (R);
 
-      --  If the type of the left operand is universal_integer and that of the
-      --  right operand is smaller, then we do not resolve the operands to the
-      --  tested type but to universal_integer instead. If not conforming to
-      --  the letter, it's conforming to the spirit of the specification of
-      --  membership tests, which are typically used to guard an operation and
+      --  If the left operand is of a universal numeric type and the right
+      --  operand is not, we do not resolve the operands to the tested type
+      --  but to the universal type instead. If not conforming to the letter,
+      --  it's conforming to the spirit of the specification of membership
+      --  tests, which are typically used to guard a specific operation and
       --  ought not to fail a check in doing so. Without this, in the case of
 
       --    type Small_Length is range 1 .. 16;
@@ -10127,9 +10127,14 @@ package body Sem_Res is
       --  for example the large values of Long_Long_Long_Unsigned.
 
       elsif not Is_Overloaded (L)
-        and then Etype (L) = Universal_Integer
+        and then Is_Universal_Numeric_Type (Etype (L))
         and then (Is_Overloaded (R)
-                   or else RM_Size (Etype (R)) < RM_Size (Universal_Integer))
+                   or else
+                     (not Is_Universal_Numeric_Type (Etype (R))
+                       and then
+                         (not Is_Integer_Type (Etype (R))
+                           or else
+                          RM_Size (Etype (R)) < RM_Size (Universal_Integer))))
       then
          T := Etype (L);