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/99536] unexplained warning on "uninitialized value" in std::normal_distribution
Date: Wed, 07 Apr 2021 21:16:29 +0000	[thread overview]
Message-ID: <bug-99536-4-pXNQUho9O9@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-99536-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org
           Keywords|                            |missed-optimization
      Known to work|                            |10.2.0, 11.0
          Component|c++                         |tree-optimization

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
I can reconfirm the warning with GCC 9.  It's been suppressed in GCC 10 and 11.

GCC 10 sees the IL below (annotated with my comments).  The warning triggers
because it doesn't know how to interpret the VIEW_CONVERT_EXPR<bool>.  This
limitation has caused other false positives as well (including the one for
std::optional in pr80635.  I suggested handling VIEW_CONVERT_EXPR in the pass
in response to the patch submitted to fix that bug and I still think that that
would be a good solution, even if other optimizations are enhanced to handle it
as well.

main ()
{
  unsigned char norm_dist$24;
  double norm_dist$_M_saved;
  result_type __ret;
  result_type __x;
  result_type __y;
  result_type __r2;
  const result_type __mult;
  result_type D.47826;
  long unsigned int __res;
  int i;
  struct normal_distribution norm_dist;
  struct default_random_engine generator;
  bool _18;
  double _20;
  double _21;
  double _23;
  double _24;
  double powmult_26;
  double powmult_27;
  bool _29;
  bool _30;
  bool _31;
  double _32;
  double _33;
  double _34;
  double _36;
  unsigned int ivtmp_41;
  unsigned int ivtmp_51;

  <bb 2> [local count: 268435456]:
  MEM[(struct linear_congruential_engine *)&generator] ={v} {CLOBBER};
  generator._M_x = 1;
  MEM[(struct  &)&norm_dist] ={v} {CLOBBER};
  MEM[(struct param_type *)&norm_dist] ={v} {CLOBBER};

  <bb 3> [local count: 805306365]:
  # norm_dist$_M_saved_2 = PHI <norm_dist$_M_saved_43(D)(2),
norm_dist$_M_saved_1(9)>
  # norm_dist$24_14 = PHI <0(2), norm_dist$24_13(9)>   <<< zero when
norm_dist$_M_saved_2 is uninitialized
  # ivtmp_41 = PHI <3(2), ivtmp_51(9)>
  _18 = VIEW_CONVERT_EXPR<bool>(norm_dist$24_14);      <<< not handled by
warning code
  if (_18 != 0)
    goto <bb 11>; [50.00%]                             <<< norm_dist$_M_saved_2
= norm_dist$_M_saved_1(9)
  else
    goto <bb 8>; [50.00%]                              <<< norm_dist$_M_saved_2
is uninitialized

  <bb 11> [local count: 402653183]:
  goto <bb 6>; [100.00%]

  <bb 8> [local count: 402653183]:

  <bb 4> [local count: 3660483495]:
  _20 = std::generate_canonical<double, 53,
std::linear_congruential_engine<long unsigned int, 16807, 0, 2147483647> >
(&generator);
  _21 = _20 * 2.0e+0;
  __x_22 = _21 - 1.0e+0;
  _23 = std::generate_canonical<double, 53,
std::linear_congruential_engine<long unsigned int, 16807, 0, 2147483647> >
(&generator);
  _24 = _23 * 2.0e+0;
  __y_25 = _24 - 1.0e+0;
  powmult_26 = __x_22 * __x_22;
  powmult_27 = __y_25 * __y_25;
  __r2_28 = powmult_26 + powmult_27;
  _29 = __r2_28 <= 1.0e+0;
  _30 = __r2_28 != 0.0;
  _31 = _29 & _30;
  if (_31 != 0)
    goto <bb 5>; [11.00%]
  else
    goto <bb 10>; [89.00%]

  <bb 10> [local count: 3257830313]:
  goto <bb 4>; [100.00%]

  <bb 5> [local count: 402653182]:
  _32 = log (__r2_28);
  _33 = _32 * -2.0e+0;
  _34 = _33 / __r2_28;
  __mult_35 = sqrt (_34);
  _36 = __x_22 * __mult_35;
  __ret_37 = __y_25 * __mult_35;

  <bb 6> [local count: 805306365]:                     <<<
norm_dist$_M_saved_2(11) == norm_dist$_M_saved_1(9)
  # __ret_39 = PHI <__ret_37(5), norm_dist$_M_saved_2(11)>
  # norm_dist$_M_saved_1 = PHI <_36(5), norm_dist$_M_saved_2(11)>
  # norm_dist$24_13 = PHI <1(5), 0(11)>
  foo (__ret_39);                                      <<<
-Wmaybe-uninitialized
  ivtmp_51 = ivtmp_41 + 4294967295;
  if (ivtmp_51 == 0)
    goto <bb 7>; [25.00%]
  else
    goto <bb 9>; [75.00%]

  <bb 9> [local count: 603979774]:
  goto <bb 3>; [100.00%]

  <bb 7> [local count: 268435456]:
  generator ={v} {CLOBBER};
  norm_dist ={v} {CLOBBER};
  return 0;

}

  parent reply	other threads:[~2021-04-07 21:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11  1:36 [Bug c++/99536] New: unexplained warning on "uninitialized value" wuz73 at hotmail dot com
2021-03-11 13:30 ` [Bug c++/99536] unexplained warning on "uninitialized value" in std::normal_distribution redi at gcc dot gnu.org
2021-03-11 15:09 ` redi at gcc dot gnu.org
2021-03-11 17:53 ` cvs-commit at gcc dot gnu.org
2021-03-11 18:18 ` redi at gcc dot gnu.org
2021-03-29 20:03 ` cvs-commit at gcc dot gnu.org
2021-03-29 21:37 ` redi at gcc dot gnu.org
2021-04-07 21:16 ` msebor at gcc dot gnu.org [this message]
2021-04-07 21:18 ` [Bug tree-optimization/99536] " msebor at gcc dot gnu.org
2021-04-20 18:52 ` cvs-commit at gcc dot gnu.org
2022-08-06  2:57 ` wuz73 at hotmail dot com

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-99536-4-pXNQUho9O9@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).