remove SkTCast
SkTCast is functionally equivalent to reinterpret_cast.
The comment about SkTCast helping to avoid strict alising issues is not
true. Dereferencing a pointer cast to a pointer of an unrelated type is
always undefined, even if smuggled through a union like in SkTCast.
To really avoid aliasing issues, you need to make a union[1] of the two
value types, or better, memcpy between values. I've had to fix
MatrixText.cpp where switching to reinterpret_cast actually let Clang
notice and warn that we're exploiting undefined behavior, and
GrSwizzle.h and SkCamera.cpp caught by GCC.
I've switched SkTLList over to use SkAlignedSTStorage, which seems
to help convince some GCC versions that fObj is used in a sound way.
[1] The union punning trick is non-standard in C++, but GCC and MSVC
both explicitly support it. I believe Clang does not officially
explicitly support it, but probably does quietly for GCC compatibility.
Change-Id: I71822e82c962f9aaac8be24d3c0f39f4f8b05026
Reviewed-on: https://skia-review.googlesource.com/134947
Commit-Queue: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Auto-Submit: Mike Klein <mtklein@chromium.org>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp
index 5dfe2ca..03661dc 100644
--- a/tests/MatrixTest.cpp
+++ b/tests/MatrixTest.cpp
@@ -27,6 +27,12 @@
return true;
}
+static int float_bits(float f) {
+ int result;
+ memcpy(&result, &f, 4);
+ return result;
+}
+
static bool are_equal(skiatest::Reporter* reporter,
const SkMatrix& a,
const SkMatrix& b) {
@@ -38,8 +44,8 @@
for (int i = 0; i < 9; ++i) {
float aVal = a.get(i);
float bVal = b.get(i);
- int aValI = *SkTCast<int*>(&aVal);
- int bValI = *SkTCast<int*>(&bVal);
+ int aValI = float_bits(aVal);
+ int bValI = float_bits(bVal);
if (0 == aVal && 0 == bVal && aValI != bValI) {
foundZeroSignDiff = true;
} else {
@@ -52,8 +58,8 @@
for (int i = 0; i < 9; ++i) {
float aVal = a.get(i);
float bVal = b.get(i);
- int aValI = *SkTCast<int*>(&aVal);
- int bValI = *SkTCast<int*>(&bVal);
+ int aValI = float_bits(aVal);
+ int bValI = float_bits(bVal);
if (sk_float_isnan(aVal) && aValI == bValI) {
foundNaN = true;
} else {