• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Codegen bug with exceptions and destructors in GCC 4.0.1
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Codegen bug with exceptions and destructors in GCC 4.0.1


  • Subject: Codegen bug with exceptions and destructors in GCC 4.0.1
  • From: Steve Baxter <email@hidden>
  • Date: Thu, 1 Jun 2006 12:35:22 +0100

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Codegen bug with exceptions and destructors in GCC 4.0.1
      • From: Steve Baxter <email@hidden>
  • Prev by Date: Re: Little problem after update to 2.3
  • Next by Date: Equiv. to CW: Undefined Macro in #if
  • Previous by thread: Re: Little problem after update to 2.3
  • Next by thread: Re: Codegen bug with exceptions and destructors in GCC 4.0.1
  • Index(es):
    • Date
    • Thread