public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: preprocessor/6386: Spurious "unterminated #if"
@ 2002-04-21  3:56 Neil Booth
  0 siblings, 0 replies; 4+ messages in thread
From: Neil Booth @ 2002-04-21  3:56 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR preprocessor/6386; it has been noted by GNATS.

From: Neil Booth <neil@daikokuya.demon.co.uk>
To: Andreas Schwab <schwab@suse.de>
Cc: gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: preprocessor/6386: Spurious "unterminated #if"
Date: Sun, 21 Apr 2002 11:50:59 +0100

 Neil Booth wrote:-
 
 > 	* cppmacro.c (funlike_invocation_p): Don't step back over CPP_EOF.
 > testsuite:
 > 	* gcc.dg/cpp/endif.h, gcc.dg/cpp/endif.c: New tests.
 > 
 > Index: cppmacro.c
 > ===================================================================
 > RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
 > retrieving revision 1.98
 > diff -u -p -r1.98 cppmacro.c
 > --- cppmacro.c	14 Apr 2002 18:42:46 -0000	1.98
 > +++ cppmacro.c	20 Apr 2002 22:04:19 -0000
 > @@ -632,12 +632,15 @@ funlike_invocation_p (pfile, node)
 >        return collect_args (pfile, node);
 >      }
 >  
 > -  /* Back up.  We may have skipped padding, in which case backing up
 > -     more than one token when expanding macros is in general too
 > -     difficult.  We re-insert it in its own context.  */
 > -  _cpp_backup_tokens (pfile, 1);
 > -  if (padding)
 > -    push_token_context (pfile, NULL, padding, 1);
 > +  if (token->type != CPP_EOF)
 > +    {
 > +      /* Back up.  We may have skipped padding, in which case backing
 > +	 up more than one token when expanding macros is in general
 > +	 too difficult.  We re-insert it in its own context.  */
 > +      _cpp_backup_tokens (pfile, 1);
 > +      if (padding)
 > +	push_token_context (pfile, NULL, padding, 1);
 > +    }
 
 Sadly, that wasn't quite enough.  This is the patch I've committed.
 
 Neil.
 
 Index: cppmacro.c
 ===================================================================
 RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
 retrieving revision 1.91.6.3
 diff -u -p -r1.91.6.3 cppmacro.c
 --- cppmacro.c	1 Apr 2002 21:16:43 -0000	1.91.6.3
 +++ cppmacro.c	21 Apr 2002 10:47:48 -0000
 @@ -646,12 +646,17 @@ funlike_invocation_p (pfile, node)
        return collect_args (pfile, node);
      }
  
 -  /* Back up.  We may have skipped padding, in which case backing up
 -     more than one token when expanding macros is in general too
 -     difficult.  We re-insert it in its own context.  */
 -  _cpp_backup_tokens (pfile, 1);
 -  if (padding)
 -    push_token_context (pfile, NULL, padding, 1);
 +  /* CPP_EOF can be the end of macro arguments, or the end of the
 +     file.  We mustn't back up over the latter.  Ugh.  */
 +  if (token->type != CPP_EOF || token == &pfile->eof)
 +    {
 +      /* Back up.  We may have skipped padding, in which case backing
 +	 up more than one token when expanding macros is in general
 +	 too difficult.  We re-insert it in its own context.  */
 +      _cpp_backup_tokens (pfile, 1);
 +      if (padding)
 +	push_token_context (pfile, NULL, padding, 1);
 +    }
  
    return NULL;
  }


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

* Re: preprocessor/6386: Spurious "unterminated #if"
@ 2002-04-21  9:13 neil
  0 siblings, 0 replies; 4+ messages in thread
From: neil @ 2002-04-21  9:13 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, schwab

Synopsis: Spurious "unterminated #if"

State-Changed-From-To: open->closed
State-Changed-By: neil
State-Changed-When: Sun Apr 21 09:13:51 2002
State-Changed-Why:
    Fixed for 3.1 and 3.2.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6386


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

* Re: preprocessor/6386: Spurious "unterminated #if"
@ 2002-04-20 15:16 Neil Booth
  0 siblings, 0 replies; 4+ messages in thread
From: Neil Booth @ 2002-04-20 15:16 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR preprocessor/6386; it has been noted by GNATS.

From: Neil Booth <neil@daikokuya.demon.co.uk>
To: Andreas Schwab <schwab@suse.de>
Cc: gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: preprocessor/6386: Spurious "unterminated #if"
Date: Sat, 20 Apr 2002 23:08:34 +0100

 Andreas Schwab wrote:-
 
 > #if 1
 > #include "b.c"
 > #endif
 > $ cat b.c
 > S
 > $ gcc -E a.c
 > # 1 "a.c"
 > # 1 "<built-in>"
 > # 1 "<command line>"
 > # 1 "a.c"
 > 
 > 
 > # 1 "b.c" 1
 > S
 > # 4 "a.c" 2
 > a.c:2:1: unterminated #if
 
 Thanks for the bug report.  I'm testing this patch for regressions;
 if it passes I'll apply it to 3.1 and 3.2.
 
 Neil.
 
 	* cppmacro.c (funlike_invocation_p): Don't step back over CPP_EOF.
 testsuite:
 	* gcc.dg/cpp/endif.h, gcc.dg/cpp/endif.c: New tests.
 
 Index: cppmacro.c
 ===================================================================
 RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
 retrieving revision 1.98
 diff -u -p -r1.98 cppmacro.c
 --- cppmacro.c	14 Apr 2002 18:42:46 -0000	1.98
 +++ cppmacro.c	20 Apr 2002 22:04:19 -0000
 @@ -632,12 +632,15 @@ funlike_invocation_p (pfile, node)
        return collect_args (pfile, node);
      }
  
 -  /* Back up.  We may have skipped padding, in which case backing up
 -     more than one token when expanding macros is in general too
 -     difficult.  We re-insert it in its own context.  */
 -  _cpp_backup_tokens (pfile, 1);
 -  if (padding)
 -    push_token_context (pfile, NULL, padding, 1);
 +  if (token->type != CPP_EOF)
 +    {
 +      /* Back up.  We may have skipped padding, in which case backing
 +	 up more than one token when expanding macros is in general
 +	 too difficult.  We re-insert it in its own context.  */
 +      _cpp_backup_tokens (pfile, 1);
 +      if (padding)
 +	push_token_context (pfile, NULL, padding, 1);
 +    }
  
    return NULL;
  }
 Index: testsuite/gcc.dg/cpp/endif.c
 ===================================================================
 RCS file: testsuite/gcc.dg/cpp/endif.c
 diff -N testsuite/gcc.dg/cpp/endif.c
 --- /dev/null	1 Jan 1970 00:00:00 -0000
 +++ testsuite/gcc.dg/cpp/endif.c	20 Apr 2002 22:04:19 -0000
 @@ -0,0 +1,14 @@
 +/* Copyright (C) 2002 Free Software Foundation, Inc.  */
 +
 +/* { dg-do preprocess } */
 +
 +/* Test case for PR preprocessor/6386 by Andreas Schwab.  We'd back up
 +   over the CPP_EOF token (indicating not a funlike macro invocation)
 +   in the header file, which would then be passed through as a real
 +   EOF, leading to an early exit (and therefore bogus complaint about
 +   unterminated #if).  */
 +
 +#define S(x)
 +#if 1
 +#include "endif.h"
 +#endif
 Index: testsuite/gcc.dg/cpp/endif.h
 ===================================================================
 RCS file: testsuite/gcc.dg/cpp/endif.h
 diff -N testsuite/gcc.dg/cpp/endif.h
 --- /dev/null	1 Jan 1970 00:00:00 -0000
 +++ testsuite/gcc.dg/cpp/endif.h	20 Apr 2002 22:04:19 -0000
 @@ -0,0 +1 @@
 +S


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

* preprocessor/6386: Spurious "unterminated #if"
@ 2002-04-20 14:26 Andreas Schwab
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2002-04-20 14:26 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6386
>Category:       preprocessor
>Synopsis:       Spurious "unterminated #if"
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 20 14:26:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        3.1 20020415 (prerelease)
>Organization:
>Environment:
System: Linux sykes 2.4.18-SMP #1 SMP Sat Apr 13 18:56:25 UTC 2002 ia64 unknown
Architecture: ia64

	
host: ia64-suse-linux-gnu
build: ia64-suse-linux-gnu
target: ia64-suse-linux-gnu
configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --enable-languages=c,c++,f77,objc,java,ada --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --libdir=/usr/lib --enable-checking ia64-suse-linux
>Description:
A function-like macro used in non-function context at the end of an
include file that was included inside #if/#endif pair confuses the
preprocessor.
>How-To-Repeat:
$ cat a.c
#define S(x)
#if 1
#include "b.c"
#endif
$ cat b.c
S
$ gcc -E a.c
# 1 "a.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "a.c"


# 1 "b.c" 1
S
# 4 "a.c" 2
a.c:2:1: unterminated #if
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2002-04-21 16:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-21  3:56 preprocessor/6386: Spurious "unterminated #if" Neil Booth
  -- strict thread matches above, loose matches on Subject: below --
2002-04-21  9:13 neil
2002-04-20 15:16 Neil Booth
2002-04-20 14:26 Andreas Schwab

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