aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/private
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2018-06-14 14:41:22 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-18 17:22:18 +0000
commite72e773ad0684626ba4ed79f97b7f36cd8e5c923 (patch)
tree921a6efa730cd115a3539d6ce71e16cdb6f2dc7c /include/private
parent19c1233c447f625c2522e7ecd0a0adecc629bb2f (diff)
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>
Diffstat (limited to 'include/private')
-rw-r--r--include/private/GrSwizzle.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/include/private/GrSwizzle.h b/include/private/GrSwizzle.h
index db645dbe49..da5d3e0f16 100644
--- a/include/private/GrSwizzle.h
+++ b/include/private/GrSwizzle.h
@@ -38,8 +38,12 @@ private:
, fKey((CToI(c[0]) << 0) | (CToI(c[1]) << 2) | (CToI(c[2]) << 4) | (CToI(c[3]) << 6)) {}
GR_STATIC_ASSERT(sizeof(char[4]) == sizeof(uint32_t));
- uint32_t* asUIntPtr() { return SkTCast<uint32_t*>(fSwiz); }
- uint32_t asUInt() const { return *SkTCast<const uint32_t*>(fSwiz); }
+ uint32_t* asUIntPtr() { return reinterpret_cast<uint32_t*>(fSwiz); }
+ uint32_t asUInt() const {
+ uint32_t v;
+ memcpy(&v, fSwiz, 4);
+ return v;
+ }
public:
GrSwizzle() { *this = RGBA(); }