This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Always pass an open file descriptor to c_common_read_pch


Hi all,

Overly complicated makefiles discover this kind of bug:

# touch x.cpp x.h
# g++ -c x.h
# g++ -include x.h -include x.h -c x.cpp  # note the double -include
<command line>:-80: internal compiler error: in c_common_read_pch, at
c-pch.c:
   238
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

(That is with my assert patch.  Without it the error reads "cc1plus:
calling
fdopen: Bad file descriptor").

The problem here is that find_file returns an entry from the cache that
has
been closed before.  That entry is then passed on until
c_common_read_pch
that tries to do an fdopen.  The call to read_file below doesn't have
this
problem because the file is reopened if needed in read_file itself.

I successfully tested the attached patch with a complete bootstrap on
i686-pc-linux-gnu, all languages including Ada with no new testsuite
failures. [I hope the webmailer won't screw up the formatting...]

Michael

2003-08-18  Michael Ritzert  <ritzert@t-online.de>

        * c-pch.c (c_common_read_pch): Assert that an invalid file
descriptor
        will never get here.
        * cppfiles.c (should_stack_file): Make sure that the file
descriptor
        passed to read_pch is valid.

Index: c-pch.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pch.c,v
retrieving revision 1.14
diff -u -3 -p -f -r1.14 c-pch.c
*** c-pch.c     29 Jul 2003 23:36:46 -0000      1.14
--- c-pch.c     18 Aug 2003 19:39:42 -0000
*************** c_common_read_pch (cpp_reader *pfile, co
*** 234,240 ****
    char *buf;
    unsigned long written;
    struct save_macro_data *smd;
!
    f = fdopen (fd, "rb");
    if (f == NULL)
      {
--- 234,241 ----
    char *buf;
    unsigned long written;
    struct save_macro_data *smd;
!
!   my_friendly_assert( fd != -1, 20030818 );
    f = fdopen (fd, "rb");
    if (f == NULL)
      {
Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.186
diff -u -3 -p -f -r1.186 cppfiles.c
*** cppfiles.c  9 Aug 2003 22:14:07 -0000       1.186
--- cppfiles.c  18 Aug 2003 19:39:42 -0000
*************** should_stack_file (cpp_reader *pfile, _c
*** 551,556 ****
--- 551,563 ----
    /* Handle PCH files immediately; don't stack them.  */
    if (include_pch_p (file))
      {
+       /* Make sure the file is open.  */
+       if (file->fd == -1)
+       {
+         if (!pch_open_file (pfile, file))
+           return false;
+       }
+
        pfile->cb.read_pch (pfile, file->path, file->fd,
file->pchname);
        close (file->fd);
        file->fd = -1;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]