]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix detection of suspicious loop patterns
authorRonan Desplanques <desplanques@adacore.com>
Thu, 4 Jul 2024 13:43:04 +0000 (15:43 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 2 Aug 2024 07:08:03 +0000 (09:08 +0200)
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.

gcc/ada/sem_ch5.adb

index e4506036cc2b8899dff089efc6969a4c6c2342d7..4db3a1a26ee30d7e7b70cd3dca276b2b0529a158 100644 (file)
@@ -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 :=