Bug 42561 - missing uninitialized variable warning on simple arrays
Summary: missing uninitialized variable warning on simple arrays
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
Reported: 2009-12-31 02:13 UTC by Matt Hargett
Modified: 2017-09-17 17:59 UTC (History)
3 users (show)

See Also:
Host: x86_64-linux-unknown
Target: x86_64-linux-unknown
Build: x86_64-linux-unknown
Known to work:
Known to fail:
Last reconfirmed:

source file (496 bytes, text/plain)
2009-12-31 02:15 UTC, Matt Hargett
slightly different example that eliminates heap dependency (472 bytes, text/plain)
2009-12-31 19:49 UTC, Matt Hargett

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Hargett 2009-12-31 02:13:12 UTC
in the attached testcase, both GCC 4.5.20091214 and GCC 4.4.1 on Ubuntu 9.10 miss the uninitialized use warnings specified in the comments. it does correct catch the simple byte variable base, as noted in the comments.
Comment 1 Matt Hargett 2009-12-31 02:15:37 UTC
Created attachment 19428 [details]
source file

to replicate (-O3 is required, would be nice if it just worked with -O2):
g++ -O3 -Wall -c gcc-missing-uninit.cpp
Comment 2 Andrew Pinski 2009-12-31 02:23:28 UTC
Well with:	int32_t actuallyRead = read(&v, SIZE_OF_BYTE);

And inlining turned on all the way, this:
	if (toRead < 1)

	memcpy(data, _totPtr, toRead);

Becomes just:
*_totPtr = *data;
which in turn becomes:
* _totPtr = v;

So the issue is more complex and GCC needs uninitialized warning for memcpy and arrays (and array SSA).

Most compilers don't implement array SSA really.  I Know of only two that do, Jikes VM (IBM's Java JIT compiler) and another one which I forget about but it is also a JIT IIRC.
Comment 3 Matt Hargett 2009-12-31 19:49:47 UTC
Created attachment 19432 [details]
slightly different example that eliminates heap dependency

to reproduce:
g++ -O3 -Wall gcc-missing-uninit.cpp

gives 1 warning

expected result:
should give 3 warnings, as noted in comments
Comment 4 Matt Hargett 2009-12-31 19:53:33 UTC
It seems like this analysis would succeed if the intrinsic memcpy for copying the [2] and [4] were inlined before this analysis. Is there a reason that the intrinsic version of memcpy isn't substituted in before this analysis is done? Am I missing something else?

What would be the implementation steps to fix this issue? 
Comment 5 Manuel López-Ibáñez 2010-02-24 13:31:01 UTC
(In reply to comment #4)
> What would be the implementation steps to fix this issue? 

1) Create a small self-contained testcase

2) Examine the dumps (-fdump-tree- options) and debug the compiler to know exactly why the warning is missing. Typical cases are common constant propagation, not enough alias information, not enough optimization, too much optimization, and bugs.

3) Propose a way to fix the above problem that does not regress on optimization.

4) Send a patch to gcc-patches (http://gcc.gnu.org/contribute.html)

5) Profit.

Any of those steps would help. Unfortunately, they have to be done in order.

Before confirming this, we would need to do (2), and we don't even have (1).
Comment 6 Richard Biener 2010-02-24 13:46:47 UTC
Note that uninitialized warnings on memory are severely limited by design.
It's not hard to improve that but it will be very costly in terms of compile-time.
Comment 7 Matt Hargett 2010-10-18 22:37:46 UTC
Re-tested on and the issue remains.