Bug 44133

Summary: [4.5 Regression] Uninit warning regression with new SRA
Product: gcc Reporter: Jakub Jelinek <jakub>
Component: middle-endAssignee: Martin Jambor <jamborm>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, manu
Priority: P2 Keywords: diagnostic
Version: 4.5.0   
Target Milestone: 4.5.1   
Host: Target:
Build: Known to work: 4.6.0
Known to fail: Last reconfirmed: 2010-05-14 09:47:27
Bug Depends on:    
Bug Blocks: 24639    

Description Jakub Jelinek 2010-05-14 09:01:49 UTC
struct S { int i, j; };

int foo (int l)
{
  struct S s;
  s.j = l - 22;
  return s.i + s.j;
}

with -O2 -W -Wall in 4.4 this used to warn:
v.c: In function 'foo':
v.c:6: warning: 's.i' is used uninitialized in this function
but with 4.5+ it warns:
v.c: In function 'foo':
v.c:6:11: warning: '({anonymous})' is used uninitialized in this function [-Wuninitialized]

For:
struct S { int i, j; };

int foo (int l)
{
  struct S s;
  if (l > 126)
    {
      s.j = l - 22;
      return s.i + s.j;
    }
  s.i = 12;
  s.j = l + 40;
  return s.i + s.j;
}
the warning is ok in both 4.4 and 4.5+.

I'd say that SRA should add the D.XXXX = s$i; stmts, perhaps right before
D.XXXX uses.
Comment 1 Martin Jambor 2010-05-14 09:47:27 UTC
Mine.
Comment 2 Martin Jambor 2010-05-16 21:09:51 UTC
Patch posted to the mailing list:
http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01209.html
Comment 3 Martin Jambor 2010-05-17 12:48:58 UTC
Subject: Bug 44133

Author: jamborm
Date: Mon May 17 12:48:34 2010
New Revision: 159482

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159482
Log:
2010-05-17  Martin Jambor  <mjambor@suse.cz>

	PR middle-end/44133
	* tree-sra.c (create_access_replacement): New parameter rename, mark
	the replaement for renaming only when it is true.
	(get_access_replacement): Pass true in the rename parameter of
	create_access_replacement.
	(get_unrenamed_access_replacement): New function.
	(replace_uses_with_default_def_ssa_name): New parameter racc, get the
	replacement declaration from it.

	* testsuite/gcc.dg/tree-ssa/pr44133.c: New test.
	* testsuite/gcc.dg/tree-ssa/sra-9.c: Make the scan regular
	expression more precise.


Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr44133.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/tree-ssa/sra-9.c
    trunk/gcc/tree-sra.c

Comment 4 Martin Jambor 2010-05-21 17:36:53 UTC
On the 4.5 branch we have a different problem, the warning is not
issued at all.  The patch does not apply because we treat scalar loads
differently.  The easiest way would be to backport this behavior to
4.5:

http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00440.html

and then commit this change on top of it.  That would of course change
the code generated by SRA in general but it does not seem too risky
now.  What do you think?
Comment 5 Martin Jambor 2010-06-17 13:14:04 UTC
A request for approval to backport the two patches sent to the mailing list:
http://gcc.gnu.org/ml/gcc-patches/2010-06/msg01663.html
Comment 6 Martin Jambor 2010-06-29 13:09:00 UTC
Subject: Bug 44133

Author: jamborm
Date: Tue Jun 29 13:08:46 2010
New Revision: 161532

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161532
Log:
2010-06-29  Martin Jambor  <mjambor@suse.cz>

	Backport from mainline
	2010-05-17  Martin Jambor  <mjambor@suse.cz>

        PR middle-end/44133
        * tree-sra.c (create_access_replacement): New parameter rename, mark
        the replaement for renaming only when it is true.
        (get_access_replacement): Pass true in the rename parameter of
        create_access_replacement.
        (get_unrenamed_access_replacement): New function.
        (replace_uses_with_default_def_ssa_name): New parameter racc, get the
        replacement declaration from it.

        * testsuite/gcc.dg/tree-ssa/pr44133.c: New test.


Added:
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/tree-ssa/pr44133.c
Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_5-branch/gcc/tree-sra.c

Comment 7 Martin Jambor 2010-06-29 13:10:46 UTC
This is now fixed on both the trunk and the 4.5 branch.