Mikael Morin wrote:
On 17/07/2012 20:52, Tobias Burnus wrote:
Build and regtested on x86-64-gnu-linux.
OK for the trunk?
Sorry, I hit "Sent" a tad too early. The patch failed because it was
also parsing the first few lines of a cpped file, which are, e.g.,
# 1 "gfortran.dg/g77/cpp4.F"
# 1 "<command-line>"
# 1 "gfortran.dg/g77/cpp4.F"
That lead to the warning:
----------<cut>-----------
gfortran.dg/g77/cpp4.F:6.16:
Included at <command-line>:1:
Included at gfortran.dg/g77/cpp4.F:1:
Included at gfortran.dg/g77/cpp4.F:1:
data i /4hbla'/
1
Warning: Extension: Hollerith constant at (1)
----------<cut>-----------
At the same time, it had also to work with gfortran.dg/g77/20010321-1.f,
which is not preprocessed but contains the following lines:
# 1 "20010321-1.f"
# 1 "include/implicit.h" 1 3
# 3 "20010321-1.f" 2 3
The current patch is slightly uglier than the original version, but it
seems to work.
PS: I didn't include a test case; one could create one using
-fdump-tree-original-lineno, if you think that it makes sense.
OK; I prefer with a testcase.
I have now also included a test case.
Thanks for the review – and sorry for asking for another review.
Tobias
PS: I wouldn't mind if you could review the assumed-rank patch. I know
that it is rather big, but it kind of blocks me from writing other
patches. I think the first external user will be Open MPI,* as MPIv3
will support assumed-rank arrays.
* Draft MPIv3 http://www.unixer.de/sec/mpi-report-r1300.pdf ; draft Open
MPI implementation https://bitbucket.org/jsquyres/mpi3-fortran/
2012-07-17 Tobias Burnus <bur...@net-b.de>
PR fortran/53993
* scanner.c (preprocessor_line): Fix parsing of a "#line"
which has no flags, add new parameter.
(load_file): Update the call.
2012-07-17 Tobias Burnus <bur...@net-b.de>
PR fortran/53993
* gfortran.dg/debug_3.F90: New.
diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c
index 4fad58b..56eaa48 100644
--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -1646,7 +1646,7 @@ get_file (const char *name, enum lc_reason reason ATTRIBUTE_UNUSED)
initial octothorp has already been seen. */
static void
-preprocessor_line (gfc_char_t *c)
+preprocessor_line (gfc_char_t *c, bool ignore_line)
{
bool flag[5];
int i, line;
@@ -1654,6 +1654,9 @@ preprocessor_line (gfc_char_t *c)
gfc_file *f;
int escaped, unescape;
char *filename;
+ enum {FLAG_NEW_FILE = 1, FLAG_PREV_FILE, FLAG_SYSHEADER, FLAG_EXTERN_C};
+
+ /* The expected syntax is "# linenumber filename flags". */
c++;
while (*c == ' ' || *c == '\t')
@@ -1739,20 +1742,25 @@ preprocessor_line (gfc_char_t *c)
flag[i] = true;
}
+ /* No flag implies that one might have a new file. However, we have to skip
+ over the first three lines of a cpp'ed file. */
+ if (!flag[FLAG_NEW_FILE] && !flag[FLAG_PREV_FILE] && !ignore_line)
+ flag[FLAG_NEW_FILE] = true;
+
/* Convert the filename in wide characters into a filename in narrow
characters. */
filename = gfc_widechar_to_char (wide_filename, -1);
/* Interpret flags. */
- if (flag[1]) /* Starting new file. */
+ if (flag[FLAG_NEW_FILE]) /* Starting new file. */
{
f = get_file (filename, LC_RENAME);
add_file_change (f->filename, f->inclusion_line);
current_file = f;
}
- if (flag[2]) /* Ending current file. */
+ if (flag[FLAG_PREV_FILE]) /* Ending current file. */
{
if (!current_file->up
|| filename_cmp (current_file->up->filename, filename) != 0)
@@ -1959,12 +1967,12 @@ load_file (const char *realfilename, const char *displayedname, bool initial)
if (initial && gfc_src_preprocessor_lines[0])
{
- preprocessor_line (gfc_src_preprocessor_lines[0]);
+ preprocessor_line (gfc_src_preprocessor_lines[0], initial);
free (gfc_src_preprocessor_lines[0]);
gfc_src_preprocessor_lines[0] = NULL;
if (gfc_src_preprocessor_lines[1])
{
- preprocessor_line (gfc_src_preprocessor_lines[1]);
+ preprocessor_line (gfc_src_preprocessor_lines[1], initial);
free (gfc_src_preprocessor_lines[1]);
gfc_src_preprocessor_lines[1] = NULL;
}
@@ -2015,7 +2023,7 @@ load_file (const char *realfilename, const char *displayedname, bool initial)
;
else
{
- preprocessor_line (line);
+ preprocessor_line (line, first_line);
continue;
}
}
--- /dev/null 2012-07-17 07:28:04.995717470 +0200
+++ gcc/gcc/testsuite/gfortran.dg/debug_3.F90 2012-07-17 21:19:34.000000000 +0200
@@ -0,0 +1,25 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original-lineno" }
+!
+! PR fortran/53993
+!
+! Contributed by Markus Geimer
+!
+program dummy
+ write(*,*) "Starting dummy"
+#line 444 "newFile.f90"
+ call foo
+ write(*,*) "Stopping dummy"
+#line 455 "newFile.f90"
+end program dummy
+#line 16 "debug_3.F90"
+
+subroutine foo
+ write(*,*) "Hello world!"
+end subroutine foo
+
+! { dg-final { scan-tree-dump "newFile.f90 : 444" "original" } }
+! { dg-final { scan-tree-dump "newFile.f90 : 445" "original" } }
+! { dg-final { scan-tree-dump "newFile.f90 : 455" "original" } }
+
+! { dg-final { scan-tree-dump "debug_3.F90 : 18" "original" } }