public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [CPP] -M vs -include
@ 2002-11-02 14:24 Richard Henderson
  2002-11-07  0:01 ` Neil Booth
  2002-11-07 15:38 ` Neil Booth
  0 siblings, 2 replies; 6+ messages in thread
From: Richard Henderson @ 2002-11-02 14:24 UTC (permalink / raw)
  To: neil, gcc-patches; +Cc: Roland McGrath

The following test case:

  % echo > x.h
  % echo > z.h
  % echo '#include "z.h"' > z.c
  % gcc -M -include x.h z.c

produced

  z.o: z.c x.h

instead of the expected

  z.o: z.c x.h z.h

This caused the dependencies created by glibc to be wrong, which
leads to extremely irritating non-recompilation errors.

The following patch appears to cure the problem.  Neil, can you
comment on why you added this in the first place?


r~


	* cppmacro.c (cpp_scan_nooutput): Do not set return_at_eof.

Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.126
diff -c -p -d -u -r1.126 cppmacro.c
--- cppmacro.c	9 Oct 2002 09:56:07 -0000	1.126
+++ cppmacro.c	2 Nov 2002 22:16:23 -0000
@@ -1198,10 +1198,6 @@ void
 cpp_scan_nooutput (pfile)
      cpp_reader *pfile;
 {
-  /* Request a CPP_EOF token at the end of this file, rather than
-     transparently continuing with the including file.  */
-  pfile->buffer->return_at_eof = true;
-
   if (CPP_OPTION (pfile, traditional))
     while (_cpp_read_logical_line_trad (pfile))
       ;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [CPP] -M vs -include
  2002-11-02 14:24 [CPP] -M vs -include Richard Henderson
@ 2002-11-07  0:01 ` Neil Booth
  2002-11-07 15:38 ` Neil Booth
  1 sibling, 0 replies; 6+ messages in thread
From: Neil Booth @ 2002-11-07  0:01 UTC (permalink / raw)
  To: Richard Henderson, gcc-patches, Roland McGrath

Richard Henderson wrote:-

> The following test case:
> 
>   % echo > x.h
>   % echo > z.h
>   % echo '#include "z.h"' > z.c
>   % gcc -M -include x.h z.c
> 
> produced
> 
>   z.o: z.c x.h
> 
> instead of the expected
> 
>   z.o: z.c x.h z.h
> 
> This caused the dependencies created by glibc to be wrong, which
> leads to extremely irritating non-recompilation errors.
> 
> The following patch appears to cure the problem.  Neil, can you
> comment on why you added this in the first place?

> -  /* Request a CPP_EOF token at the end of this file, rather than
> -     transparently continuing with the including file.  */
> -  pfile->buffer->return_at_eof = true;
> -

At a glance, I don't *think* this is the bug; that is needed so we
only scan a single file.

I'll take a look in the next 24 hours.

Neil.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [CPP] -M vs -include
  2002-11-02 14:24 [CPP] -M vs -include Richard Henderson
  2002-11-07  0:01 ` Neil Booth
@ 2002-11-07 15:38 ` Neil Booth
  2002-11-07 15:45   ` Zack Weinberg
  1 sibling, 1 reply; 6+ messages in thread
From: Neil Booth @ 2002-11-07 15:38 UTC (permalink / raw)
  To: Richard Henderson, gcc-patches, Roland McGrath

Richard Henderson wrote:-

> The following test case:
> 
>   % echo > x.h
>   % echo > z.h
>   % echo '#include "z.h"' > z.c
>   % gcc -M -include x.h z.c
> 
> produced
> 
>   z.o: z.c x.h
> 
> instead of the expected
> 
>   z.o: z.c x.h z.h
> 
> This caused the dependencies created by glibc to be wrong, which
> leads to extremely irritating non-recompilation errors.
> 
> The following patch appears to cure the problem.  Neil, can you
> comment on why you added this in the first place?

cpp_scan_nooutput's semantics are to return when the current buffer
(and anything it includes) have been scanned; this is why it sets
return_at_eof.  This is what we need for -imacros; with your suggested
patch -imacros would not stop after the first -imacros file; it would
continue its scan and only get its CPP_EOF at the end of the main file.
Oops.

The bug is that cpp_preprocess_file in cppmain.c is assuming, in calling
cpp_scan_nooutput the way it does, that the current buffer is the
main file, and so that when the current buffer is finished, the whole
job is done.  In the presence of -include, that is not true, as
_cpp_maybe_push_include_file has put the first -included file on top
of the main file and made it the current one.

Easily fixed by forcing cpp_preprocess_file to loop until it really has
done all the buffers.  I seem to recall removing this loop thinking it
didn't achieve anything.  Heh.

The loop condition sucks; I'll do something better for 3.4.

Thanks for finding this issue.  I'll apply the patch after a bootstrap
etc.

Neil.

	* cppmain.c (cpp_preprocess_file): Loop to pop any -included
	buffers.

Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.104
diff -u -p -r1.104 cppmain.c
--- cppmain.c	12 Aug 2002 17:21:52 -0000	1.104
+++ cppmain.c	7 Nov 2002 23:35:42 -0000
@@ -78,7 +78,13 @@ cpp_preprocess_file (pfile, in_fname, ou
       /* A successful cpp_read_main_file guarantees that we can call
 	 cpp_scan_nooutput or cpp_get_token next.  */
       if (options->no_output)
-	cpp_scan_nooutput (pfile);
+	{
+	  /* Loop in case of -included buffers.  */
+	  do
+	    cpp_scan_nooutput (pfile);
+	  while (pfile->buffer->prev
+		 || pfile->buffer->cur < pfile->buffer->rlimit);
+	}
       else if (options->traditional)
 	scan_translation_unit_trad (pfile);
       else

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [CPP] -M vs -include
  2002-11-07 15:38 ` Neil Booth
@ 2002-11-07 15:45   ` Zack Weinberg
  2002-11-07 15:54     ` Richard Henderson
  0 siblings, 1 reply; 6+ messages in thread
From: Zack Weinberg @ 2002-11-07 15:45 UTC (permalink / raw)
  To: Neil Booth; +Cc: Richard Henderson, gcc-patches, Roland McGrath

On Thu, Nov 07, 2002 at 11:38:19PM +0000, Neil Booth wrote:
> +	{
> +	  /* Loop in case of -included buffers.  */
> +	  do
> +	    cpp_scan_nooutput (pfile);
> +	  while (pfile->buffer->prev
> +		 || pfile->buffer->cur < pfile->buffer->rlimit);
> +	}

Hmm, is that brace block necessary?

zw

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [CPP] -M vs -include
  2002-11-07 15:45   ` Zack Weinberg
@ 2002-11-07 15:54     ` Richard Henderson
  2002-11-08  0:33       ` Neil Booth
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2002-11-07 15:54 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: Neil Booth, gcc-patches, Roland McGrath

On Thu, Nov 07, 2002 at 03:45:08PM -0800, Zack Weinberg wrote:
> On Thu, Nov 07, 2002 at 11:38:19PM +0000, Neil Booth wrote:
> > +	{
> > +	  /* Loop in case of -included buffers.  */
> > +	  do
> > +	    cpp_scan_nooutput (pfile);
> > +	  while (pfile->buffer->prev
> > +		 || pfile->buffer->cur < pfile->buffer->rlimit);
> > +	}
> 
> Hmm, is that brace block necessary?

No, but I think it's easier to read.


r~

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [CPP] -M vs -include
  2002-11-07 15:54     ` Richard Henderson
@ 2002-11-08  0:33       ` Neil Booth
  0 siblings, 0 replies; 6+ messages in thread
From: Neil Booth @ 2002-11-08  0:33 UTC (permalink / raw)
  To: Richard Henderson, Zack Weinberg, gcc-patches, Roland McGrath

Richard Henderson wrote:-

> On Thu, Nov 07, 2002 at 03:45:08PM -0800, Zack Weinberg wrote:
> > On Thu, Nov 07, 2002 at 11:38:19PM +0000, Neil Booth wrote:
> > > +	{
> > > +	  /* Loop in case of -included buffers.  */
> > > +	  do
> > > +	    cpp_scan_nooutput (pfile);
> > > +	  while (pfile->buffer->prev
> > > +		 || pfile->buffer->cur < pfile->buffer->rlimit);
> > > +	}
> > 
> > Hmm, is that brace block necessary?
> 
> No, but I think it's easier to read.

This patch is better; it's clearer and avoids the icky loop condition.
This code will eventually move to the front end and out of cpplib,
so the pfile dereference will have to go then.  Possibly we can
have an extra argument to cpp_scan_nooutput or something.

I'll come up with a testcase, similarly to some of Jakub's tests,
this evening if I find time.

Neil.

	* cppmain.c (cpp_preprocess_file): Loop to pop any -included
	buffers.

Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.104
diff -u -p -r1.104 cppmain.c
--- cppmain.c	12 Aug 2002 17:21:52 -0000	1.104
+++ cppmain.c	8 Nov 2002 08:27:30 -0000
@@ -78,7 +78,12 @@ cpp_preprocess_file (pfile, in_fname, ou
       /* A successful cpp_read_main_file guarantees that we can call
 	 cpp_scan_nooutput or cpp_get_token next.  */
       if (options->no_output)
-	cpp_scan_nooutput (pfile);
+	{
+	  /* Scan -included buffers, then the main file.  */
+	  while (pfile->buffer->prev)
+	    cpp_scan_nooutput (pfile);
+	  cpp_scan_nooutput (pfile);
+	}
       else if (options->traditional)
 	scan_translation_unit_trad (pfile);
       else

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-11-08  8:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-02 14:24 [CPP] -M vs -include Richard Henderson
2002-11-07  0:01 ` Neil Booth
2002-11-07 15:38 ` Neil Booth
2002-11-07 15:45   ` Zack Weinberg
2002-11-07 15:54     ` Richard Henderson
2002-11-08  0:33       ` Neil Booth

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).