public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/53855] New: Emitting a warning for some dangling references.
@ 2012-07-04 16:36 ed at edrosten dot com
  2012-07-04 18:18 ` [Bug middle-end/53855] Emitting a warning for use after clobber pinskia at gcc dot gnu.org
  2012-07-05  8:40 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: ed at edrosten dot com @ 2012-07-04 16:36 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53855
           Summary: Emitting a warning for some dangling references.
    Classification: Unclassified
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ed@edrosten.com


A dangling reference is created in the following code:


struct IntRef
{
    IntRef(const int& v_)
    :v(v_)
    {
    }

    const int& v;
    double get() const
    {
        return v;
    }
};



struct BRef
{
    BRef(const IntRef& v_)
    :v(v_)
    {
    }

    const IntRef& v;
    double get() const
    {
        return v.get();
    }
};


double test(const int& a)
{
    const BRef c(a);
    return c.get();
}

After the first stage of copy propagation, the representation of test is (from
test.cc.029t.copyprop1):


;; Function double test(const int&) (_Z4testRKi, funcdef_no=8, decl_uid=2230,
cgraph_uid=8)

double test(const int&) (const int & a)
{
  const struct IntRef & c$v;
  const struct IntRef & D.2286;
  int D.2284;
  const int & D.2283;
  double D.2282;
  const struct BRef c;
  const struct IntRef D.2251;

<bb 2>:
  D.2251.v = a_1(D);
  D.2251 ={v} {CLOBBER};
  D.2283_9 = D.2251.v;
  D.2284_10 = *D.2283_9;
  D.2282_11 = (double) D.2284_10;
  return D.2282_11;

}

at which point is is quite obvious that D.2251 is used after it is CLOBBER'd.
Is it possible to add a feature to generate a warning in this case?


I'm using gcc version r189256 from SVN, but things are much the same in 4.7.


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

* [Bug middle-end/53855] Emitting a warning for use after clobber
  2012-07-04 16:36 [Bug tree-optimization/53855] New: Emitting a warning for some dangling references ed at edrosten dot com
@ 2012-07-04 18:18 ` pinskia at gcc dot gnu.org
  2012-07-05  8:40 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-07-04 18:18 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
          Component|tree-optimization           |middle-end
            Version|tree-ssa                    |4.7.0
            Summary|Emitting a warning for some |Emitting a warning for use
                   |dangling references.        |after clobber

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-07-04 18:18:19 UTC ---
Maybe the C++ front-end could warn about use of temp variables passed to
constructors.


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

* [Bug middle-end/53855] Emitting a warning for use after clobber
  2012-07-04 16:36 [Bug tree-optimization/53855] New: Emitting a warning for some dangling references ed at edrosten dot com
  2012-07-04 18:18 ` [Bug middle-end/53855] Emitting a warning for use after clobber pinskia at gcc dot gnu.org
@ 2012-07-05  8:40 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-05  8:40 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-07-05
     Ever Confirmed|0                           |1

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-05 08:40:06 UTC ---
Confirmed.


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

end of thread, other threads:[~2012-07-05  8:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-04 16:36 [Bug tree-optimization/53855] New: Emitting a warning for some dangling references ed at edrosten dot com
2012-07-04 18:18 ` [Bug middle-end/53855] Emitting a warning for use after clobber pinskia at gcc dot gnu.org
2012-07-05  8:40 ` 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).