https://gcc.gnu.org/g:48a5910dde566180a0a0878651a78ccece89be45
commit r15-9775-g48a5910dde566180a0a0878651a78ccece89be45 Author: Steve Baird <ba...@adacore.com> Date: Thu Jan 30 13:28:50 2025 -0800 ada: Exception-raising loop incorrectly eliminated 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. Diff: --- gcc/ada/sem_util.adb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index b833b3552978..7757e04b2a1f 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -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))