* [Bug c++/35548] g++ 4.3.{0,1} miscompile this simple program
2008-03-12 8:21 [Bug c++/35548] New: g++ 4.3.{0,1} miscompile this simple program varg at theor dot jinr dot ru
@ 2008-03-12 10:20 ` rguenth at gcc dot gnu dot org
2008-03-13 6:43 ` varg at theor dot jinr dot ru
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-12 10:20 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2008-03-12 10:19 -------
It's by no means a "simple" program ;)
the failure mode is that
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400bed in basic::compare (this=0x603040, other=@0x603010) at t.C:98
98 return compare_same_type(other);
(gdb) print other
$1 = (const basic &) @0x603010: {<refcounted> = {refcount = 1},
_vptr.basic = 0x401430, static tinfo_static = {<No data fields>},
tinfo_key = 0x401365, flags = 3}
(gdb) print *this
$3 = {<refcounted> = {refcount = 0}, _vptr.basic = 0x0,
static tinfo_static = {<No data fields>}, tinfo_key = 0x401365, flags = 3}
the object compare is invoked on is not properly initialized (its _vptr is
NULL).
(gdb) bt
#0 0x0000000000400bed in basic::compare (this=0x603040, other=@0x603010)
at t.C:98
#1 0x0000000000400f41 in ex::compare (this=0x7fff106c4510,
other=@0x7fff106c44e0) at t.C:165
#2 0x00000000004009a8 in main (argc=1, argv=0x7fff106c4628) at t.C:213
For whatever reason (program non-conformance or GCC bug).
Please try to simplify the test program.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35548
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/35548] g++ 4.3.{0,1} miscompile this simple program
2008-03-12 8:21 [Bug c++/35548] New: g++ 4.3.{0,1} miscompile this simple program varg at theor dot jinr dot ru
2008-03-12 10:20 ` [Bug c++/35548] " rguenth at gcc dot gnu dot org
@ 2008-03-13 6:43 ` varg at theor dot jinr dot ru
2008-03-13 11:18 ` varg at theor dot jinr dot ru
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: varg at theor dot jinr dot ru @ 2008-03-13 6:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from varg at theor dot jinr dot ru 2008-03-13 06:42 -------
Richard Guenther wrote:
> the object compare is invoked on is not properly initialized (its _vptr is
> NULL).
Not exactly. The object (or rather, the pointer managed by that objects) gets
deleted too early.
> Please try to simplify the test program.
template <class T> class ptr
{
T* p;
public:
ptr(T* t) throw() : p(t)
{
p->set_refcount(1);
}
explicit ptr(T& t) throw() : p(&t)
{
p->add_reference();
}
ptr(const ptr& other) throw() : p(other.p)
{
p->add_reference();
}
~ptr()
{
if (p->remove_reference() == 0)
delete p;
}
ptr& operator=(const ptr& other)
{
T* otherp = other.p;
otherp->add_reference();
if (p->remove_reference() == 0)
delete p;
p = otherp;
return *this;
}
T& operator*() const throw()
{
return *p;
}
T* operator->() const throw()
{
return p;
}
};
class refcounted
{
public:
refcounted() throw() : refcount(0) { }
unsigned add_reference() throw()
{
return ++refcount;
}
unsigned remove_reference() throw()
{
return --refcount;
}
unsigned get_refcount() const throw()
{
return refcount;
}
void set_refcount(unsigned r) throw()
{
refcount = r;
}
private:
unsigned refcount;
};
class ex;
enum status_flags {
dynallocated = 1,
evaluated = 2
};
class basic : public refcounted
{
public:
basic() : flags(0) { }
basic(const basic& other) : flags(other.flags & ~dynallocated) { }
virtual basic* duplicate() const
{
return new basic(*this);
}
virtual ex eval() const;
const basic& hold() const
{
flags |= evaluated;
return *this;
}
virtual ~basic() { }
protected:
mutable unsigned flags;
private:
friend class ex;
};
class ex {
private:
mutable ptr<basic> bp;
static ptr<basic> construct_from_basic(const basic& other)
{
if (!(other.flags & evaluated)) {
const ex& tmpex = other.eval();
if ((other.get_refcount() == 0) && (other.flags &
dynallocated))
delete &other;
return tmpex.bp;
} else {
if (other.flags & dynallocated) {
return ptr<basic>(const_cast<basic &>(other));
} else {
basic* bp = other.duplicate();
bp->flags |= dynallocated;
return bp;
}
}
}
public:
ex(const basic& other) : bp(construct_from_basic(other)) { }
ex eval() const
{
return bp->eval();
}
};
ex basic::eval() const
{
return hold();
}
class oops : public basic
{
public:
oops() { }
oops* duplicate() const
{
return new oops(*this);
}
ex eval() const
{
return oops().hold();
}
};
int main(int argc, char** argv)
{
const ex e = oops().hold();
const ex& f = argc > 1 ? e : e.eval();
const ex& g = f.eval();
return 0;
}
--
varg at theor dot jinr dot ru changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |varg at theor dot jinr dot
| |ru
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35548
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/35548] g++ 4.3.{0,1} miscompile this simple program
2008-03-12 8:21 [Bug c++/35548] New: g++ 4.3.{0,1} miscompile this simple program varg at theor dot jinr dot ru
2008-03-12 10:20 ` [Bug c++/35548] " rguenth at gcc dot gnu dot org
2008-03-13 6:43 ` varg at theor dot jinr dot ru
@ 2008-03-13 11:18 ` varg at theor dot jinr dot ru
2008-03-13 16:43 ` [Bug c++/35548] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: varg at theor dot jinr dot ru @ 2008-03-13 11:18 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from varg at theor dot jinr dot ru 2008-03-13 11:17 -------
Even more simple program:
template <class T> class ptr
{
T* p;
public:
ptr(T* t) throw() : p(t)
{
p->set_refcount(1);
}
explicit ptr(T& t) throw() : p(&t)
{
p->add_reference();
}
ptr(const ptr& other) throw() : p(other.p)
{
p->add_reference();
}
~ptr()
{
if (p->remove_reference() == 0)
delete p;
}
ptr& operator=(const ptr& other)
{
T* otherp = other.p;
otherp->add_reference();
if (p->remove_reference() == 0)
delete p;
p = otherp;
return *this;
}
T& operator*() const throw()
{
return *p;
}
T* operator->() const throw()
{
return p;
}
};
class refcounted
{
public:
refcounted() throw() : refcount(0) { }
unsigned add_reference() throw()
{
return ++refcount;
}
unsigned remove_reference() throw()
{
return --refcount;
}
unsigned get_refcount() const throw()
{
return refcount;
}
void set_refcount(unsigned r) throw()
{
refcount = r;
}
private:
unsigned refcount;
};
class ex;
class basic : public refcounted
{
public:
basic() : flags(false) { }
basic(const basic& other) : flags(false) { }
virtual basic* duplicate() const
{
return new basic(*this);
}
virtual ex eval() const;
virtual ~basic() { }
protected:
mutable bool flags;
private:
friend class ex;
};
class ex {
private:
mutable ptr<basic> bp;
static ptr<basic> construct_from_basic(const basic& other)
{
if (other.flags)
return ptr<basic>(const_cast<basic &>(other));
else {
basic* t = other.duplicate();
t->flags = true;
return t;
}
}
public:
ex(const basic& other) : bp(construct_from_basic(other)) { }
ex eval() const
{
return bp->eval();
}
};
ex basic::eval() const
{
return *this;
}
class oops : public basic
{
public:
oops() { }
oops* duplicate() const
{
return new oops(*this);
}
ex eval() const
{
return oops();
}
};
int main(int argc, char** argv)
{
const ex e = oops();
const ex& f = argc > 1 ? e : e.eval();
const ex& g = f.eval();
return 0;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35548
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/35548] [4.3/4.4 Regression] g++ 4.3.{0,1} miscompile this simple program
2008-03-12 8:21 [Bug c++/35548] New: g++ 4.3.{0,1} miscompile this simple program varg at theor dot jinr dot ru
` (2 preceding siblings ...)
2008-03-13 11:18 ` varg at theor dot jinr dot ru
@ 2008-03-13 16:43 ` rguenth at gcc dot gnu dot org
2008-03-13 22:11 ` hjl dot tools at gmail dot com
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-13 16:43 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu dot
| |org
Keywords| |wrong-code
Known to fail| |4.3.0
Known to work| |4.2.3
Summary|g++ 4.3.{0,1} miscompile |[4.3/4.4 Regression] g++
|this simple program |4.3.{0,1} miscompile this
| |simple program
Target Milestone|--- |4.3.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35548
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/35548] [4.3/4.4 Regression] g++ 4.3.{0,1} miscompile this simple program
2008-03-12 8:21 [Bug c++/35548] New: g++ 4.3.{0,1} miscompile this simple program varg at theor dot jinr dot ru
` (3 preceding siblings ...)
2008-03-13 16:43 ` [Bug c++/35548] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
@ 2008-03-13 22:11 ` hjl dot tools at gmail dot com
2008-03-15 19:14 ` [Bug c++/35548] [4.3/4.4 Regression] g++ 4.3 " rguenth at gcc dot gnu dot org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl dot tools at gmail dot com @ 2008-03-13 22:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from hjl dot tools at gmail dot com 2008-03-13 22:11 -------
Revision 129596:
http://gcc.gnu.org/ml/gcc-cvs/2007-10/msg00701.html
http://gcc.gnu.org/ml/gcc-patches/2007-10/msg01386.html
is the cause.
--
hjl dot tools at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hjl dot tools at gmail dot
| |com, jason at redhat dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35548
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/35548] [4.3/4.4 Regression] g++ 4.3 miscompile this simple program
2008-03-12 8:21 [Bug c++/35548] New: g++ 4.3.{0,1} miscompile this simple program varg at theor dot jinr dot ru
` (4 preceding siblings ...)
2008-03-13 22:11 ` hjl dot tools at gmail dot com
@ 2008-03-15 19:14 ` rguenth at gcc dot gnu dot org
2008-03-17 21:29 ` jason at gcc dot gnu dot org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-15 19:14 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P1
Summary|[4.3/4.4 Regression] g++ |[4.3/4.4 Regression] g++ 4.3
|4.3.{0,1} miscompile this |miscompile this simple
|simple program |program
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35548
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/35548] [4.3/4.4 Regression] g++ 4.3 miscompile this simple program
2008-03-12 8:21 [Bug c++/35548] New: g++ 4.3.{0,1} miscompile this simple program varg at theor dot jinr dot ru
` (5 preceding siblings ...)
2008-03-15 19:14 ` [Bug c++/35548] [4.3/4.4 Regression] g++ 4.3 " rguenth at gcc dot gnu dot org
@ 2008-03-17 21:29 ` jason at gcc dot gnu dot org
2008-03-18 2:54 ` jason at gcc dot gnu dot org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-03-17 21:29 UTC (permalink / raw)
To: gcc-bugs
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jason at gcc dot gnu dot org
|dot org |
Status|UNCONFIRMED |ASSIGNED
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2008-03-17 21:28:26
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35548
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/35548] [4.3/4.4 Regression] g++ 4.3 miscompile this simple program
2008-03-12 8:21 [Bug c++/35548] New: g++ 4.3.{0,1} miscompile this simple program varg at theor dot jinr dot ru
` (6 preceding siblings ...)
2008-03-17 21:29 ` jason at gcc dot gnu dot org
@ 2008-03-18 2:54 ` jason at gcc dot gnu dot org
2008-03-18 2:58 ` jason at gcc dot gnu dot org
2008-03-18 2:58 ` jason at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-03-18 2:54 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from jason at gcc dot gnu dot org 2008-03-18 02:53 -------
Subject: Bug 35548
Author: jason
Date: Tue Mar 18 02:52:34 2008
New Revision: 133299
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133299
Log:
PR c++/35548
* call.c (reference_binding): Check LOOKUP_NO_TEMP_BIND when binding
a temp directly to a reference as per DR391.
Added:
trunk/gcc/testsuite/g++.dg/init/ref16.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35548
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/35548] [4.3/4.4 Regression] g++ 4.3 miscompile this simple program
2008-03-12 8:21 [Bug c++/35548] New: g++ 4.3.{0,1} miscompile this simple program varg at theor dot jinr dot ru
` (7 preceding siblings ...)
2008-03-18 2:54 ` jason at gcc dot gnu dot org
@ 2008-03-18 2:58 ` jason at gcc dot gnu dot org
2008-03-18 2:58 ` jason at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-03-18 2:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from jason at gcc dot gnu dot org 2008-03-18 02:57 -------
Fixed in 4.3 and 4.4.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35548
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/35548] [4.3/4.4 Regression] g++ 4.3 miscompile this simple program
2008-03-12 8:21 [Bug c++/35548] New: g++ 4.3.{0,1} miscompile this simple program varg at theor dot jinr dot ru
` (8 preceding siblings ...)
2008-03-18 2:58 ` jason at gcc dot gnu dot org
@ 2008-03-18 2:58 ` jason at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-03-18 2:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from jason at gcc dot gnu dot org 2008-03-18 02:57 -------
Subject: Bug 35548
Author: jason
Date: Tue Mar 18 02:56:52 2008
New Revision: 133300
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133300
Log:
PR c++/35548
* call.c (reference_binding): Check LOOKUP_NO_TEMP_BIND when binding
a temp directly to a reference as per DR391.
Added:
branches/gcc-4_3-branch/gcc/testsuite/g++.dg/init/ref16.C
- copied unchanged from r133299, trunk/gcc/testsuite/g++.dg/init/ref16.C
Modified:
branches/gcc-4_3-branch/gcc/cp/ChangeLog
branches/gcc-4_3-branch/gcc/cp/call.c
branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35548
^ permalink raw reply [flat|nested] 11+ messages in thread