OSDN Git Service

* cppinit.c (cpp_finish): Pop the final buffer without comment.
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 7 Aug 2001 20:37:26 +0000 (20:37 +0000)
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 7 Aug 2001 20:37:26 +0000 (20:37 +0000)
* cpplex.c (_cpp_lex_token): Don't pop the final buffer; and
take care to avoid multiple no-newline at EOF warnings in that
case.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@44701 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/cppinit.c
gcc/cpplex.c

index 669297e..b995be2 100644 (file)
@@ -1,3 +1,10 @@
+2001-08-07  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * cppinit.c (cpp_finish): Pop the final buffer without comment.
+       * cpplex.c (_cpp_lex_token): Don't pop the final buffer; and
+       take care to avoid multiple no-newline at EOF warnings in that
+       case.
+
 Tue Aug  7 22:18:06 CEST 2001  Jan Hubicka  <jh@suse.cz>
 
        * calls.c (expand_call): Do not emit INSN_SETJMP note.
index f1b6b24..5a38734 100644 (file)
@@ -1010,12 +1010,13 @@ void
 cpp_finish (pfile)
      cpp_reader *pfile;
 {
-  if (CPP_BUFFER (pfile))
-    {
-      cpp_ice (pfile, "buffers still stacked in cpp_finish");
-      while (CPP_BUFFER (pfile))
-       _cpp_pop_buffer (pfile);
-    }
+  /* cpplex.c leaves the final buffer on the stack.  This it so that
+     it returns an unending stream of CPP_EOFs to the client.  If we
+     popped the buffer, we'd derefence a NULL buffer pointer and
+     segfault.  It's nice to allow the client to do worry-free excess
+     cpp_get_token calls.  */
+  while (pfile->buffer)
+    _cpp_pop_buffer (pfile);
 
   /* Don't write the deps file if preprocessing has failed.  */
   if (CPP_OPTION (pfile, print_deps) && pfile->errors == 0)
index f9c4bb9..5e0aa5a 100644 (file)
@@ -897,21 +897,26 @@ _cpp_lex_token (pfile, result)
        pfile->line--;
       else if (! pfile->state.parsing_args)
        {
-         unsigned char ret = pfile->buffer->return_at_eof;
-
          /* Non-empty files should end in a newline.  Don't warn for
             command line and _Pragma buffers.  */
          if (pfile->lexer_pos.col != 0)
            {
-             /* Account for the missing \n.  */
+             /* Account for the missing \n, prevent multiple warnings.  */
              pfile->line++;
+             pfile->lexer_pos.col = 0;
              if (!buffer->from_stage3)
                cpp_pedwarn (pfile, "no newline at end of file");
            }
 
-         _cpp_pop_buffer (pfile);
-         if (pfile->buffer && !ret)
-           goto next_token;
+         /* Don't pop the last file.  */
+         if (buffer->prev)
+           {
+             unsigned char stop = buffer->return_at_eof;
+
+             _cpp_pop_buffer (pfile);
+             if (!stop)
+               goto next_token;
+           }
        }
       result->type = CPP_EOF;
       return;