This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/78203] missing warning on return of unitialized variable


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

--- Comment #2 from fwd <fwd at quantentunnel dot de> ---
(In reply to Richard Biener from comment #1)
> There is a duplicate for this, we perform optimistic constant propagation
> which
> makes i == 1 and eliminates the conditional uninitialized use very early.

Well, with optimization -O2 the "optimistic constant propagation" is performed
and the return value is constant.
Nevertheless, I think the warning should be given, at least with '-Wpedantic'.
I wouldn't expect a constant there. If I had tests for this code, the tests
might become dependent on the optimization level.

If the constant value is exchanged by a variable of global scope, the warning
is given.
int e = 0;
int func1(const int x)
{
  int i;
  if (0 == x)
  {
    i = e;
  }
  return i;
}

In my opinion, the warning should be given because of "ambiguous" code, even
though "optimistic constant propagation" removes one branch of the conditional.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]