]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix for validity checking and conditional evaluation of 'Old
authorPiotr Trojanek <trojanek@adacore.com>
Mon, 11 Mar 2024 22:02:50 +0000 (23:02 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 17 May 2024 08:21:04 +0000 (10:21 +0200)
Detection of expression that are "known on entry" (as defined in Ada
2022 RM 6.1.1(20/5)) was confused by validity checks when used from
within expansion of attribute 'Old.

gcc/ada/

* sem_util.adb (Is_Known_On_Entry): Handle constants introduced
by validity checks.

gcc/ada/sem_util.adb

index be777d26e46563e1c591a99b2918d2cd95745326..d512d462b443981bc14b9df64376d9dc8ef6c2ea 100644 (file)
@@ -30791,6 +30791,14 @@ package body Sem_Util is
                               return False;
                            end if;
 
+                           --  Handle constants introduced by side-effect
+                           --  removal, e.g. by validity checks.
+
+                           if not Comes_From_Source (Obj) then
+                              return
+                                Is_Known_On_Entry (Expression (Parent (Obj)));
+                           end if;
+
                            --  return False if not "all views are constant".
                            if Is_Immutably_Limited_Type (Obj_Typ)
                              or Needs_Finalization (Obj_Typ)