]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Tune code related to potentially unevaluated expressions
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 3 Apr 2024 11:25:04 +0000 (13:25 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 10 Jun 2024 09:04:00 +0000 (11:04 +0200)
Code cleanup; semantics is unaffected.

gcc/ada/

* sem_util.adb
(Immediate_Context_Implies_Is_Potentially_Unevaluated): Use
collective subtypes in membership tests.
(Is_Known_On_Entry): Require all alternatives in a case statement
to return; this change could prevent a recently fixed glitch,
where one of the alternatives relied on the return statement
afterwards (also, the new code is shorter).
* sem_util.ads (Is_Potentially_Unevaluated): Clarify that this
routine applies to Ada 2012.

gcc/ada/sem_util.adb
gcc/ada/sem_util.ads

index 241be3d2957168e127854da1f4a3a552ce2d0f52..5bea088c44e23499e5b18bb1351f914ff7ed9597 100644 (file)
@@ -19485,10 +19485,10 @@ package body Sem_Util is
          elsif Nkind (Par) = N_Case_Expression then
             return Expr /= Expression (Par);
 
-         elsif Nkind (Par) in N_And_Then | N_Or_Else then
+         elsif Nkind (Par) in N_Short_Circuit then
             return Expr = Right_Opnd (Par);
 
-         elsif Nkind (Par) in N_In | N_Not_In then
+         elsif Nkind (Par) in N_Membership_Test then
 
             --  If the membership includes several alternatives, only the first
             --  is definitely evaluated.
@@ -30880,10 +30880,8 @@ package body Sem_Util is
                   return True;
 
                when others =>
-                  null;
+                  return False;
             end case;
-
-            return False;
          end Is_Known_On_Entry;
 
       end Conditional_Evaluation;
index 4fef89663805df4575d4e1c0c62ed5fd42c6a480..f282d1fad99e6022b37725757cf3e901585eec66 100644 (file)
@@ -2219,7 +2219,7 @@ package Sem_Util is
    --  type be partially initialized.
 
    function Is_Potentially_Unevaluated (N : Node_Id) return Boolean;
-   --  Predicate to implement definition given in RM 6.1.1 (20/3)
+   --  Predicate to implement definition given in RM 2012 6.1.1 (20/3)
 
    function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean;
    --  Determines if type T is a potentially persistent type. A potentially