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 tree-optimization/103332] [12 Regression] Spurious -Wstringop-overflow on string concatenation in libstdc++ tests
Date: Wed, 08 Dec 2021 23:30:42 +0000	[thread overview]
Message-ID: <bug-103332-4-wFlL5qdIfl@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103332-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=103534
            Summary|Spurious                    |[12 Regression] Spurious
                   |-Wstringop-overflow         |-Wstringop-overflow on
                   |warnings in libstdc++ tests |string concatenation in
                   |                            |libstdc++ tests
      Known to fail|                            |12.0

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
The first warning is for the invalid memcpy() call below:

  struct string D.35215;
  ...
  <bb 3> [local count: 1073312331]:
  D.35215._M_string_length = 16;
  _62 = D.35215._M_dataplus._M_p;
  MEM[(char_type &)_62 + 16] = 0;
  D.35222 ={v} {CLOBBER};
  MEM[(struct _Alloc_hider *)&D.35222] ={v} {CLOBBER};
  MEM[(struct _Alloc_hider *)&D.35222]._M_p = &D.35222.D.28102._M_local_buf;
  if (&MEM <const char[16]> [(void *)&D.35215 + 16B] == _62)
    goto <bb 4>; [30.00%]
  else
    goto <bb 5>; [70.00%]

  <bb 4> [local count: 157390518]:
  __builtin_memcpy (&D.35222.D.28102._M_local_buf, &MEM <const char[16]> [(void
*)&D.35215 + 16B], 17);
  goto <bb 6>; [100.00%]

sizeof std::string::_M_local_buf is 16 but the call writes 17 bytes into it, so
the call is invalid.

I only see the warning at -O1 (and with -D_GLIBCXX_DEBUG).  It also goes away
if I force std::string::_M_mutate to be inlined.  _M_mutate allocates the
dynamic string so with it inlined GCC can determine that the local buffer is no
longer used and eliminate the invalid call.  So as in the other cases we have
seen recently, this false positive is due to some optimizer limitations caused
by the combination of -O1 and a decision to throttle inlining.  The second
warning is due to the same issue.  It too goes away with more aggressive
inlining (on x86_64 setting -finline-limit=200 avoids it).

  parent reply	other threads:[~2021-12-08 23:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19 15:52 [Bug tree-optimization/103332] New: Spurious -Wstringop-overflow warnings " redi at gcc dot gnu.org
2021-11-19 16:03 ` [Bug tree-optimization/103332] " msebor at gcc dot gnu.org
2021-11-19 17:59 ` redi at gcc dot gnu.org
2021-11-19 18:16 ` cvs-commit at gcc dot gnu.org
2021-11-25 19:22 ` pinskia at gcc dot gnu.org
2021-12-08 23:30 ` msebor at gcc dot gnu.org [this message]
2021-12-09 23:24 ` [Bug tree-optimization/103332] [12 Regression] Spurious -Wstringop-overflow on string concatenation " cvs-commit at gcc dot gnu.org
2021-12-13 16:11 ` jason 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-103332-4-wFlL5qdIfl@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).