Tuesday, 16 September 2008

ARM “by-value” compiler bug

Hi Folks,

newly we've rediscoverd an already "known" compiler bug while developing Windows CE 5.0 applications with eMbedded Visual C++ 4 (SP4) for the ARM processor. But maybe it is still important to some developer to talk about it.

The C++ ARM compiler creates buggy code when passing structs and classes per value and when the struct or class stores pointers to itself or its members somewhere.

Code Example:

class A{
A (): m_OrigThis(NULL) { }
A (A& a): m_OrigThis(this) { }
A* m_OrigThis;

void foo (A a2)
ASSERT(a2.m_OrigThis == &a2); // unequal on ARM

int WINAPI WinMain( .... )
A a;
foo (a);
return 0;

You can avoid this bug by switching your development environment from eMbedded Visual Tools 4 to VC2005.
Then the VS2005 ARM compiler creates correct code, if the struct or class contains the copy constructor. In VS2008 the ARM compiler works well also.
If you're developing for Windows CE 4.x you must use eMbedded Visual Tools 4, in this case you have to "rewrite" your code.
If you're looking for some more stuff about Windows CE ARM compiler, then take a look at the following links:

No comments: