]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Exception-raising loop incorrectly eliminated
authorSteve Baird <baird@adacore.com>
Thu, 30 Jan 2025 21:28:50 +0000 (13:28 -0800)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 5 Jun 2025 08:18:37 +0000 (10:18 +0200)
If the body of a loop includes a raise statement then the loop should not be
considered to be free of side-effects and therefore eligible for elimination
by the compiler.

gcc/ada/ChangeLog:

* sem_util.adb
(Side_Effect_Free_Statements): Return False if the statement list
includes an explicit (i.e. Comes_From_Source) raise statement.

gcc/ada/sem_util.adb

index ce54deaab850a5525208cfec1f1588d5f05d6600..97dc4c0af8b9ab6df1fff9e1d35a2320123eeb75 100644 (file)
@@ -12425,9 +12425,14 @@ package body Sem_Util is
 
       while Present (Node) loop
          case Nkind (Node) is
-            when N_Null_Statement | N_Call_Marker | N_Raise_xxx_Error =>
+            when N_Null_Statement | N_Call_Marker =>
                null;
 
+            when N_Raise_xxx_Error =>
+               if Comes_From_Source (Node) then
+                  return False;
+               end if;
+
             when N_Object_Declaration =>
                if Present (Expression (Node))
                  and then not Side_Effect_Free (Expression (Node))