public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/61456] New: Unnecesary "may be used uninitialized" warning
@ 2014-06-09 18:36 tmsriram at google dot com
  2014-06-09 20:38 ` [Bug middle-end/61456] Bogus " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: tmsriram at google dot com @ 2014-06-09 18:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61456

            Bug ID: 61456
           Summary: Unnecesary "may be used uninitialized" warning
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tmsriram at google dot com

This test case:

problem.cc
==========


int rand ();

class Funcs
{
public:
    int *f1 ();
    int *f2 ();
};
typedef decltype (&Funcs::f1) pfunc;

static int Set (Funcs * f, const pfunc & fp)
{
    (f->*fp) ();
}

void
Foo ()
{
    pfunc fp = &Funcs::f1;
    if (rand ())
        fp = &Funcs::f2;
    Set (0, fp);
}

compiled with trunk compiler:
g++ ./problem.cc -O2 -std=c++0x -c -Werror=uninitialized
./problem.cc: In function ‘void Foo()’:
./problem.cc:13:15: error: ‘fp.int* (Funcs::* const)()::__delta’ is used
uninitialized in this function [-Werror=uninitialized]
     (f->*fp) ();
               ^
./problem.cc:19:11: note: ‘fp.int* (Funcs::* const)()::__delta’ was declared
here
     pfunc fp = &Funcs::f1


With -fdump-tree-all, the dce1 pass is deleting the statement:
fp.__delta = 0;

even though this is later used with the following gimple sequence:
  _22 = fp.__delta;
  _24 = (struct Funcs *) _22;
  iftmp.2_25 (_24);
>From gcc-bugs-return-453553-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Jun 09 18:48:53 2014
Return-Path: <gcc-bugs-return-453553-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 19276 invoked by alias); 9 Jun 2014 18:48:52 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 19028 invoked by uid 48); 9 Jun 2014 18:48:48 -0000
From: "ppluzhnikov at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/61456] Bogus "may be used uninitialized" warning
Date: Mon, 09 Jun 2014 18:48:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 4.10.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: ppluzhnikov at google dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-61456-4-KW3wbVEKH6@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-61456-4@http.gcc.gnu.org/bugzilla/>
References: <bug-61456-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-06/txt/msg00635.txt.bz2
Content-length: 663

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61456

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppluzhnikov at google dot com

--- Comment #1 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
Google ref: b/15089262

> error: ‘fp.int* (Funcs::* const)()::__delta’ is used uninitialized ...

Note that there is no '__delta' in the original source, so the error message is
exceedingly confusing to the end user, in addition to being bogus.
>From gcc-bugs-return-453554-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Jun 09 19:14:50 2014
Return-Path: <gcc-bugs-return-453554-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 12755 invoked by alias); 9 Jun 2014 19:14:49 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 12715 invoked by uid 48); 9 Jun 2014 19:14:44 -0000
From: "tejohnson at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/61456] Bogus "may be used uninitialized" warning
Date: Mon, 09 Jun 2014 19:14:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 4.10.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: tejohnson at google dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-61456-4-lTGoE3U00E@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-61456-4@http.gcc.gnu.org/bugzilla/>
References: <bug-61456-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-06/txt/msg00636.txt.bz2
Content-length: 1724

https://gcc.gnu.org/bugzilla/show_bug.cgi?ida456

Teresa Johnson <tejohnson at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tejohnson at google dot com

--- Comment #2 from Teresa Johnson <tejohnson at google dot com> ---
I have another small test case that manifests as a seg fault at runtime, but I
believe it is likely the same issue.

test.cc:

class MyClass {
 public:
  virtual void Method1() const {}

  virtual void Method2() const {}

  virtual ~MyClass() {}
};

int main(void) {
  MyClass *d = new MyClass;
  struct MethodStruct {
    void (MyClass::*method)() const;
  };

  const MethodStruct kTest[] = {
    {&MyClass::Method1},
    {&MyClass::Method2},
  };

  for (int i = 0; i < 2; ++i) {
    (d->*kTest[i].method)();
  }
  delete d;
}


Compiled with "g++ -O2 test.cc -std=gnu++11" it seg faults when trying to
invoke method in the for loop. If I make this change:

22c22,23
<     (d->*kTest[i].method)();
---
>     const auto ptmf = kTest[i].method;
>     (d->*ptmf)();

the test case passes.

I found that the following initializations of the function pointers in kTest
are being eliminated by cddce1, and if that is disabled, then they are
eliminated by dce1:

  [test.cc : 19:3] # .MEM_12 = VDEF <.MEM_10>
  kTestD.2288[0].methodD.2287.__pfnD.2284 = 1B;
  [test.cc : 19:3] # .MEM_13 = VDEF <.MEM_12>
  kTestD.2288[0].methodD.2287.__deltaD.2285 = 0;
  [test.cc : 19:3] # .MEM_14 = VDEF <.MEM_13>
  kTestD.2288[1].methodD.2287.__pfnD.2284 = 9B;
  [test.cc : 19:3] # .MEM_15 = VDEF <.MEM_14>
  kTestD.2288[1].methodD.2287.__deltaD.2285 = 0;


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-06-11  9:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-09 18:36 [Bug middle-end/61456] New: Unnecesary "may be used uninitialized" warning tmsriram at google dot com
2014-06-09 20:38 ` [Bug middle-end/61456] Bogus " pinskia at gcc dot gnu.org
2014-06-10  9:50 ` rguenth at gcc dot gnu.org
2014-06-10  9:58 ` manu at gcc dot gnu.org
2014-06-10  9:59 ` [Bug middle-end/61456] [4.9/4.10 Regression] " rguenth at gcc dot gnu.org
2014-06-10 14:11 ` rguenth at gcc dot gnu.org
2014-06-10 14:15 ` tejohnson at google dot com
2014-06-10 14:38 ` rguenth at gcc dot gnu.org
2014-06-10 15:08 ` [Bug middle-end/61456] [4.9 " tejohnson at google dot com
2014-06-11  9:29 ` rguenth at gcc dot gnu.org
2014-06-11  9:33 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).