This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Who should set main_input_filename to "<stdin>"?
Neil Booth <neil@daikokuya.co.uk> writes:
> Roger Sayle wrote:-
>
> >
> > Whilst debugging in gdb, I accidentally ran the command "jc1 -O2",
> > i.e. without a filename, only to discover than jc1 ICEs. Similar
> > tests reveal that mainline f771 also ICEs, but neither did back
> > in gcc 3.2. I then tried to discover why neither cc1 nor cc1plus
> > currently ICE, which revealed that mysteriously for the C-family
> > front-ends, main_input_filename gets set to "<stdin>" as an
> > undocumented side-effect of linemap_add in linemap.c.
> >
> > I was wondering which routine *should* be responsible for setting
> > input filename? Should java and fortran be calling linemap earlier?
> > Should "default_file_start" in varasm.c call output_file_directive
> > when main_input_filename is NULL? Or if so, is it reasonable to
> > generate ".file <stdin>" in asm_out_file. Do java_parse_file and
> > ffe_parse_file now need to defend against NULL filenames?
> >
> > This is one of those pan front-end problems that its difficult to
> > file as a f77 or java PR, as neither of them is at fault: something
> > else has obviously changed in toplev.c. I'm happy to investigate
> > a fix myself, but I don't yet know what the intended behaviour is
> > (or should be)?
>
> Maybe Geoff has an opinion. He moved it out of cpplib to linemap.c.
I do have an opinion: The name, and even the concept, of a 'main input
file' is clearly a language-specific concept, since there's no reason
that a language has to have input files at all let alone a 'main' one.
This is in fact the problem that happened to C, since if you're using
intermodule analysis you don't have a single 'main' input file, you
have several equally-important toplevel input files. I'm pretty sure
that all the places that use main_input_filename for C are broken and
need some kind of fixing.
What does Java think is the 'main' input file? I'd expect it'd have
the same problem since it compiles multiple .java files at once.
I'm not sure whether this opinion helps with this problem.
My change was dealing with the difference between an *empty* filename,
that is "", and "<stdin>"; I decided that the rule should be that
filenames that are names of files (and so can be opened etc.) should
be "" and filenames that are just tokens should be "<stdin>". I
don't think it knows about NULL filenames at all, in fact I'm pretty
sure it would crash if the filename was NULL.
--
- Geoffrey Keating <geoffk@geoffk.org>