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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning looks valid to me:

template <class> struct q {
  int r() { return ah; }
  int ah;
  q(int) {}          <<< ctor doesn't initialize ah
};
class s : q<int>, q<k> {
public:
  template <class an, class ao> s(an, ao) : q<int>(0), q<k>(ao()) {}
  int t() { return q<int>(*this).r(); }
};
template <class> class ar {
public:
  s at;
  ar() noexcept(i::aa);
  ~ar();
};
template <class e> ar<e>::ar() noexcept(i::aa) : at(nullptr, int()) {}
template <class e> ar<e>::~ar() {
  long o = at.t();   <<< o is a copy of an uninitialized member
  j(o);              <<< -Wuninitialized
}


$ gcc -O2 -S -Wall -fPIC -fdump-tree-uninit=/dev/stdout pr10083.C

;; Function j (_Z1jl, funcdef_no=0, decl_uid=2392, cgraph_uid=1,
symbol_order=0)

void j (long int D.2391)
{
  <bb 2> [local count: 1073741824]:
  return;

}


The -fdump-tree-uninit dump below shows the uninitialized read.  The reason why
the warning only appears with -fPIC is because the call to j() must be assumed
to be a superimposed definition of the function in some other DSO.  Otherwise
the call is inlined and the uninitialized read is eliminated along with
everything else.

If the test case has been reduced too much and doesn't accurately reflect the
actual problem then please reopen with a valid test case.

;; Function u::v (_ZN1u1vEv, funcdef_no=9, decl_uid=2624, cgraph_uid=10,
symbol_order=9)

In member function ‘int s::t()’,
    inlined from ‘ar< <template-parameter-1-1> >::~ar() [with
<template-parameter-1-1> = int]’ at pr10083.C:33:16,
    inlined from ‘l<int>::~l()’ at pr10083.C:36:31,
    inlined from ‘H::~H()’ at pr10083.C:45:8,
    inlined from ‘void u::v()’ at pr10083.C:52:21:
pr10083.C:23:20: warning: ‘<unnamed>.H::p.l<int,
c>::<unnamed>.ar<int>::at.s::<anonymous>.q<int>::ah’ is used uninitialized
[-Wuninitialized]
   23 |   int t() { return q<int>(*this).r(); }
      |                    ^~~~~~~~~~~~~
pr10083.C: In member function ‘void u::v()’:
pr10083.C:52:21: note: ‘<anonymous>’ declared here
   52 | void u::v() { au = {}; }
      |                     ^
void u::v (struct u * const this)
{
  long int o;
  int SR.2;
  struct H D.2731;

  <bb 2> [local count: 1073741824]:
  MEM[(struct q *)&D.2731] ={v} {CLOBBER};
  SR.2_3 = MEM[(struct s *)&D.2731].D.2477.ah;   <<< not initialized
  o_5 = (long int) SR.2_3;
  j (o_5);                                       <<< -Wuninitialized
  D.2731 ={v} {CLOBBER};
  D.2731 ={v} {CLOBBER};
  return;

}

Reply via email to