User account creation filtered due to spam.

Bug 21124 - [4.1 regression] bogus "may be used uninitialized" warning
Summary: [4.1 regression] bogus "may be used uninitialized" warning
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, monitored, rejects-valid
: 21310 (view as bug list)
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2005-04-20 15:02 UTC by Volker Reichelt
Modified: 2005-11-02 19:17 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-04-20 15:19:17


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2005-04-20 15:02:48 UTC
On mainline I get some bogus warnings about uninitialized variables.
Just compile the following with "g++ -O -Wall":

==================================================
#include<valarray>

void foo(int i, std::valarray<int>& v)
{
    v += i*v;
}

void bar()
{
    std::valarray<int> v;

    for (int j=0; j<2; ++j)
        foo(0, v);
}
==================================================

The warning message is:

bug.cc: In function 'void bar()':
bug.cc:13: warning: 'i' may be used uninitialized in this function

A reduced version is here (compile with "-O -Wall"):

==================================================
struct A
{
    void foo() const;
};

struct B
{
    const int& i;
    const A& a;

    B(const int& __i, const A& __a) : i(__i), a(__a) {}
    static void bar(const B& b) { b.a.foo(); }
};

void baz()
{
    A a;

    for (int j=0; j<2; ++j)
        B::bar(B(0,a));
}
==================================================

The warning message for this case is even weirder (anonymous seems to refer
to the constant 0):

bug.cc: In function 'void baz()':
bug.cc:20: warning: '<anonymous>' may be used uninitialized in this function

Code like this compiled with -Werror will be rejected, so I'll rate
this as a rejects-valid bug.
The 4.0 branch is not affected.
Comment 1 Andrew Pinski 2005-04-20 15:19:16 UTC
Confirmed:
  # D.1678_31 = PHI <0(3), D.1678_8(0)>;


Why is this PHI, here, it is just dead code, maybe we should check the use info to see if it is actually 
used.
Comment 2 Volker Reichelt 2005-04-20 16:04:20 UTC
Here's an even simpler testcase that triggers the warning with -O, -O2, -O3:

============================================
struct A
{
    const int& i;
    int j;

    A(const int& __i) : i(__i), j(0) {}
};

void foo(const int&);

inline void bar(const A& a) { foo(a.j); }

void baz()
{
    for (int k=0; k<2; ++k)
        bar(A(0));
}
============================================
Comment 3 Volker Reichelt 2005-04-26 20:53:50 UTC
This was introduced with a merge from tree-cleanup-branch:
http://gcc.gnu.org/ml/gcc-cvs/2005-04/msg00501.html
Comment 4 joseph@codesourcery.com 2005-04-26 21:13:54 UTC
Subject: Re:  [4.1 regression] bogus "may be used
 uninitialized" warning

On Tue, 26 Apr 2005, reichelt at gcc dot gnu dot org wrote:

> This was introduced with a merge from tree-cleanup-branch:
> http://gcc.gnu.org/ml/gcc-cvs/2005-04/msg00501.html

Bug 21005, gcc.dg/uninit-1.c failure, was also introduced by the same 
merge; they may be related.

Comment 5 Andrew Pinski 2005-04-30 23:38:22 UTC
*** Bug 21310 has been marked as a duplicate of this bug. ***
Comment 6 Volker Reichelt 2005-05-23 10:46:14 UTC
This got fixed by Diego's reorganization of the initial optimization passes:
http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00955.html
http://gcc.gnu.org/ml/gcc-cvs/2005-05/msg00529.html