]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Incorrect constant folding in postcondition involving 'Old
authorJustin Squirek <squirek@adacore.com>
Thu, 9 Feb 2023 17:00:46 +0000 (17:00 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 22 May 2023 08:46:12 +0000 (10:46 +0200)
The following patch fixes an issue in the compiler whereby certain flavors of
access comparisons may be incorrectly constant-folded out of contract
expressions - notably in postcondition expressions featuring a reference to
'Old.

gcc/ada/

* checks.adb (Install_Null_Excluding_Check): Avoid non-null
optimizations when assertions are enabled.

gcc/ada/checks.adb

index 9f3c679ed7e190eda383e91c5bda5ec4d89aec97..0d472964ff5166777f3a59c3f5e7c4b5386511c1 100644 (file)
@@ -8437,7 +8437,18 @@ package body Checks is
               Right_Opnd => Make_Null (Loc)),
           Reason => CE_Access_Check_Failed));
 
-      Mark_Non_Null;
+      --  Mark the entity of N "non-null" except when assertions are enabled -
+      --  since expansion becomes much more complicated (especially when it
+      --  comes to contracts) due to the generation of wrappers and wholesale
+      --  moving of declarations and statements which may happen.
+
+      --  Additionally, it is assumed that extra checks will exist with
+      --  assertions enabled so some potentially redundant checks are
+      --  acceptable.
+
+      if not Assertions_Enabled then
+         Mark_Non_Null;
+      end if;
    end Install_Null_Excluding_Check;
 
    -----------------------------------------