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;

}

Reply via email to