PR14066 Allow infinite loops with label-do-stmt

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Sat May 8 16:28:00 GMT 2004


This is a followup to the first patch I ever submitted to g95 4 years 
ago. Unfortunately I missed the necessity of allowing infinite loops 
with a label, e.g.
	do 10
  10	end do

This patch fixes this. Patch & compile testcase below. Bootstrapped and 
regtested on i686-pc-linux-gnu. This also passed Steve Kargl's testsuite 
without introducing new failures.

- Tobi

2004-05-08  Tobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/14066
	* match.c (gfc_match_do): Allow infinite loops with
	label-do-stmt.

! test various forms of the DO statement
! inspired by PR14066
LOGICAL L
DO i=1,10
END DO
DO 10 i=1,20
    DO 20 j=1,10,2
20 CONTINUE
10 END DO
L = .TRUE.
DO WHILE(L)
    L = .FALSE.
END DO
DO 50 WHILE(.NOT.L)
    L = .TRUE.
50 CONTINUE
DO
    DO 30
       DO 40
40    CONTINUE
30 END DO
END DO
outer: DO i=1,20
    inner: DO j=i,30
       IF (j.EQ.2*i) CYCLE outer
    END DO inner
END DO outer
END


Index: match.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/Attic/match.c,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 match.c
--- match.c	11 Jan 2004 15:21:50 -0000	1.1.2.8
+++ match.c	8 May 2004 11:47:51 -0000
@@ -1202,6 +1210,10 @@ gfc_match_do (void)
    if (gfc_match (" do") != MATCH_YES)
      return MATCH_NO;

+  m = gfc_match_st_label (&label, 0);
+  if (m == MATCH_ERROR)
+    goto cleanup;
+
  /* Match an infinite DO, make it like a DO WHILE(.TRUE.) */

    if (gfc_match_eos () == MATCH_YES)
@@ -1211,10 +1223,6 @@ gfc_match_do (void)
        goto done;
      }

-  m = gfc_match_st_label (&label, 0);
-  if (m == MATCH_ERROR)
-    goto cleanup;
-
    gfc_match_char (',');

    if (gfc_match ("% ") != MATCH_YES)



More information about the Gcc-patches mailing list