public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/105562] std::function<bool(char)>::_M_invoker may be used uninitialized in std::regex move with -fno-strict-aliasing
Date: Thu, 12 May 2022 09:27:52 +0000	[thread overview]
Message-ID: <bug-105562-4-qpKXOAgtwq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-105562-4@http.gcc.gnu.org/bugzilla/>

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
>From what I can see, the warning is on dead code.
  <bb 2> [local count: 1073741824]:
  MEM[(struct _State_base *)&__tmp] ={v} {CLOBBER};
  MEM[(struct _State_base *)&__tmp]._M_opcode = 9;
  MEM[(struct _State_base *)&__tmp]._M_next = -1;
  _12 = MEM[(long unsigned int * const &)this_3(D) + 8];
  _1 = MEM[(value_type &)_12 + 18446744073709551608];
  __tmp.D.93077.D.69952._M_subexpr = _1;
  _11 = _12 + 18446744073709551608;
  MEM[(struct vector *)this_3(D)].D.71153._M_impl.D.70460._M_finish = _11;
  MEM[(struct _State *)&D.93141] ={v} {CLOBBER};
  MEM[(struct _State *)&D.93141].D.93077 = MEM[(struct _State
&)&__tmp].D.93077;
  _43 = MEM[(const struct _State *)&__tmp].D.93077._M_opcode;
  if (_43 == 11)
    goto <bb 3>; [34.00%]
  else
    goto <bb 23>; [66.00%]

  <bb 23> [local count: 708669600]:
  goto <bb 5>; [100.00%]

  <bb 3> [local count: 365072224]:
  MEM[(struct function *)&D.93141 + 16B] ={v} {CLOBBER};
  MEM[(struct function *)&D.93141 + 16B].D.69910 = {};
  _44 = MEM[(struct function &)&__tmp + 16]._M_invoker;
  MEM[(struct function *)&D.93141 + 16B]._M_invoker = _44;

__tmp has:
  struct _State_base
  {
  protected:
    _Opcode      _M_opcode;           // type of outgoing transition

  public:
    _StateIdT    _M_next;             // outgoing transition
    union // Since they are mutually exclusive.
    {
      size_t _M_subexpr;        // for _S_opcode_subexpr_*
      size_t _M_backref_index;  // for _S_opcode_backref
      struct
      {
        // for _S_opcode_alternative, _S_opcode_repeat and
        // _S_opcode_subexpr_lookahead
        _StateIdT  _M_alt;
        // for _S_opcode_word_boundary or _S_opcode_subexpr_lookahead or
        // quantifiers (ungreedy if set true)
        bool       _M_neg;
      };
      // For _S_opcode_match
      __gnu_cxx::__aligned_membuf<_Matcher<char>> _M_matcher_storage;
    };
type where _StateIdT is some pointer and _M_matcher_storage is 32 bytes large,
the union is at offset 16.
Now, bb 2 initializes it to be _M_opcode 9 (aka _S_opcode_subexpr_end) with the
_M_subexpr as active
union field (so everything but the first 8 bytes of the union are
uninitialized).
But at the end of the bb we test _M_opcode against 11 (aka _S_opcode_match) and
if it is that
value, we extract std::function's _M_invoker (which is a pointer at offset 16
bytes into the union).
So obviously it is uninitialized but dead.
At -O1 we don't do PRE, but I wonder why fre3 doesn't optimize this.
  <bb 2> [local count: 1073741824]:
  MEM[(struct _State_base *)&__tmp] ={v} {CLOBBER};
  MEM[(struct _State_base *)&__tmp]._M_opcode = 9;
  MEM[(struct _State_base *)&__tmp]._M_next = -1;
  _12 = MEM[(long unsigned int * const &)this_3(D) + 8];
  _1 = MEM[(value_type &)_12 + 18446744073709551608];
  __tmp.D.93077.D.69952._M_subexpr = _1;
  _11 = _12 + 18446744073709551608;
  MEM[(struct vector *)this_3(D)].D.71153._M_impl.D.70460._M_finish = _11;
  MEM[(long unsigned int *)_12 + -8B] ={v} {CLOBBER};
  MEM[(struct _State *)&D.93141] ={v} {CLOBBER};
  MEM[(struct _State *)&D.93141].D.93077 = MEM[(struct _State
&)&__tmp].D.93077;
  _43 = MEM[(const struct _State *)&__tmp].D.93077._M_opcode;
  if (_43 == 11)
there are 3 stores into __tmp, one to offset 0 4 bytes _M_opcode = 9, one to
offset 8 8 bytes _M_next = -1 and one to offset 16 8 bytes _M_subexpr = _1,
it doesn't seem like other stores could alias with that, so why don't we
optimize _43 = 9; ?

  parent reply	other threads:[~2022-05-12  9:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-11 10:48 [Bug libstdc++/105562] New: [12 Regression] std::function<bool(char)>::_M_invoker may be used uninitialized in std:regex " andrey.vihrov at gmail dot com
2022-05-11 10:55 ` [Bug libstdc++/105562] [12/13 Regression] std::function<bool(char)>::_M_invoker may be used uninitialized in std::regex move with -fno-strict-aliasing since r12-6216-g5a431b60d1f22199 marxin at gcc dot gnu.org
2022-05-11 11:05 ` rguenth at gcc dot gnu.org
2022-05-11 11:32 ` andrey.vihrov at gmail dot com
2022-05-11 11:54 ` redi at gcc dot gnu.org
2022-05-11 12:44 ` [Bug libstdc++/105562] std::function<bool(char)>::_M_invoker may be used uninitialized in std::regex move with -fno-strict-aliasing redi at gcc dot gnu.org
2022-05-11 12:56 ` redi at gcc dot gnu.org
2022-05-11 12:57 ` redi at gcc dot gnu.org
2022-05-11 12:59 ` redi at gcc dot gnu.org
2022-05-12  9:27 ` jakub at gcc dot gnu.org [this message]
2022-05-12  9:35 ` jakub at gcc dot gnu.org
2022-05-12  9:54 ` rguenth at gcc dot gnu.org
2022-05-12  9:57 ` rguenth at gcc dot gnu.org
2022-05-12 10:07 ` rguenth at gcc dot gnu.org
2022-05-12 11:27 ` cvs-commit at gcc dot gnu.org
2022-05-12 11:28 ` [Bug libstdc++/105562] [12 Regression] " rguenth at gcc dot gnu.org
2022-05-19 12:47 ` cvs-commit at gcc dot gnu.org
2022-05-19 12:50 ` rguenth at gcc dot gnu.org
2022-10-22  0:50 ` pinskia at gcc dot gnu.org
2023-05-26 21:40 ` urisimchoni at gmail dot com
2023-09-12 12:04 ` jakub1miernik at gmail dot com
2023-12-06 10:03 ` romain.geissler at amadeus dot com
2023-12-06 10:26 ` rguenth at gcc dot gnu.org
2023-12-06 10:35 ` romain.geissler at amadeus dot com
2023-12-06 10:43 ` rguenther at suse dot de
2023-12-06 10:50 ` jakub at gcc dot gnu.org
2023-12-06 11:13 ` romain.geissler at amadeus dot com
2023-12-06 11:16 ` sjames 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-105562-4-qpKXOAgtwq@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).