Bug 40943 - [4.4/4.5 Regression] Uninitialized warning is missed when dereferencing uninitialized pointers
Summary: [4.4/4.5 Regression] Uninitialized warning is missed when dereferencing unini...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: 4.4.2
Assignee: Jakub Jelinek
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2009-08-02 19:34 UTC by mikulas
Modified: 2009-08-03 19:32 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.3.3
Known to fail: 4.4.1 4.5.0
Last reconfirmed: 2009-08-03 16:22:45


Attachments
gcc45-pr40943.patch (436 bytes, patch)
2009-08-03 13:41 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mikulas 2009-08-02 19:34:24 UTC
Hi

This is a simple example that should warn about uninitialized variable, but doesn't. Compile with -O2 -Wall:

void a(void)
{
        int *p1;
        *p1 = 3;
}

gcc-4.3 warned correctly in this case.
Comment 1 Richard Biener 2009-08-02 21:42:09 UTC
Confirmed.  I see no technical reason for this.
Comment 2 Jakub Jelinek 2009-08-03 13:10:32 UTC
Broken by Manu's PR179 changes:
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139347
Comment 3 Jakub Jelinek 2009-08-03 13:41:20 UTC
Created attachment 18289 [details]
gcc45-pr40943.patch

Untested fix.  It breaks uninit-6*.c again though, but "fixing" this kind of false positive by simply disabling uninitialized warnings for all pointer dereferences on LHS is IMHO too big hammer.
Comment 4 Richard Biener 2009-08-03 13:44:45 UTC
Since the alias-improvements branch merge uninitialized warnings for aggregates
are seriously broken implementation wise anyway.
Comment 5 Manuel López-Ibáñez 2009-08-03 14:07:09 UTC
(In reply to comment #3)
> Created an attachment (id=18289) [edit]
> gcc45-pr40943.patch
> 
> Untested fix.  It breaks uninit-6*.c again though, but "fixing" this kind of
> false positive by simply disabling uninitialized warnings for all pointer
> dereferences on LHS is IMHO too big hammer.
> 

I was testing the exactly same patch, you posted first, so the honor is yours. :-)

Notice that you should not need -O2 for testing this. The testcase should work even with -O0.

Notice that uninit-6 is a missed optimization. Even with -O2, the unreachable use of field is still present in the code shown by uninit-6-O0.c.136t.optimized, so it seems the tree optimizers do not handle this case. My patch only hide the symptom (the warning) but the missed optimization was still there so we could xfail it again.
Comment 6 Jakub Jelinek 2009-08-03 19:26:24 UTC
Subject: Bug 40943

Author: jakub
Date: Mon Aug  3 19:26:10 2009
New Revision: 150379

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=150379
Log:
	PR middle-end/40943
	* tree-ssa.c (warn_uninitialized_var): Even on LHS warn for
	operand of INDIRECT_REF.

	* gcc.dg/uninit-6.c: Re-add XFAIL.
	* gcc.dg/uninit-6-O0.c: Likewise.
	* gcc.dg/uninit-pr40943.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/uninit-pr40943.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/uninit-6-O0.c
    trunk/gcc/testsuite/gcc.dg/uninit-6.c
    trunk/gcc/tree-ssa.c

Comment 7 Jakub Jelinek 2009-08-03 19:27:47 UTC
Subject: Bug 40943

Author: jakub
Date: Mon Aug  3 19:27:32 2009
New Revision: 150380

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=150380
Log:
	PR middle-end/40943
	* tree-ssa.c (warn_uninitialized_var): Even on LHS warn for
	operand of INDIRECT_REF.

	* gcc.dg/uninit-6.c: Re-add XFAIL.
	* gcc.dg/uninit-6-O0.c: Likewise.
	* gcc.dg/uninit-pr40943.c: New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/uninit-pr40943.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/uninit-6-O0.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/uninit-6.c
    branches/gcc-4_4-branch/gcc/tree-ssa.c

Comment 8 Jakub Jelinek 2009-08-03 19:32:10 UTC
Fixed.