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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
The IL has

  <bb 2> [local count: 1073741824]:
  D.35417 = D.35181;
  [/home/rguenther/install/gcc-12/usr/local/include/c++/12.0.0/optional:737:17]
D.34833 ={v} {CLOBBER};
  [/home/rguenther/install/gcc-12/usr/local/include/c++/12.0.0/optional:237:14]
MEM[(union _Storage *)[t.C:26:20] &D.34833] ={v} {CLOBBER};
  [/home/rguenther/install/gcc-12/usr/local/include/c++/12.0.0/optional:118:7]
[/home/rguenther/install/gcc-12/usr/local/include/c++/12.0.0/optional:118:7]
MEM[(struct _Optional_payload_base *)[t.C:26:20] &D.34833]._M_engaged = 0;
  [t.C:26:20] D.35417 ={v} {CLOBBER};

I suspect we warn on the use of D.35181 which is indeed not initialized
(of std::nullopt_t type).  The copied to D.35417 is dead but at -Og we
fail to elide the store.  I see there's no DSE performed for -Og
possibly on purpose to not degrade debug info more.  But that makes
-Wuninitialized susceptible for these kind of issues.

Note at -O1 the same IL is in the program, it's just elided before we get
the chance to warn on it.  The uninit use there is even visible before
inlining but we don't seem to diagnose by value passing of uninitialized
aggregates:

int main ()
{
  struct B b;
  struct nullopt_t D.35181;
  const struct optional D.34833;
  int _8;

  <bb 2> :
  [t.C:26:20] std::optional<A>::optional ([t.C:26:20] &D.34833, D.35181);

here D.35181 is passed to the CTOR (where it might be eventually not
used so not warning at the call is eventually OK).  The copy itself
is emitted by the inliner, so it's spurious to warn there and the
inliner could either try harder to not emit it or alternatively
mark the copy as to be not warned about.

Reply via email to