https://gcc.gnu.org/g:99337cb2385c38182e48a491442da449c028f51c
commit r15-2662-g99337cb2385c38182e48a491442da449c028f51c Author: Ronan Desplanques <desplanq...@adacore.com> Date: Thu Jul 4 15:43:04 2024 +0200 ada: Fix detection of suspicious loop patterns This patch fixes an assertion failure in some cases in the code to warn about possible misuse of range attributes in loop. The root of the problem is that this code failed to consider the case where the outer loop is a while loop. Also fix a typo in a nearby comment. gcc/ada/ * sem_ch5.adb (Analyze_Loop_Statement): Fix loop pattern detection code. Fix typo. Diff: --- gcc/ada/sem_ch5.adb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb index e4506036cc2b..4db3a1a26ee3 100644 --- a/gcc/ada/sem_ch5.adb +++ b/gcc/ada/sem_ch5.adb @@ -3967,7 +3967,7 @@ package body Sem_Ch5 is Push_Scope (Ent); Analyze_Iteration_Scheme (Iter); - -- Check for following case which merits a warning if the type E of is + -- Check for following case which merits a warning if the type of E is -- a multi-dimensional array (and no explicit subscript ranges present). -- for J in E'Range @@ -3992,6 +3992,10 @@ package body Sem_Ch5 is and then Number_Dimensions (Typ) > 1 and then Nkind (Parent (N)) = N_Loop_Statement and then Present (Iteration_Scheme (Parent (N))) + -- The next conjunct tests that the enclosing loop is + -- a for loop and not a while loop. + and then Present (Loop_Parameter_Specification + (Iteration_Scheme (Parent (N)))) then declare OIter : constant Node_Id :=