public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug preprocessor/98882] [11 Regression] ICE in in cpp_directive_only_process on empty translation unit
Date: Wed, 03 Feb 2021 22:18:45 +0000	[thread overview]
Message-ID: <bug-98882-4-p0MFyGi8I5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98882-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98882

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:ac16f4327fef5dfc288409371a61649253353ef7

commit r11-7093-gac16f4327fef5dfc288409371a61649253353ef7
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Feb 3 23:18:05 2021 +0100

    libcpp: Fix up -fdirectives-only preprocessing [PR98882]

    GCC 11 ICEs on all -fdirectives-only preprocessing when the files don't end
    with a newline.

    The problem is in the assertion, for empty TUs buffer->cur ==
buffer->rlimit
    and so buffer->rlimit[-1] access triggers UB in the preprocessor, for
    non-empty TUs it refers to the last character in the file, which can be
    anything.
    The preprocessor adds a '\n' character (or '\r', in particular if the
    user file ends with '\r' then it adds another '\r' rather than '\n'), but
    that is added after the limit, i.e. at buffer->rlimit[0].

    Now, if the routine handles occassional bumping of pos to buffer->rlimit +
1,
    I think it is just the assert that needs changing, usually we read from
*pos
    if pos < limit and then e.g. if it is '\r', look at the following character
    (which could be one of those '\n' or '\r' at buffer->rlimit[0]).  There is
    also the case where for '\\' before the limit we read following character
    and if it is '\n', do one thing, if it is '\r' read another character.
    But in that case if '\\' was the last char in the TU, the limit char will
be
    '\n', so we are ok.

    2021-02-03  Jakub Jelinek  <jakub@redhat.com>

            PR preprocessor/98882
            * lex.c (cpp_directive_only_process): Don't assert that rlimit[-1]
            is a newline, instead assert that rlimit[0] is either newline or
            carriage return.  When seeing '\\' followed by '\r', check limit
            before accessing pos[1].

            * gcc.dg/cpp/pr98882.c: New test.

  parent reply	other threads:[~2021-02-03 22:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-29 10:58 [Bug c++/98882] New: " boris at kolpackov dot net
2021-01-29 11:34 ` [Bug c++/98882] " jakub at gcc dot gnu.org
2021-01-29 12:01 ` [Bug c++/98882] [11 Regression] " jakub at gcc dot gnu.org
2021-01-29 12:32 ` [Bug preprocessor/98882] " jakub at gcc dot gnu.org
2021-02-03 22:18 ` cvs-commit at gcc dot gnu.org [this message]
2021-02-03 22:19 ` jakub at gcc dot gnu.org
2021-02-08 10:42 ` boris at kolpackov dot net
2021-02-09 16:40 ` jakub at gcc dot gnu.org
2021-02-10  5:21 ` boris at kolpackov dot net

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-98882-4-p0MFyGi8I5@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).