Original Post
I've come across a MinGW/GCC optimization that causes a crash.. There's this C++ function which takes a value parameter (Vector3 is a 12 bytes POD type)
Normally the Vector3 should of course be passed by const reference, but it's now being passed by value due to a templated auto-serialization system that also calls this function.
Now, when the function is exposed to Angelscript normally, it will crash on MinGW when called, as the compiler actually optimized it to a reference, and instead of reading the Vector3 data on the stack as expected, it interprets it as a pointer to Vector3:
What I currently do to work around this is somewhat ugly:
This is of course not a fault of AngelScript, but rather, I'm asking if anyone knows a GCC flag that will disable this optimization?
void PhysicsWorld::SetGravity(Vector3 gravity)
{
dWorldSetGravity(physicsWorld_, gravity.x_, gravity.y_, gravity.z_);
}
Normally the Vector3 should of course be passed by const reference, but it's now being passed by value due to a templated auto-serialization system that also calls this function.
Now, when the function is exposed to Angelscript normally, it will crash on MinGW when called, as the compiler actually optimized it to a reference, and instead of reading the Vector3 data on the stack as expected, it interprets it as a pointer to Vector3:
engine->RegisterObjectMethod("PhysicsWorld", "void set_gravity(Vector3)", asMETHOD(PhysicsWorld, SetGravity), asCALL_THISCALL);
What I currently do to work around this is somewhat ugly:
#ifdef _MSC_VER
engine->RegisterObjectMethod("PhysicsWorld", "void set_gravity(Vector3)", asMETHOD(PhysicsWorld, SetGravity), asCALL_THISCALL);
#else
// GCC will convert to reference
engine->RegisterObjectMethod("PhysicsWorld", "void set_gravity(const Vector3∈)", asMETHOD(PhysicsWorld, SetGravity), asCALL_THISCALL);
#endif
This is of course not a fault of AngelScript, but rather, I'm asking if anyone knows a GCC flag that will disable this optimization?