diff mbox series

[COMMITTED,25/35] ada: Fix for validity checking and conditional evaluation of 'Old

Message ID 20240517083207.130391-25-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/35] ada: Add support for 'Object_Size to pragma Compile_Time_{Warning, Error} | expand

Commit Message

Marc Poulhiès May 17, 2024, 8:31 a.m. UTC
From: Piotr Trojanek <trojanek@adacore.com>

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.

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

---
 gcc/ada/sem_util.adb | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index be777d26e46..d512d462b44 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -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)