[COMMITTED,01/26] ada: Fix detection of suspicious loop patterns
Commit Message
From: Ronan Desplanques <desplanques@adacore.com>
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.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_ch5.adb | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
@@ -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 :=