Subject: Re: bin/8553: gcc reported line number too big
To: Ignatious Souvatzis <is@jocelyn.rhein.de>
From: John Hawkinson <jhawk@mit.edu>
List: netbsd-bugs
Date: 04/09/2000 14:50:59
>Description:
It appears that this problem, presuming it is the same one I am
seeing, if a result of multiline macro expansion being mishandled in
the preprocessor.

If a macro expands to be multiple lines, then either those lines need
to be merged into one line, or there needs to be a #line directive
after the macro (and, indeed, formally speaking, after each line of
the macro).

I presume this was some sort of bug introduced in egcs since I don't
recall it happening pre-egcs, but I really can't say. Consulting the
egcs ChangeLog and cvs repository isn't terribly enlightening for me;
there are some possibly related stuff, but the code has changed quite
a bit from the egcs in 1.4.2 (where I'm seeing this), and I'm not sure
if it is related or not.

chopps may have also seen this problem in bin/9099 ("cc1 cores on
syntax error"), but I'm not certain (offline discussion with him
syggested so).

>Fix:
The following patch is a workaround. I'm not sure it's safe.
I've applied it because I was getting terribly screwed by not
having good line number information for kernel debugging.

This patch causes the preprocessor to merge newlines when outputting
multiline macros, as it would do in non-macros. It certainly corrects
the line number problems, but could conceivably cause others. I'm
certainly not proficient enough in egcs to say.

Please note that this patch doesn't update the comment immediately
prior. I'm not sure I understand the commnt, anyhow, since there
are clearly backslash newlines in the macro that represent
real newlines.

===================================================================
RCS file: gnu/dist/gcc/RCS/cccp.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -c -r1.1 -r1.2
*** gnu/dist/gcc/cccp.c	2000/04/08 15:13:38	1.1
--- gnu/dist/gcc/cccp.c	2000/04/08 16:06:24	1.2
***************
*** 2935,2944 ****
  	       keep the line counts correct.  But if we are reading
  	       from a macro, keep the backslash newline, since backslash
  	       newlines have already been processed.  */
! 	    if (ip->macro)
! 	      *obp++ = '\n';
! 	    else
! 	      --obp;
  	    ++ibp;
  	    ++ip->lineno;
  	  } else {
--- 2935,2941 ----
  	       keep the line counts correct.  But if we are reading
  	       from a macro, keep the backslash newline, since backslash
  	       newlines have already been processed.  */
! 	    --obp;
  	    ++ibp;
  	    ++ip->lineno;
  	  } else {
===================================================================
RCS file: gnu/dist/gcc/RCS/version.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -c -r1.1 -r1.2
*** gnu/dist/gcc/version.c	2000/04/08 16:05:13	1.1
--- gnu/dist/gcc/version.c	2000/04/08 16:05:56	1.2
***************
*** 1 ****
! char *version_string = "egcs-2.91.60 19981201 (egcs-1.1.1 release)";
--- 1 ----
! char *version_string = "egcs-2.91.60 19981201 (egcs-1.1.1 release)+jhawk-cpp-fix";