Is CPP broken? (Re: Strange gcc error message)

H . J . Lu hjl@lucon.org
Sun Oct 7 11:34:00 GMT 2001


On Sun, Oct 07, 2001 at 06:23:38PM +0100, Neil Booth wrote:
> H . J . Lu wrote:-
> 
> > On Sat, Oct 06, 2001 at 10:16:37AM -0700, H . J . Lu wrote:
> > > With the CVS on Oct. 6, I got
> > > 
> > > # touch foo.c   
> > > # ./xgcc -B./  -c foo.c
> > > Errors detected in input file (your bison.simple is out of date)
> > > 
> > > I think it is a new message for me. I don't believe it is right.
> > 
> > Hi Neil,
> > 
> > It turned out that this error message is caued by CPP. Is that
> > intentional for CPP to treat an empty file as an error?
> 
> Would you elaborate?
> 

#define DO_NOT_REREAD(inc) \
((inc)->cmacro && ((inc)->cmacro == NEVER_REREAD \
                   || (inc)->cmacro->type == NT_MACRO))

In open_file (),

          /* Mark a regular, zero-length file never-reread now.  */
          if (S_ISREG (file->st.st_mode) && file->st.st_size == 0)
            {       
              _cpp_never_reread (file); 
              close (file->fd);
              file->fd = -1;
            }

          return file;

In stack_include_file (),

  if (DO_NOT_REREAD (inc))
    return false;

In _cpp_read_file (),

  if (f == NULL)
    cpp_error_from_errno (pfile, fname); 
  else
    stacked = stack_include_file (pfile, f);

  return stacked;

#0  open_file (pfile=0x82c73d0, filename=0xbffffac6 "/tmp/x.i")
    at /home/hjl/work/gnu/src/gcc/gcc/gcc/cppfiles.c:212
#1  0x08077506 in _cpp_read_file (pfile=0x82c73d0, fname=0xbffffac6 "/tmp/x.i")
    at /home/hjl/work/gnu/src/gcc/gcc/gcc/cppfiles.c:712
#2  0x08079104 in cpp_start_read (pfile=0x82c73d0, fname=0xbffffac6 "/tmp/x.i")
    at /home/hjl/work/gnu/src/gcc/gcc/gcc/cppinit.c:953
#3  0x0804ef37 in yyparse () at /home/hjl/work/gnu/src/gcc/gcc/gcc/c-lex.c:163
#4  0x08169e5c in compile_file (name=0x82c59e4 "/tmp/x.i")
    at /home/hjl/work/gnu/src/gcc/gcc/gcc/toplev.c:2328
#5  0x0816d7f7 in toplev_main (argc=9, argv=0xbffff954)
    at /home/hjl/work/gnu/src/gcc/gcc/gcc/toplev.c:4973
#6  0x400435b7 in __libc_start_main (main=0x807b540 <main>, argc=9, 
    ubp_av=0xbffff954, init=0x804909c <_init>, fini=0x8201a70 <_fini>, 
    rtld_fini=0x4000dc74 <_dl_fini>, stack_end=0xbffff94c)
    at ../sysdeps/generic/libc-start.c:129

Since cpp_start_read () returns false, yyparse () returns 1.

>From the comments in open_file, it is done on purpose. Is that true?



H.J.



More information about the Gcc-bugs mailing list