Patchwork Fix PR39799: missing uninitialized vars warning

login
register
mail settings
Submitter Bernd Schmidt
Date June 30, 2010, 11:33 a.m.
Message ID <4C2B2B9E.1010005@codesourcery.com>
Download mbox | patch
Permalink /patch/57392/
State New
Headers show

Comments

Bernd Schmidt - June 30, 2010, 11:33 a.m.
On 06/30/2010 12:00 PM, Manuel López-Ibáñez wrote:

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

When I tried something like this initially I couldn't get it to work, so
I started looking at other testcases.  I've tried again now - how about
this version?


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
	* c-c++-common/uninit-17.c: New test.
Manuel López-Ibáñez - June 30, 2010, 11:38 a.m.
On 30 June 2010 13:33, Bernd Schmidt <bernds@codesourcery.com> wrote:
> On 06/30/2010 12:00 PM, Manuel López-Ibáñez wrote:
>
>> /* { dg-message "note: 'b' was declared here" } */
>
> When I tried something like this initially I couldn't get it to work, so
> I started looking at other testcases.  I've tried again now - how about
> this version?

I am not sure what the problem was, perhaps the quotes? If it works
now (it should), this version is OK.

Thanks,

Manuel.
Richard Henderson - June 30, 2010, 4:32 p.m.
> +    int b; /* { dg-message "note: 'b' was declared here" } */
> +    if (b < 40) {
> +      ptr[0] = b; /* { dg-warning "may be used uninitialized" } */
> +    }
> +    b += 1;

I'd be interested to know why the warning appears on the 
second use of the uninitialized variable and not the first.


r~
Richard Guenther - June 30, 2010, 4:56 p.m.
On Wed, Jun 30, 2010 at 6:32 PM, Richard Henderson <rth@redhat.com> wrote:
>> +    int b; /* { dg-message "note: 'b' was declared here" } */
>> +    if (b < 40) {
>> +      ptr[0] = b; /* { dg-warning "may be used uninitialized" } */
>> +    }
>> +    b += 1;
>
> I'd be interested to know why the warning appears on the
> second use of the uninitialized variable and not the first.

I bet the comparison is optimized away, only the store retained.

Richard.

>
> r~
>
H.J. Lu - July 1, 2010, 12:57 a.m.
On Wed, Jun 30, 2010 at 4:33 AM, Bernd Schmidt <bernds@codesourcery.com> wrote:
> On 06/30/2010 12:00 PM, Manuel López-Ibáñez wrote:
>
>> /* { dg-message "note: 'b' was declared here" } */
>
> When I tried something like this initially I couldn't get it to work, so
> I started looking at other testcases.  I've tried again now - how about
> this version?

The test failed with -m32 on Linux/x86-64:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44738

But they work for 32bit gcc.
Manuel López-Ibáñez - July 1, 2010, 7:04 a.m.
On 1 July 2010 02:57, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Jun 30, 2010 at 4:33 AM, Bernd Schmidt <bernds@codesourcery.com> wrote:
>> On 06/30/2010 12:00 PM, Manuel López-Ibáñez wrote:
>>
>>> /* { dg-message "note: 'b' was declared here" } */
>>
>> When I tried something like this initially I couldn't get it to work, so
>> I started looking at other testcases.  I've tried again now - how about
>> this version?
>
> The test failed with -m32 on Linux/x86-64:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44738
>
> But they work for 32bit gcc.

It seems a location bug. Moving the dg-message around does hide the
bug for this test but the bug is still there. Tests are supposed to
catch bugs and this test is catching one. If you don't want to fix it,
then don't, but don't hide it.

Manuel.
Jie Zhang - July 13, 2010, 9:55 a.m.
On 06/30/2010 07:33 PM, Bernd Schmidt wrote:
> On 06/30/2010 12:00 PM, Manuel López-Ibáñez wrote:
>
>> >  /* { dg-message "note: 'b' was declared here" } */
> When I tried something like this initially I couldn't get it to work, so
> I started looking at other testcases.  I've tried again now - how about
> this version?
>
> 	PR tree-optimization/39799
> 	* tree-inline.c (remap_ssa_name): Initialize variable only if
> 	SSA_NAME_OCCURS_IN_ABNORMAL_PHI.
>
> 	PR tree-optimization/39799
> 	* c-c++-common/uninit-17.c: New test.
>
This might cause

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44921

Patch

Index: tree-inline.c
===================================================================
--- tree-inline.c	(revision 161540)
+++ 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/c-c++-common/uninit-17.c
===================================================================
--- testsuite/c-c++-common/uninit-17.c	(revision 0)
+++ testsuite/c-c++-common/uninit-17.c	(revision 0)
@@ -0,0 +1,25 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized" } */
+
+inline int foo(int x)
+{
+  return x;
+}
+static void bar(int a, int *ptr)
+{
+  do
+  {
+    int b; /* { dg-message "note: 'b' was declared here" } */
+    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);
+}
+