Re: Codegen bug with exceptions and destructors in GCC 4.0.1
Re: Codegen bug with exceptions and destructors in GCC 4.0.1
- Subject: Re: Codegen bug with exceptions and destructors in GCC 4.0.1
- From: Steve Baxter <email@hidden>
- Date: Thu, 1 Jun 2006 15:55:57 +0100
Hi,
A little more information on this after talking with Chris Jefferson:
- My test code does not provoke the problem on PPC, only on Intel.
The original problem occurs on both Intel and PPC however.
- I can make the problem go away if I mark either Sleep() or Sleep2()
as inline.
I suspect this is a problem with the automatic inliner. It is
probably not appearing in my test case on PPC because the function
ends up being too long to inline, whereas on Intel it does get inlined.
Cheers,
Steve.
On 1 Jun 2006, at 12:35, Steve Baxter wrote:
Hi,
We've just come across a nasty problem that manifests itself at -O3
that I wanted to make everyone aware of. It seems that under
certain conditions, the destructor for stack objects will not get
called when an exception is thrown.
This is a pretty critical bug - we rely on stack objects to clean
up after exceptions! Anyone that uses stack objects might want to
avoid -O3 until this is resolved.
I have reported it to Apple (radr://4569804). Here is code that
demonstrates the problem (excuse the code, it was boiled down from
the original problem in our code):
#include <iostream>
#include <exception>
class XStackObject
{
public:
inline XStackObject()
{
std::cout << "XStackObject constructed\n";
}
inline ~XStackObject()
{
try
{
std::cout << "XStackObject destructed\n";
}
catch( ... )
{
}
}
};
void ThrowException()
{
throw std::exception();
}
bool Sleep2( int sleepMS, bool threadCanBeStopped )
{
try
{
ThrowException();
}
catch( ... )
{
std::cout << "Caught exception\n";
throw;
}
return true;
}
bool Sleep( int sleepMS, bool threadCanBeStopped )
{
XStackObject lock;
while( true )
{
int timeLeft = 0;
if( sleepMS == 1 )
{
timeLeft = 1000;
}
else
{
timeLeft = 2000;
}
if( Sleep2( timeLeft, threadCanBeStopped ) )
{
return true;
}
}
return false;
}
int main (int argc, char * const argv[])
{
try
{
Sleep( 1000, true );
}
catch( ... )
{
std::cout << "Caught exception\n";
}
return 0;
}
The correct output (at -O2) is:
XStackObject constructed
Caught exception
XStackObject destructed
Caught exception
The output at -O3 is:
XStackObject constructed
Caught exception
Caught exception
Cheers,
Steve.
Steve Baxter
Software Development Manager
Improvision
+44-2476-692229
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40improvision.com
This email sent to email@hidden
Steve Baxter
Software Development Manager
Improvision
+44-2476-692229
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden