From e08a896b96792d73293db82d0dc3541c17e545ad Mon Sep 17 00:00:00 2001 From: Bob Duff Date: Wed, 3 Jul 2019 08:15:28 +0000 Subject: [Ada] Improve warnings about infinite loops The compiler now has fewer false alarms when warning about infinite loops. For example, a loop of the form "for X of A ...", where A is an array, cannot be infinite. The compiler no longer warns in this case. 2019-07-03 Bob Duff gcc/ada/ * sem_warn.adb (Check_Infinite_Loop_Warning): Avoid the warning if an Iterator_Specification is present. gcc/testsuite/ * gnat.dg/warn20.adb, gnat.dg/warn20_pkg.adb, gnat.dg/warn20_pkg.ads: New testcase. From-SVN: r272978 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_warn.adb | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'gcc/ada') diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index dd14590..02f35d5 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,10 @@ 2019-07-03 Bob Duff + * sem_warn.adb (Check_Infinite_Loop_Warning): Avoid the warning + if an Iterator_Specification is present. + +2019-07-03 Bob Duff + * doc/gnat_ugn/gnat_utility_programs.rst: Document default new-line behavior. diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb index dda94d2..7e13aa5 100644 --- a/gcc/ada/sem_warn.adb +++ b/gcc/ada/sem_warn.adb @@ -632,9 +632,16 @@ package body Sem_Warn is Expression := Condition (Iter); - -- For iteration, do not process, since loop will always terminate - - elsif Present (Loop_Parameter_Specification (Iter)) then + -- For Loop_Parameter_Specification, do not process, since loop + -- will always terminate. For Iterator_Specification, also do not + -- process. Either it will always terminate (e.g. "for X of + -- Some_Array ..."), or we can't tell if it's going to terminate + -- without looking at the iterator, so any warning here would be + -- noise. + + elsif Present (Loop_Parameter_Specification (Iter)) + or else Present (Iterator_Specification (Iter)) + then return; end if; end if; -- cgit v1.1