[gfortran] Fix PR18993: Match EOS in NULLIFY matcher

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Wed Dec 15 18:02:00 GMT 2004


This is a simple omission which would make us yield a weird error in the
following fixed form source code:
      subroutine ordern( )
      real, pointer :: aux(:,:)
C Nullify pointers
        nullify(aux)
C Set default sizes for order N arrays
      end subroutine ordern

It would also make us accept the following code without giving an error,
accepting both the NULLIFY and the assignment statement as if there were a
semicolon in between:
      subroutine ordern( )
      real, pointer :: aux(:,:)
C Nullify pointers
        nullify(aux) i=i+1
C Set default sizes for order N arrays
      end subroutine ordern

The appended patch fixes this by adapting gfc_match_nullify to the example set
by the other matchers, i.e. make it check for the end of statement. Since I
orignally thought that this problem was more widespread I went through the
other matchers in match.c and made sure that all of them do indeed eat up the
end of statement following the matched code. While I was at it I did a minor
cleanup in gfc_match_if: '%t' eats whitespace, so there's no need to allow for
optional whitespace there.

With this patch, the first example is correctly compiled, the second example
gives an internal error, while freeing memory. I think I know why this
happens, but I wanted to get this simple fix out of the way first, before
changing the order in which things are allocated.

Bubblestrapped and regtested, I'll add the first testcase to the testsuite
(dg-do compile), ok?

- Tobi

2004-12-15  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/18993
	* match.c (gfc_match_if): Don't explicitly skip optional whitespace.
	(gfc_match_nullify): Make sure that ')' is in front of the end of
	statement.

Index: match.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/match.c,v
retrieving revision 1.26
diff -u -p -r1.26 match.c
--- match.c     12 Dec 2004 21:11:57 -0000      1.26
+++ match.c     15 Dec 2004 17:50:42 -0000
@@ -974,7 +974,7 @@ gfc_match_if (gfc_statement * if_type)
       return MATCH_YES;
     }

-  if (gfc_match (" then %t") == MATCH_YES)
+  if (gfc_match (" then%t") == MATCH_YES)
     {
       new_st.op = EXEC_IF;
       new_st.expr = expr;
@@ -1822,7 +1822,7 @@ gfc_match_nullify (void)
       tail->expr = p;
       tail->expr2 = e;

-      if (gfc_match_char (')') == MATCH_YES)
+      if (gfc_match (" )%t") == MATCH_YES)
        break;
       if (gfc_match_char (',') != MATCH_YES)
        goto syntax;



More information about the Gcc-patches mailing list