[Bug preprocessor/34869] valgrind error indication in testsuite from _cpp_lex_token (lex.c:783) with gcc.dg/cpp/line5.c

lauras at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Thu Apr 23 17:10:00 GMT 2009



------- Comment #1 from lauras at gcc dot gnu dot org  2009-04-23 17:09 -------
It looks like _cpp_lex_direct lexes ahead even if there unused lookahead
tokens, which later causes uninitialized tokens as reported by valgrind. I am
bootstrapping the patch below which seems to fix the issue.

Index: libcpp/lex.c
===================================================================
--- libcpp/lex.c        (revision 146637)
+++ libcpp/lex.c        (working copy)
@@ -880,8 +880,8 @@
 }

 /* Lex a token into RESULT (external interface).  Takes care of issues
-   like directive handling, token lookahead, multiple include
-   optimization and skipping.  */
+   like directive handling, multiple include optimization and
+   skipping.  */
 const cpp_token *
 _cpp_lex_token (cpp_reader *pfile)
 {
@@ -900,13 +900,7 @@
          || pfile->cur_token >= pfile->cur_run->limit)
        abort ();

-      if (pfile->lookaheads)
-       {
-         pfile->lookaheads--;
-         result = pfile->cur_token++;
-       }
-      else
-       result = _cpp_lex_direct (pfile);
+      result = _cpp_lex_direct (pfile);

       if (result->flags & BOL)
        {
@@ -1003,10 +997,11 @@
 /* Lex a token into pfile->cur_token, which is also incremented, to
    get diagnostics pointing to the correct location.

-   Does not handle issues such as token lookahead, multiple-include
-   optimization, directives, skipping etc.  This function is only
-   suitable for use by _cpp_lex_token, and in special cases like
-   lex_expansion_token which doesn't care for any of these issues.
+   Is able to handle token lookahead, but does not handle issues such
+   as multiple-include optimization, directives, skipping etc.  This
+   function is only suitable for use by _cpp_lex_token, and in special
+   cases like lex_expansion_token which doesn't care for any of these
+   issues.

    When meeting a newline, returns CPP_EOF if parsing a directive,
    otherwise returns to the start of the token buffer if permissible.
@@ -1019,6 +1014,12 @@
   const unsigned char *comment_start;
   cpp_token *result = pfile->cur_token++;

+  if (pfile->lookaheads)
+    {
+      pfile->lookaheads--;
+      return result;
+    }
+
  fresh_line:
   result->flags = 0;
   buffer = pfile->buffer;


-- 

lauras at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lauras at gcc dot gnu dot
                   |                            |org
   Last reconfirmed|2008-04-18 16:38:18         |2009-04-23 17:09:55
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34869



More information about the Gcc-bugs mailing list