From: Piotr Trojanek <troja...@adacore.com>

Move detection of always valid expressions from routine
Ensure_Valid (which inserts validity checks) to Expr_Known_Valid
(which decides their validity). In particular, this patch removes
duplicated detection of boolean operators, which were recognized
in both these routines.

Code cleanup; behavior is unaffected.

gcc/ada/

        * checks.adb (Ensure_Valid): Remove detection of boolean and
        short-circuit operators.
        (Expr_Known_Valid): Detect short-circuit operators; detection of
        boolean operators was already done in this routine.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/checks.adb | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index d13e7bb3269..3650c070b7a 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -6816,17 +6816,6 @@ package body Checks is
          end if;
       end if;
 
-      --  If this is a boolean expression, only its elementary operands need
-      --  checking: if they are valid, a boolean or short-circuit operation
-      --  with them will be valid as well.
-
-      if Base_Type (Typ) = Standard_Boolean
-        and then
-         (Nkind (Expr) in N_Op or else Nkind (Expr) in N_Short_Circuit)
-      then
-         return;
-      end if;
-
       --  If we fall through, a validity check is required
 
       Insert_Valid_Check (Expr, Related_Id, Is_Low_Bound, Is_High_Bound);
@@ -6947,9 +6936,10 @@ package body Checks is
          return True;
 
       --  The result of a membership test is always valid, since it is true or
-      --  false, there are no other possibilities.
+      --  false, there are no other possibilities; same for short-circuit
+      --  operators.
 
-      elsif Nkind (Expr) in N_Membership_Test then
+      elsif Nkind (Expr) in N_Membership_Test | N_Short_Circuit then
          return True;
 
       --  For all other cases, we do not know the expression is valid
-- 
2.45.2

Reply via email to