public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/104965] [11/12 Regression] Yet another -Warray-bounds false positive
Date: Thu, 17 Mar 2022 16:00:16 +0000	[thread overview]
Message-ID: <bug-104965-4-bk1V0QDbmP@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104965-4@http.gcc.gnu.org/bugzilla/>

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
It looks like an escape analysis limitation.  With this simpler test case using
different types to rule out aliasing assumptions:

#include <string>

int main()
{
  std::basic_string<short> s;
  auto p = new int[s.size ()]{ };
  char c = 0;
  if (s.size())
    c = *p;
  delete[] p;
  return c;
}

pr104965.C:9:9: warning: array subscript 0 is outside array bounds of ‘void
[0]’ [-Warray-bounds]
    9 |     c = *p;
      |         ^~
pr104965.C:6:34: note: object of size 0 allocated by ‘operator new []’
    6 |   auto p = new short[s.size ()]{ };
      |                                  ^

One of the stores to the local s escapes its address which is then assumed to
have been clobbered by operator new:

  <bb 2> [local count: 1073741824]:
  s ={v} {CLOBBER};
  MEM[(struct _Alloc_hider *)&s] ={v} {CLOBBER};
  MEM[(struct _Alloc_hider *)&s]._M_p = &s.D.33279._M_local_buf;
  s._M_string_length = 0;
  MEM[(char_type &)&s + 16] = 0;
  _5 = operator new [] (0);

  <bb 3> [local count: 1073741824]:
  _10 = s._M_string_length;
  if (_10 != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 4> [local count: 536870913]:
  _1 = MEM[(int *)_5];
  c_6 = (char) _1;

  parent reply	other threads:[~2022-03-17 16:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 12:15 [Bug middle-end/104965] New: " redi at gcc dot gnu.org
2022-03-17 12:52 ` [Bug middle-end/104965] [11/12 Regression] " rguenth at gcc dot gnu.org
2022-03-17 13:47 ` redi at gcc dot gnu.org
2022-03-17 16:00 ` msebor at gcc dot gnu.org [this message]
2022-03-17 23:46 ` pinskia at gcc dot gnu.org
2022-04-21  7:51 ` rguenth at gcc dot gnu.org
2022-07-26 12:41 ` [Bug middle-end/104965] [11/12/13 " rguenth at gcc dot gnu.org
2022-07-26 12:41 ` rguenth at gcc dot gnu.org
2022-07-26 13:59 ` redi at gcc dot gnu.org
2023-05-29 10:06 ` [Bug middle-end/104965] [11/12/13/14 " 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-104965-4-bk1V0QDbmP@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).