Patchwork Fix PR39799: missing uninitialized vars warning

login
register
mail settings
Submitter Bernd Schmidt
Date June 30, 2010, 9:15 a.m.
Message ID <4C2B0B37.70209@codesourcery.com>
Download mbox | patch
Permalink /patch/57388/
State New
Headers show

Comments

Bernd Schmidt - June 30, 2010, 9:15 a.m.
This is a problem that was introduced with the fix for PR31081.  Looking
at that PR's history, it seems the inliner has problems with overlapping
lifetimes for things where SSA_NAME_OCCURS_IN_ABNORMAL_PHI.

The solution was to zero-initialize all uninitialized variables when
inlining.  This disables warnings for them, which is the regression in
PR39799.

I've bootstrapped and regression tested the patch below on i686-linux.
This limits the zero-initialization to variables with
SSA_NAME_OCCURS_IN_ABNORMAL_PHI.  I doubt register pressure is an issue
since we have another rtl-based init-regs pass.  Ok?


Bernd
PR tree-optimization/39799
	* tree-inline.c (remap_ssa_name): Initialize variable only if
	SSA_NAME_OCCURS_IN_ABNORMAL_PHI.

	PR tree-optimization/39799
	* gcc.dg/uninit-17.c: New test.
Manuel López-Ibáñez - June 30, 2010, 9:26 a.m.
On 30 June 2010 11:15, Bernd Schmidt <bernds@codesourcery.com> wrote:
> This is a problem that was introduced with the fix for PR31081.  Looking
> at that PR's history, it seems the inliner has problems with overlapping
> lifetimes for things where SSA_NAME_OCCURS_IN_ABNORMAL_PHI.
>
> The solution was to zero-initialize all uninitialized variables when
> inlining.  This disables warnings for them, which is the regression in
> PR39799.
>
> I've bootstrapped and regression tested the patch below on i686-linux.
> This limits the zero-initialization to variables with
> SSA_NAME_OCCURS_IN_ABNORMAL_PHI.  I doubt register pressure is an issue
> since we have another rtl-based init-regs pass.  Ok?

+/* { dg-message "note: '\[^\n'\]*' was declared here" "note:
expected" { target *-*-* } 0 } */

Why not put this in the proper line?

Does this work at -O{0,1,3,fast,s}? If so, why not put it in torture
tests? Otherwise, I would still suggest to put it in c-c++-common.

Manuel.
Bernd Schmidt - June 30, 2010, 9:38 a.m.
On 06/30/2010 11:26 AM, Manuel López-Ibáñez wrote:

> +/* { dg-message "note: '\[^\n'\]*' was declared here" "note:
> expected" { target *-*-* } 0 } */
> 
> Why not put this in the proper line?

I was looking at vla-8.c where it's also done this way.  Also, seemed
more readable.

> Does this work at -O{0,1,3,fast,s}? If so, why not put it in torture
> tests?

We don't warn without optimization.

>  Otherwise, I would still suggest to put it in c-c++-common.

Could do that I guess.


Bernd
Manuel López-Ibáñez - June 30, 2010, 10 a.m.
On 30 June 2010 11:38, Bernd Schmidt <bernds@codesourcery.com> wrote:
> On 06/30/2010 11:26 AM, Manuel López-Ibáńez wrote:
>
>> +/* { dg-message "note: '\[^\n'\]*' was declared here" "note:
>> expected" { target *-*-* } 0 } */
>>
>> Why not put this in the proper line?
>
> I was looking at vla-8.c where it's also done this way.  Also, seemed
> more readable.

Past practice is not always a good quality indicator in GCC, specially
in the testsuite.

You can also specify the correct line number instead of 0. Don't need
to move it. But I cannot see how

/* { dg-message "note: '\[^\n'\]*' was declared here" "note: expected"
{ target *-*-* } 0 } */

is more readable than

/* { dg-message "note: 'b' was declared here" } */

which tests both the correct location and that we do not generate
'temp.b1' instead of the proper name.

Cheers,

Manuel.
Richard Guenther - June 30, 2010, 10:14 a.m.
On Wed, Jun 30, 2010 at 11:15 AM, Bernd Schmidt <bernds@codesourcery.com> wrote:
> This is a problem that was introduced with the fix for PR31081.  Looking
> at that PR's history, it seems the inliner has problems with overlapping
> lifetimes for things where SSA_NAME_OCCURS_IN_ABNORMAL_PHI.
>
> The solution was to zero-initialize all uninitialized variables when
> inlining.  This disables warnings for them, which is the regression in
> PR39799.
>
> I've bootstrapped and regression tested the patch below on i686-linux.
> This limits the zero-initialization to variables with
> SSA_NAME_OCCURS_IN_ABNORMAL_PHI.  I doubt register pressure is an issue
> since we have another rtl-based init-regs pass.  Ok?

Ok if you sorted out the testsuite issues with Manuel.

Richard.
>
> Bernd
>

Patch

Index: tree-inline.c
===================================================================
--- tree-inline.c	(revision 161371)
+++ tree-inline.c	(working copy)
@@ -234,6 +234,7 @@  remap_ssa_name (tree name, copy_body_dat
 	     regions of the CFG, but this is expensive to test.  */
 	  if (id->entry_bb
 	      && is_gimple_reg (SSA_NAME_VAR (name))
+	      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name)
 	      && TREE_CODE (SSA_NAME_VAR (name)) != PARM_DECL
 	      && (id->entry_bb != EDGE_SUCC (ENTRY_BLOCK_PTR, 0)->dest
 		  || EDGE_COUNT (id->entry_bb->preds) != 1))
Index: testsuite/gcc.dg/uninit-17.c
===================================================================
--- testsuite/gcc.dg/uninit-17.c	(revision 0)
+++ testsuite/gcc.dg/uninit-17.c	(revision 0)
@@ -0,0 +1,26 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized" } */
+
+inline int foo(int x)
+{
+  return x;
+}
+static void bar(int a, int *ptr)
+{
+  do
+  {
+    int b;
+    if (b < 40) {
+      ptr[0] = b; /* { dg-warning "may be used uninitialized" } */
+    }
+    b += 1;
+    ptr++;
+  }
+  while (--a != 0);
+}
+void foobar(int a, int *ptr)
+{
+  bar(foo(a), ptr);
+}
+
+/* { dg-message "note: '\[^\n'\]*' was declared here" "note: expected" { target *-*-* } 0 } */