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]

[3.3 regression] fix incorrect line break before functional macro name


It came to my attention that code such as:

#define FOO()
FOO
bar

that used to be preprocessed such that FOO and bar were in separate
lines, after my patch to get the separate preprocessor in sync with
the internal preprocessor, would result in FOO being printed in the
wrong line, i.e., in same line as bar.

The behavior change seems to have also affected other uses of the
preprocessor for assembly code (why do we use cc1, and not cpp0, to
preprocess assembly?  Shouldn't assembly be regarded as requiring
-traditional preprocessing?).

This patch is an update of the patch I posted on Aug 4 as an
alternative to the one that ended up going in, that restores the
original preprocessor behavior, and adjusts the integrated
preprocessor such that its behavior matches that of the separate
preprocessor (a condition that I'm told was set as an acceptance
criteria for the integrated preprocessor).

Bootstrapped and regression tested on athlon-pc-linux-gnu.  Ok to
install in the 3.3 branch?  Ok for mainline as well?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* c-ppoutput.c (cb_line_change): Revert 2003-08-04's change.
	* c-lex.c (cb_line_change): Skip line changing whenever
	c-ppoutput.c would.

Index: gcc/c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.190.4.1
diff -u -p -r1.190.4.1 c-lex.c
--- gcc/c-lex.c 11 Feb 2003 22:49:52 -0000 1.190.4.1
+++ gcc/c-lex.c 14 Sep 2003 03:58:32 -0000
@@ -245,8 +245,11 @@ static void
 cb_line_change (pfile, token, parsing_args)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
      const cpp_token *token;
-     int parsing_args ATTRIBUTE_UNUSED;
+     int parsing_args;
 {
+  if (token->type == CPP_EOF || parsing_args)
+    return;
+
   src_lineno = SOURCE_LINE (map, token->line);
 }
 
Index: gcc/cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/cppmain.c,v
retrieving revision 1.105.2.1
diff -u -p -r1.105.2.1 cppmain.c
--- gcc/cppmain.c 23 Aug 2003 20:27:54 -0000 1.105.2.1
+++ gcc/cppmain.c 14 Sep 2003 03:58:33 -0000
@@ -284,9 +284,9 @@ static void
 cb_line_change (pfile, token, parsing_args)
      cpp_reader *pfile;
      const cpp_token *token;
-     int parsing_args ATTRIBUTE_UNUSED;
+     int parsing_args;
 {
-  if (token->type == CPP_EOF)
+  if (token->type == CPP_EOF || parsing_args)
     return;
 
   maybe_print_line (pfile, pfile->print.map, token->line);
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* gcc.dg/cpp/separate-1.c: Adjust line of error.  Test for correct
	non-expansion of functional macro name without arguments at EOL.
	* gcc.dg/cpp/spacing1.c: Revert 2003-08-04's change.  Likewise.

Index: gcc/testsuite/gcc.dg/cpp/separate-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/cpp/separate-1.c,v
retrieving revision 1.1.8.1
diff -u -p -r1.1.8.1 separate-1.c
--- gcc/testsuite/gcc.dg/cpp/separate-1.c 23 Aug 2003 20:27:49 -0000 1.1.8.1
+++ gcc/testsuite/gcc.dg/cpp/separate-1.c 14 Sep 2003 03:58:40 -0000
@@ -8,5 +8,8 @@
 
 #define FOO()
 
-int FOO(
-	), bar; /* { dg-error "(parse|syntax) error" "error on this line" } */
+int FOO( /* { dg-error "(parse|syntax) error" "error on this line" } */
+	), bar;
+
+int baz FOO /* { dg-error "(parse|syntax) error" "error on this line" } */
+; /* { dg-warning "no type or storage class" "warning on this line" } */
Index: gcc/testsuite/gcc.dg/cpp/spacing1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/cpp/spacing1.c,v
retrieving revision 1.3.38.2
diff -u -p -r1.3.38.2 spacing1.c
--- gcc/testsuite/gcc.dg/cpp/spacing1.c 23 Aug 2003 20:38:43 -0000 1.3.38.2
+++ gcc/testsuite/gcc.dg/cpp/spacing1.c 14 Sep 2003 03:58:40 -0000
@@ -14,14 +14,10 @@
    invocation is not defined: we might consider them to be in the same
    line as the initial token of the invocation, or as the final token
    of the invocation, or even anything in between.  We choose to make
-   it the final token, but we might as well collapse the invocation
-   and the rest of the line into the initial line, such that `g
-   ... bam baz' below were all in a single line in the preprocessor
-   output.  We used to do this at some point, but it disagreed with
-   the way we numbered lines with the integrated preprocessor, so we
-   had to pick one of them to change.
+   it the initial token, such that everything that is in a logical
+   line ends up in a single line after preprocessing.
 
-   Alexandre Oliva, Aug 5, 2003.  */
+   Alexandre Oliva, Sept 13, 2003.  */
 
 #define str(x) #x
 #define f(x) x
@@ -41,18 +37,18 @@
 B Q B Q A Q A:
 f
 bar
-g
+A
+bad
+g "1 2" bam baz
 
-
-
- "1 2"
- bam baz
 */
 
 glue (EMPTY 4, 4) EMPTY;
 A(Q) C(Q) D()Q D():
 f
 bar
+A
+bad
 f (g) str
 (
 1
@@ -66,9 +62,9 @@ f (g) str
    { dg-final { if \{ [grep spacing1.i "B Q B Q A Q A:"] != "" \}     \{  } }
    { dg-final { if \{ [grep spacing1.i "f.*bar"] == "" \} \{              } }
    { dg-final { if \{ [grep spacing1.i "^bar"] != "" \}   \{              } }
-   { dg-final { if \{ [grep spacing1.i "g"] != "" \} \{                   } }
-   { dg-final { if \{ [grep spacing1.i " \"1 2\""] != "" \} \{            } }
-   { dg-final { if \{ [grep spacing1.i " bam baz"] != "" \} \{            } }
+   { dg-final { if \{ [grep spacing1.i "^A$"] != "" \}   \{               } }
+   { dg-final { if \{ [grep spacing1.i "^bad$"] != "" \}   \{             } }
+   { dg-final { if \{ [grep spacing1.i "g \"1 2\" bam baz"] != "" \} \{   } }
    { dg-final { return \} \} \} \} \} \} \}                               } }
    { dg-final { fail "spacing1.c: spacing and new-line preservation"      } }
 */
-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

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