[Bug middle-end/104550] bogus warning from -Wuninitialized + -ftrivial-auto-var-init=pattern

qinzhao at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Feb 15 21:33:20 GMT 2022


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

--- Comment #3 from qinzhao at gcc dot gnu.org ---
the root cause for this bug is due to the new call to __builtin_clear_padding 
added by -ftrivial-auto-var-init=pattern, this is treated as a use of the
uninitialized variable during early uninitialized analysis phase, in which
phase DCE hasn't been applied yet, as a result, the early uninit phase reported
this uninitialized usage. 

the following is the details:

1. without -ftrivial-auto-var-init, the IR in gimple stage is:
void vx_set_monitor_level ()
{ 
  struct vx_audio_level info;

  try
    {

    }
  finally
    {
      info = {CLOBBER(eol)};
    }
}

no any usage of the auto var "info", no any warning message for
-Wuninitialized;

2. With -ftrivial-auto-var-init, the IR in gimple stage is:
void vx_set_monitor_level ()
{ 
  struct vx_audio_level info;

  try
    {
      info = .DEFERRED_INIT (4, 1, &"info"[0]);
      __builtin_clear_padding (&info, 1B);
    }
  finally
    {
      info = {CLOBBER(eol)};
    }
}

then after folding of call to "__builtin_clear_padding", the IR at early
uninitialized analysis phase is:

void vx_set_monitor_level ()
{
  struct vx_audio_level info;
  int _1;
  int _2;

  <bb 2> :
  info = .DEFERRED_INIT (4, 1, &"info"[0]);
  _1 = MEM[(struct vx_audio_level *)&info];
  _2 = _1 & 1;
  MEM[(struct vx_audio_level *)&info] = _2;
  info ={v} {CLOBBER(eol)};
  return;

}

The bogus warning is issued for the following fake usage:

 _1 = MEM[(struct vx_audio_level *)&info];

which is unavoidable during the early uninitialized stage based on the current
IR info.


More information about the Gcc-bugs mailing list