This is the mail archive of the gcc-bugs@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]

Re: Bad error message for non-existent multiply included headers


Matt Kraai wrote:-

> When a non-existent header file is multiply included, the second
> error message is not correct.  For instance, when compiling the
> following file with Code Sourcery's online tester (2001-05-03),
> 
> #include "foo.h"
> #include "foo.h"
> 
> I get the following output:
> 
> /usr/tmp/@8078.7.c:1:17: foo.h: No such file or directory
> /usr/tmp/@8078.7.c:2:17: foo.h: Success

Ugh.  This patch fixes it; if it completes a bootstrap for me I'll
put it in mainline only.

Thanks,

Neil.

	* cppfiles.c (struct include_file): New member err_no.
	(find_or_create_entry): Set it.
	(open_file): Don't set fds to -2.  Instead, use err_no to
	remember previous errors, if any.

Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.116
diff -u -p -r1.116 cppfiles.c
--- cppfiles.c	2001/04/06 07:21:59	1.116
+++ cppfiles.c	2001/05/04 21:23:36
@@ -67,6 +67,7 @@ struct include_file
   const unsigned char *buffer;	/* pointer to cached file contents */
   struct stat st;		/* copy of stat(2) data for file */
   int fd;			/* fd open on file (short term storage only) */
+  int err_no;			/* errno obtained if opening a file failed */
   unsigned short include_count;	/* number of times file has been read */
   unsigned short refcnt;	/* number of stacked buffers using this file */
   unsigned char mapped;		/* file buffer is mmapped */
@@ -175,6 +176,7 @@ find_or_create_entry (pfile, fname)
     {
       file = xcnew (struct include_file);
       file->name = name;
+      file->err_no = errno;
       node = splay_tree_insert (pfile->all_include_files,
 				(splay_tree_key) file->name,
 				(splay_tree_value) file);
@@ -210,12 +212,12 @@ open_file (pfile, filename)
   splay_tree_node nd = find_or_create_entry (pfile, filename);
   struct include_file *file = (struct include_file *) nd->value;
 
-  if (errno)
-    file->fd = -2;
-
-  /* Don't retry opening if we failed previously.  */
-  if (file->fd == -2)
-    return 0;
+  if (file->err_no)
+    {
+      /* Ugh.  handle_missing_header () needs errno to be set.  */
+      errno = file->err_no;
+      return 0;
+    }
 
   /* Don't reopen an idempotent file. */
   if (DO_NOT_REREAD (file))
@@ -266,11 +268,9 @@ open_file (pfile, filename)
     }
 
   /* Don't issue an error message if the file doesn't exist.  */
+  file->err_no = errno;
   if (errno != ENOENT && errno != ENOTDIR)
     cpp_error_from_errno (pfile, file->name);
-
-  /* Create a negative node for this path, and return null.  */
-  file->fd = -2;
 
   return 0;
 }


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