GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 35609 - [4.3 Regression] "is used uninitialized in this function" should be may warning
Summary: [4.3 Regression] "is used uninitialized in this function" should be may warning
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.3.0
: P4 enhancement
Target Milestone: 4.3.1
Assignee: Richard Biener
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2008-03-16 21:19 UTC by Adrian Bunk
Modified: 2008-03-25 10:09 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.2.3 4.4.0 4.3.1
Known to fail: 4.3.0
Last reconfirmed: 2008-03-18 16:53:41


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Bunk 2008-03-16 21:19:02 UTC
<--  snip  -->

$ cat test.c
int foo, bar;

void decode_reloc(int reloc, int *is_alt)
{
  if (reloc >= 20)
      *is_alt = 1;
  else if (reloc >= 10)
      *is_alt = 0;
}

void testfunc()
{
  int alt_reloc;

  decode_reloc(foo, &alt_reloc);

  if (alt_reloc)
    bar = 42;
}
$ gcc -O2 -Wall -c test.c
test.c: In function ‘testfunc’:
test.c:17: warning: ‘alt_reloc’ is used uninitialized in this function
$ 

<--  snip  -->

A "may be used uninitialized in this function" warning might be appropriate here, but gcc seems to wrongly think it can prove "alt_reloc" was for sure uninitialized here.
Comment 1 Andrew Pinski 2008-03-16 21:30:09 UTC
So Jump threading comes along and threads the jump for some reason makes the PHI node go away.
Comment 2 Richard Biener 2008-03-16 21:32:31 UTC
The warning works as designed, the PHI node in question that causes the
warning only has a single incoming edge:

testfunc ()
{
  int alt_reloc;
  int foo.0;

<bb 2>:
  foo.0_1 = foo;
  if (foo.0_1 > 19)
    goto <bb 5>;
  else
    goto <bb 3>;

<bb 3>:
  if (foo.0_1 > 9)
    goto <bb 6>;
  else
    goto <bb 4>;

<bb 4>:
  if (alt_reloc_4(D) != 0)
    goto <bb 5>;
  else
    goto <bb 6>;

<bb 5>:
  bar = 42;

<bb 6>:
  return;

}

we don't check whether the uninitialized use post-dominates the function
entry.  I don't know if we should.

This is just a case of 4.3 optimizing better than 4.2 which makes the
warning less precise.
Comment 3 Richard Biener 2008-03-18 16:53:41 UTC
While this is a regression the underlying problem was latent and thus this
should be an enhacement report.  But I'll have a look.
Comment 4 Richard Biener 2008-03-19 10:45:36 UTC
Subject: Bug 35609

Author: rguenth
Date: Wed Mar 19 10:44:52 2008
New Revision: 133341

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133341
Log:
2008-03-19  Richard Guenther  <rguenther@suse.de>

	PR middle-end/35609
	* tree-ssa.c (always_executed): New global flag.
	(warn_uninitialized_var): If !always_executed warn with "maybe"
	instead of "is".
	(execute_early_warn_uninitialized): Compute post-dominators.
	Initialize always_executed before processing each basic block.

	* gcc.dg/testsuite/uninit-15.c: New testcase.
	* gcc.dg/testsuite/uninit-16.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.dg/uninit-15.c
    trunk/gcc/testsuite/gcc.dg/uninit-16.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa.c

Comment 5 Richard Biener 2008-03-19 10:45:55 UTC
Fixed on the trunk.
Comment 6 Richard Biener 2008-03-25 10:09:43 UTC
And on the branch.
Comment 7 Richard Biener 2008-03-25 10:10:13 UTC
Subject: Bug 35609

Author: rguenth
Date: Tue Mar 25 10:09:22 2008
New Revision: 133507

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133507
Log:
2008-03-25  Richard Guenther  <rguenther@suse.de>

        Backport from mainline:
        2008-03-19  Richard Guenther  <rguenther@suse.de>

        PR middle-end/35609
        * tree-ssa.c (walk_data): New structure.
        (warn_uninitialized_var): If not always_executed warn with "maybe"
        instead of "is".
        (execute_early_warn_uninitialized): Compute post-dominators.
        Initialize always_executed before processing each basic block.

        * gcc.dg/testsuite/uninit-15.c: New testcase.
        * gcc.dg/testsuite/uninit-16.c: Likewise.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/uninit-15.c
      - copied unchanged from r133341, trunk/gcc/testsuite/gcc.dg/uninit-15.c
    branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/uninit-16.c
      - copied unchanged from r133341, trunk/gcc/testsuite/gcc.dg/uninit-16.c
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_3-branch/gcc/tree-ssa.c