public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/53993] New: gfortran ignores file part of #line directives
@ 2012-07-17 10:54 mg1102 at web dot de
2012-07-17 11:55 ` [Bug fortran/53993] gfortran ignores file part of #line directives for debugging burnus at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: mg1102 at web dot de @ 2012-07-17 10:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53993
Bug #: 53993
Summary: gfortran ignores file part of #line directives
Classification: Unclassified
Product: gcc
Version: 4.7.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: mg1102@web.de
Created attachment 27810
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27810
Example files to reproduce bug
#line directives inserted by source-code preprocessors are only partially
handled by gfortran. The line number part is OK, the file name part is ignored
and the input file name is used instead. This can mess up the debug information
of preprocessed Fortran files.
Example:
- The file 'dummy.f90' in the attached tar archive provides a simple Fortran
code, calling a subroutine from the main program which prints "Hello world!".
Compilation with gfortran 4.7.1 yields the following result:
% gfortran -g -c dummy.f90
% nm -l dummy.o
000000000000006d t MAIN__ /tmp/bug/dummy.f90:1
U _gfortran_set_args /tmp/bug/dummy.f90:3
U _gfortran_set_options /tmp/bug/dummy.f90:3
U _gfortran_st_write /tmp/bug/dummy.f90:6
U _gfortran_st_write_done /tmp/bug/dummy.f90:6
U _gfortran_transfer_character_write /tmp/bug/dummy.f90:6
0000000000000000 T foo_ /tmp/bug/dummy.f90:5
0000000000000078 T main /tmp/bug/dummy.f90:3
0000000000000020 r options.1.1854
- Suppose a source-code preprocessor inserts write statements to mark the
begin and end of the main program as well as #line directives to account
for modified line numbers and file name (prospective output provided as
'dummy.mod.F90').
% gfortran -g -c dummy.mod.F90
% nm -l dummy.mod.o
000000000000006d t MAIN__ /tmp/bug/dummy.mod.F90:1
U _gfortran_set_args /tmp/bug/dummy.mod.F90:3
U _gfortran_set_options /tmp/bug/dummy.mod.F90:3
U _gfortran_st_write /tmp/bug/dummy.mod.F90:6
U _gfortran_st_write_done /tmp/bug/dummy.mod.F90:6
U _gfortran_transfer_character_write
/tmp/bug/dummy.mod.F90:6
0000000000000000 T foo_ /tmp/bug/dummy.mod.F90:5
000000000000013f T main /tmp/bug/dummy.mod.F90:3
0000000000000040 r options.3.1856
- As can be seen, the line number information provided by the #line directives
is handled correctly, however, the file name refers to the actual input file
instead of the file specified by the directive.
This bug seems to only affect Fortran, similar examples in C/C++ work fine.
This behavior has been verified with GCC 4.5.3, 4.6.2 and 4.7.1.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/53993] gfortran ignores file part of #line directives for debugging
2012-07-17 10:54 [Bug fortran/53993] New: gfortran ignores file part of #line directives mg1102 at web dot de
@ 2012-07-17 11:55 ` burnus at gcc dot gnu.org
2012-07-17 12:38 ` burnus at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-07-17 11:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53993
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Keywords| |wrong-debug
Last reconfirmed| |2012-07-17
CC| |burnus at gcc dot gnu.org
Ever Confirmed|0 |1
Summary|gfortran ignores file part |gfortran ignores file part
|of #line directives |of #line directives for
| |debugging
--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-07-17 11:55:40 UTC ---
Confirmed.
For diagnostic output, the file name is taken into account, but not for
generating debug info.
That the diagnostic part is okay, can be seen when making the test case
invalid, but also when looking at the code generated by
-fdump-tree-original-lineno (the correct file name is passed to the I/O
library).
In principle, it is handled via gcc/fortran/scanner.c's preprocessor_line().
The question is why it only works partially.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/53993] gfortran ignores file part of #line directives for debugging
2012-07-17 10:54 [Bug fortran/53993] New: gfortran ignores file part of #line directives mg1102 at web dot de
2012-07-17 11:55 ` [Bug fortran/53993] gfortran ignores file part of #line directives for debugging burnus at gcc dot gnu.org
@ 2012-07-17 12:38 ` burnus at gcc dot gnu.org
2012-07-17 15:53 ` burnus at gcc dot gnu.org
2012-07-18 9:29 ` burnus at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-07-17 12:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53993
--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-07-17 12:37:52 UTC ---
Okay, I think I understand:
#include "myfile.f90"
gets translated (cpp) into
# 1 "myfile.f90" 1
... content of that file ...
# 8 "myfile.f90" 2
Where "1" is the first line of "file" and "8" is the line, in the main file,
after the #include.
However, '#line 1234 "file"' gets translated into a simple:
# 1234 "file"
And the scanner.c code seemingly doesn't handle the case of having no number
after the string.
The following feels a bit hackish, but it works. I think the function could do
with some more comments.
--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -1728,2 +1728,8 @@ preprocessor_line (gfc_char_t *c)
+ if (! *c)
+ {
+ flag[1] = true;
+ goto process;
+ }
+
for (;;)
@@ -1741,2 +1747,3 @@ preprocessor_line (gfc_char_t *c)
+process:
/* Convert the filename in wide characters into a filename in narrow
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/53993] gfortran ignores file part of #line directives for debugging
2012-07-17 10:54 [Bug fortran/53993] New: gfortran ignores file part of #line directives mg1102 at web dot de
2012-07-17 11:55 ` [Bug fortran/53993] gfortran ignores file part of #line directives for debugging burnus at gcc dot gnu.org
2012-07-17 12:38 ` burnus at gcc dot gnu.org
@ 2012-07-17 15:53 ` burnus at gcc dot gnu.org
2012-07-18 9:29 ` burnus at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-07-17 15:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53993
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-07-17 15:52:54 UTC ---
Better documentation:
http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html
Multiple flags are allowed - and mishandled is the case that no new file/return
flag is given.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/53993] gfortran ignores file part of #line directives for debugging
2012-07-17 10:54 [Bug fortran/53993] New: gfortran ignores file part of #line directives mg1102 at web dot de
` (2 preceding siblings ...)
2012-07-17 15:53 ` burnus at gcc dot gnu.org
@ 2012-07-18 9:29 ` burnus at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-07-18 9:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53993
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-07-18 09:28:51 UTC ---
Unfortunately, my attempts to generate a working patch failed, cf.
http://gcc.gnu.org/ml/fortran/2012-07/msg00082.html
http://gcc.gnu.org/ml/fortran/2012-07/msg00085.html
I always end up with warnings of the form "filename left but not entered".
This warning is generated in scanner.c's preprocessor_line.
I think someone needs to understand what input can be expected. In particular:
How to handle the first few lines of the CPP output, of which only the last
seems to be relevant vs. those of #line directives, all of which have no flag.
For the last failing test case, the file (gfortran -E) starts with:
# 1 "libgfortran/generated/_abs_c4.F90"
# 1 "<command-line>"
# 1 "gcc-build/x86_64-unknown-linux-gnu/libgfortran//"
# 1 "libgfortran/generated/_abs_c4.F90"
Which is one line more than before.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-07-18 9:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-17 10:54 [Bug fortran/53993] New: gfortran ignores file part of #line directives mg1102 at web dot de
2012-07-17 11:55 ` [Bug fortran/53993] gfortran ignores file part of #line directives for debugging burnus at gcc dot gnu.org
2012-07-17 12:38 ` burnus at gcc dot gnu.org
2012-07-17 15:53 ` burnus at gcc dot gnu.org
2012-07-18 9:29 ` burnus at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).