From 48bb1f1cb043593fdde9e3085beb9d312ec2ff2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 19 Mar 2013 16:21:44 +0100 Subject: [PATCH] GCC 4.4 compatibility: workarounds for strict-aliasing fascism. These four cover most (but not all) warnings when compiling in Release mode. Now all the tests pass, but the warnings signalize that something could go bad somewhere else. However, only one drastic solution comes to my mind at this time -- disabling strict aliasing completely `-fno-strict-aliasing`. Don't know performance impact of that. --- src/Math/Matrix3.h | 12 ++++++++++++ src/Math/Matrix4.h | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 344f55d86..579610d70 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -244,7 +244,13 @@ template class Matrix3: public Matrix<3, T> { * @todo extract 2x2 matrix and multiply directly? (benchmark that) */ inline Vector2 transformVector(const Vector2& vector) const { + /* Workaround for GCC 4.4 strict-aliasing fascism */ + #ifndef CORRADE_GCC44_COMPATIBILITY return ((*this)*Vector3(vector, T(0))).xy(); + #else + const auto v = (*this)*Vector3(vector, T(0)); + return v.xy(); + #endif } /** @@ -257,7 +263,13 @@ template class Matrix3: public Matrix<3, T> { * @see DualComplex::transformPoint(), Matrix4::transformPoint() */ inline Vector2 transformPoint(const Vector2& vector) const { + /* Workaround for GCC 4.4 strict-aliasing fascism */ + #ifndef CORRADE_GCC44_COMPATIBILITY return ((*this)*Vector3(vector, T(1))).xy(); + #else + const auto v = (*this)*Vector3(vector, T(1)); + return v.xy(); + #endif } MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(3, 3, Matrix3) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 7a72d9ec3..2346b2e77 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -401,7 +401,13 @@ template class Matrix4: public Matrix<4, T> { * @todo extract 3x3 matrix and multiply directly? (benchmark that) */ inline Vector3 transformVector(const Vector3& vector) const { + /* Workaround for GCC 4.4 strict-aliasing fascism */ + #ifndef CORRADE_GCC44_COMPATIBILITY return ((*this)*Vector4(vector, T(0))).xyz(); + #else + const auto v = (*this)*Vector4(vector, T(0)); + return v.xyz(); + #endif } /** @@ -414,7 +420,13 @@ template class Matrix4: public Matrix<4, T> { * @see DualQuaternion::transformPoint(), Matrix3::transformPoint() */ inline Vector3 transformPoint(const Vector3& vector) const { + /* Workaround for GCC 4.4 strict-aliasing fascism */ + #ifndef CORRADE_GCC44_COMPATIBILITY return ((*this)*Vector4(vector, T(1))).xyz(); + #else + const auto v = (*this)*Vector4(vector, T(1)); + return v.xyz(); + #endif } MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(4, 4, Matrix4)