This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Check infinite loop warning for exit when statement


This patch generalizes the Check_Infinite_Loop_Warning proceddure so
that it can be used for exit when tests as well as while tests, and
adds the appropriate call to Analyze_Exit_Statement.

The following test program compiled with -gnatwa shows the new
warning in action:

     1. procedure exitwarn (m : integer) is
     2.    g : integer := 3;
     3.    x : integer := m;
     4.
     5. begin
     6.    x := x + 1;
     7.    while x > 5 loop
                 |
        >>> warning: variable "x" is not modified in loop body
        >>> warning: possible infinite loop

     8.       g := g + 1;
     9.    end loop;
    10.
    11.    loop
    12.       exit when x <= 5;
                        |
        >>> warning: variable "x" is not modified in loop body
        >>> warning: possible infinite loop

    13.       g := g + 1;
    14.    end loop;
    15.
    16.    loop
    17.       exit when x <= 5;
    18.       x := x - 1;
    19.    end loop;
    20. end;

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-06-14  Robert Dewar  <dewar@adacore.com>

	* debug.adb: Entry for gnatw.d no longer specific for while loops
	* einfo.adb (First_Exit_Statement): New attribute for E_Loop
	* einfo.ads (First_Exit_Statement): New attribute for E_Loop
	* sem_ch5.adb (Analyze_Loop_Statement): Check_Infinite_Loop_Warning has
	new calling sequence to include test for EXIT WHEN.
	(Analyze_Exit_Statement): Chain EXIT statement into exit statement chain
	* sem_warn.ads, sem_warn.adb (Check_Infinite_Loop_Warning): Now handles
	EXIT WHEN case.
	* sinfo.adb (Next_Exit_Statement): New attribute of N_Exit_Statement
	node.
	* sinfo.ads (N_Pragma): Correct comment on Sloc field (points to
	PRAGMA, not to pragma identifier).
	(Next_Exit_Statement): New attribute of N_Exit_Statement node

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]