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 tree-optimization/110603] [14 Regression] GCC, ICE: internal compiler error: in verify_range, at value-range.cc:1104 since r14-255
Date: Mon, 29 Jan 2024 09:21:23 +0000	[thread overview]
Message-ID: <bug-110603-4-qgCecrCpKI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110603-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #7 from GCC 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:b338fdbc2b74f25c07da263a1f5983421fac1a53

commit r14-8487-gb338fdbc2b74f25c07da263a1f5983421fac1a53
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jan 29 10:20:32 2024 +0100

    tree-ssa-strlen: Fix pdata->maxlen computation [PR110603]

    On the following testcase we emit an invalid range of [2, 1] due to
    UB in the source.  Older VRP code silently swapped the boundaries and
    made [1, 2] range out of it, but newer code just ICEs on it.

    The reason for pdata->minlen 2 is that we see a memcpy in this case
    setting both elements of the array to non-zero value, so strlen (a)
    can't be smaller than 2.  The reason for pdata->maxlen 1 is that in
    char a[2] array without UB there can be at most 1 non-zero character
    because there needs to be '\0' termination in the buffer too.

    IMHO we shouldn't create invalid ranges like that and even creating
    for that case a range [1, 2] looks wrong to me, so the following patch
    just doesn't set maxlen in that case to the array size - 1, matching
    what will really happen at runtime when triggering such UB (strlen will
    be at least 2, perhaps more or will crash).
    This is what the second hunk of the patch does.

    The first hunk fixes a fortunately harmless thinko.
    If the strlen pass knows the string length (i.e. get_string_length
    function returns non-NULL), we take a different path, we get to this
    only if all we know is that there are certain number of non-zero
    characters but we don't know what it is followed with, whether further
    non-zero characters or zero termination or either of that.
    If we know exactly how many non-zero characters it is, such as
    char a[42];
    ...
      memcpy (a, "01234567890123456789", 20);
    then we take an earlier if for the INTEGER_CST case and set correctly
    just pdata->minlen to 20 in that case, but if we have something like
      int len;
      ...
      if (len < 15 || len > 32) return;
      memcpy (a, "0123456789012345678901234567890123456789", len);
    then we have [15, 32] range for the nonzero_chars and we set pdata->minlen
    correctly to 15, but incorrectly set also pdata->maxlen to 32.  That is
    not what the above implies, it just means that in some cases we know that
    there are at least 32 non-zero characters, followed by something we don't
    know.  There is no guarantee that there is '\0' right after it, so it
    means nothing.
    The reason this is harmless, just confusing, is that the code a few lines
    later fortunately overwrites this incorrect pdata->maxlen value with
    something different (either array length - 1 or all ones etc.).

    2024-01-29  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/110603
            * tree-ssa-strlen.cc (get_range_strlen_dynamic): Remove incorrect
            setting of pdata->maxlen to vr.upper_bound (which is
unconditionally
            overwritten anyway).  Avoid creating invalid range with minlen
            larger than maxlen.  Formatting fix.

            * gcc.c-torture/compile/pr110603.c: New test.

  parent reply	other threads:[~2024-01-29  9:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-09 11:34 [Bug c/110603] New: GCC, ICE: internal compiler error: in verify_range, at value-range.cc:1104 141242068 at smail dot nju.edu.cn
2023-07-09 14:57 ` [Bug tree-optimization/110603] [14 Regression] " pinskia at gcc dot gnu.org
2023-07-10  6:36 ` rguenth at gcc dot gnu.org
2023-10-17 12:10 ` rguenth at gcc dot gnu.org
2024-01-02 20:39 ` doko at gcc dot gnu.org
2024-01-09 18:06 ` [Bug tree-optimization/110603] [14 Regression] GCC, ICE: internal compiler error: in verify_range, at value-range.cc:1104 since r14-255 jakub at gcc dot gnu.org
2024-01-10 10:31 ` aldyh at gcc dot gnu.org
2024-01-23 11:16 ` jakub at gcc dot gnu.org
2024-01-27 12:48 ` jakub at gcc dot gnu.org
2024-01-29  9:21 ` cvs-commit at gcc dot gnu.org [this message]
2024-01-29  9:30 ` jakub at gcc dot gnu.org

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-110603-4-qgCecrCpKI@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).