This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
A bad EH bug
- To: hjl at sea dot lucon dot org (hjl)
- Subject: A bad EH bug
- From: hjl at lucon dot org (H.J. Lu)
- Date: Fri, 30 Oct 1998 10:18:09 -0800 (PST)
- Cc: oliva at dcc dot unicamp dot br, matthew at ooc dot com, jbuck at synopsys dot com, egcs at cygnus dot com, support at ooc dot com
> >
> > > On Tue, Oct 13, 1998 at 02:48:36PM -0700, Joe Buck wrote:
> >
> > >> Please send a complete test case (a complete program) to
> > >> egcs-bugs@cygnus.com, so that the experts will be able to run it through
> > >> and figure out what goes wrong.
> >
> > > This demonstrates the problem quite effectively. However, I'm afraid
> > > it's rather big. I had a (quick) crack at isolating the problem with
> > > little success.
> >
# gcc bad.cc -g
# a.out
Foo::Foo
Foo::~Foo
zsh: 12158 segmentation fault ./a.out
# gdb a.out
(gdb) r
(gdb) r
Starting program: /home/hjl/bugs/g++/opt.3/a.out
Foo::Foo
Foo::~Foo
Program received signal SIGSEGV, Segmentation fault.
0x804a2b1 in __cp_pop_exception (p=0x4002fbaa)
at /home/work/misc/gnu/src/egcs-1.1/gcc/cp/exception.cc:211
211 --p->handlers;
(gdb) bt
#0 0x804a2b1 in __cp_pop_exception (p=0x4002fbaa)
at /home/work/misc/gnu/src/egcs-1.1/gcc/cp/exception.cc:211
#1 0x804947e in Base::dispatch (this=0xbffffc17, x=0) at bad.cc:80
#2 0x80494e9 in main () at bad.cc:101
BTW, it failed on Solaris/Sparc. But it works on HP-UX 10.20. It seems
it affects all platforms with DWARF2 based EH. FYI, egcs 1.0.3 is ok.
It must be a new bug. I'd like to see it be fixed in egcs 1.1.1.
Could someone please clean it up and put it into the g++ testsuite?
Thanks.
--
H.J. Lu (hjl@gnu.org)
---
#include <stdio.h>
class Base
{
public:
int dispatch (int);
};
class Derived : public Base
{
};
class Foo
{
public:
Foo ();
~Foo ();
int getValue (int);
};
template<class T>
class OBObjVar
{
T* ptr;
public:
OBObjVar (T *p) : ptr (p) {}
~OBObjVar() { delete ptr; }
T* operator->() const { return ptr; }
};
Foo * getFoo ();
Foo::Foo ()
{
printf ("Foo::Foo\n");
}
Foo::~Foo ()
{
printf ("Foo::~Foo\n");
}
int
Foo::getValue (int x)
{
return x;
}
Foo*
getFoo ()
{
return new Foo;
}
int
Base::dispatch (int x)
{
int y = 1;
while (y)
{
OBObjVar<Foo> f = getFoo ();
try
{
y = f->getValue (x);
}
catch (const char *s)
{
printf ("Base::dispatch: %s\n", s);
if (x == 0)
{
y = 0;
continue;
}
throw;
}
catch (int)
{
continue;
}
if (y == 0)
{
f->getValue (y);
throw "Throw an exception!";
}
break;
}
return y;
}
int
main ()
{
Derived x;
try
{
x.dispatch (0);
}
catch (const char *s)
{
printf ("Caught: %s\n", s);
}
}