Bug 52523 - Missing "uninitialized" warning (VOP, taking address of var)
Summary: Missing "uninitialized" warning (VOP, taking address of var)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 11.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2012-03-07 20:21 UTC by Andrea Corradi
Modified: 2021-03-25 22:29 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 10.2.0, 4.7.0, 4.8.4, 4.9.4, 5.5.0, 6.4.0, 7.2.0, 8.3.0, 9.1.0
Last reconfirmed: 2012-03-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrea Corradi 2012-03-07 20:21:12 UTC
Compiling this code:

#include <iostream>
int main()
{
  int x;
  std::cout << x;
  std::cin >> x;
}

with g++ -Wall uninitialized.cc
give no warning.

But compiling this code:

#include <iostream>
int main()
{
  int x;
  std::cout << x;
}

with g++ -Wall uninitialized.cc
gives:
uninitialized.cc: In function ‘int main()’:
uninitialized.cc:6:17: warning: ‘x’ is used uninitialized in this function [-Wuninitialized

Tested also on version 4.6.1 and 4.6.2
Comment 1 Manuel López-Ibáñez 2012-03-08 00:05:22 UTC
The SSA dump is a bit obscure to me:

int main() ()
{
  int x;
  int D.21721;
  int x.0;

<bb 2>:
  [pr52523.cc : 5:17] x.0_1 = x;
  [pr52523.cc : 5:17] std::basic_ostream<char>::operator<< ([pr52523.cc : 5] &cout, x.0_1);

<bb 3>:
  [pr52523.cc : 6:16] std::basic_istream<char>::operator>> ([pr52523.cc : 6] &cin, &x);

<bb 4>:
  x ={v} {CLOBBER};
  [pr52523.cc : 7:1] D.21721_2 = 0;

<L0>:
  [pr52523.cc : 7:1] return D.21721_2;

<L1>:
  x ={v} {CLOBBER};
  resx 1

}

but I guess that 'std::cin >> x' creates a VOP, and the warning machinery does not work well with VOPs. See PR19430.
Comment 2 Martin Sebor 2021-03-25 22:29:32 UTC
GCC 11 (since g:b825a22890740f341eae566af27e18e528cd29a7) diagnoses passing an
uninitialized object by const reference by -Wmaybe-uninitialized:

$ g++ -S -Wall pr52523.C
pr52523.C: In function ‘int main()’:
pr52523.C:6:13: warning: ‘x’ is used uninitialized [-Wuninitialized]
    6 |   std::cout << x;
      |   ~~~~~~~~~~^~~~
pr52523.C:5:7: note: ‘x’ declared here
    5 |   int x;
      |       ^