]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Redundant validity checks
authorSteve Baird <baird@adacore.com>
Tue, 27 Feb 2024 20:11:47 +0000 (12:11 -0800)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 16 May 2024 08:49:34 +0000 (10:49 +0200)
In some cases with validity checking enabled via the -gnatVa option,
the compiler generates validity checks that can (obviously) never fail.
These include validity checks for (some) static expressions, and consecutive
identical checks generated for a single read of an object.

gcc/ada/

* checks.adb (Expr_Known_Valid): Return True for a static expression.
* exp_util.adb (Adjust_Condition): No validity check needed for a
condition if it is an expression for which a validity check has
already been generated.

gcc/ada/checks.adb
gcc/ada/exp_util.adb

index 6af392eeda8a955bf337f74ea0b00729417ccc48..bada3dffcbfc0bb46576820666055b93ffd2a8e2 100644 (file)
@@ -6839,6 +6839,9 @@ package body Checks is
       then
          return True;
 
+      elsif Is_Static_Expression (Expr) then
+         return True;
+
       --  If the expression is the value of an object that is known to be
       --  valid, then clearly the expression value itself is valid.
 
index 057cf3ebc48008aee77e683c58649c7edc9cfeb9..b71f7739481dc68b4f9722d99175d557c6460f78 100644 (file)
@@ -416,6 +416,11 @@ package body Exp_Util is
          if Validity_Checks_On
            and then
              (Validity_Check_Tests or else Is_Hardbool_Type (T))
+
+           --  no check needed here if validity has already been checked
+           and then not
+             (Validity_Check_Operands and then
+               (Nkind (N) in N_Op or else Nkind (Parent (N)) in N_Op))
          then
             Ensure_Valid (N);
          end if;