aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Ben Wagner <benjaminwagner@google.com>2017-09-15 17:48:08 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-16 22:44:33 +0000
commit05c474b3093222f8bd291d725fca8efc4fea75cb (patch)
treec00e18df495093d586c7f5ca110edc9cb4927c1e
parentbf12c079707a89f683ad0a6c989127fa20d9d202 (diff)
Suppress float-cast-overflow in SkPoint::Length.
Bug: skia:4632 Change-Id: I0f8a7d7a11fc76fcb315c3f0183577c3f0958926 Reviewed-on: https://skia-review.googlesource.com/47421 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Ben Wagner <benjaminwagner@google.com>
-rw-r--r--include/private/SkFloatingPoint.h8
-rw-r--r--infra/bots/recipes/test.expected/Test-Debian9-Clang-GCE-CPU-AVX2-x86_64-Debug-UBSAN_float_cast_overflow.json1
-rw-r--r--infra/bots/recipes/test.py1
-rw-r--r--src/core/SkPoint.cpp2
4 files changed, 9 insertions, 3 deletions
diff --git a/include/private/SkFloatingPoint.h b/include/private/SkFloatingPoint.h
index 79a39a2840..d167bf6ef2 100644
--- a/include/private/SkFloatingPoint.h
+++ b/include/private/SkFloatingPoint.h
@@ -105,6 +105,14 @@ static inline int sk_float_saturate2int(float x) {
#define sk_double_round2int(x) (int)floor((x) + 0.5f)
#define sk_double_ceil2int(x) (int)ceil(x)
+// Cast double to float, ignoring any warning about finite values being cast to infinity.
+#if defined(__clang__)
+__attribute__((no_sanitize("float-cast-overflow")))
+#endif
+static inline float sk_double_to_float(double x) {
+ return static_cast<float>(x);
+}
+
static const uint32_t kIEEENotANumber = 0x7fffffff;
#define SK_FloatNaN (*SkTCast<const float*>(&kIEEENotANumber))
#define SK_FloatInfinity (+(float)INFINITY)
diff --git a/infra/bots/recipes/test.expected/Test-Debian9-Clang-GCE-CPU-AVX2-x86_64-Debug-UBSAN_float_cast_overflow.json b/infra/bots/recipes/test.expected/Test-Debian9-Clang-GCE-CPU-AVX2-x86_64-Debug-UBSAN_float_cast_overflow.json
index 822bfc50c3..656073e019 100644
--- a/infra/bots/recipes/test.expected/Test-Debian9-Clang-GCE-CPU-AVX2-x86_64-Debug-UBSAN_float_cast_overflow.json
+++ b/infra/bots/recipes/test.expected/Test-Debian9-Clang-GCE-CPU-AVX2-x86_64-Debug-UBSAN_float_cast_overflow.json
@@ -528,7 +528,6 @@
"~^PathOpsFailOp$",
"~^PathOpsOpCubicsThreaded$",
"~^PathOpsOpLoopsThreaded$",
- "~^Point$",
"--verbose"
],
"cwd": "[START_DIR]/skia",
diff --git a/infra/bots/recipes/test.py b/infra/bots/recipes/test.py
index cc592e34c2..6b5ef31d78 100644
--- a/infra/bots/recipes/test.py
+++ b/infra/bots/recipes/test.py
@@ -547,7 +547,6 @@ def dm_flags(api, bot):
match.append('~^PathOpsFailOp$')
match.append('~^PathOpsOpCubicsThreaded$')
match.append('~^PathOpsOpLoopsThreaded$')
- match.append('~^Point$')
if 'float_cast_overflow' in bot and 'GPU' in bot:
# skia:4632
match.append('~^GLPrograms$')
diff --git a/src/core/SkPoint.cpp b/src/core/SkPoint.cpp
index dfa484bb4c..a131e2ff65 100644
--- a/src/core/SkPoint.cpp
+++ b/src/core/SkPoint.cpp
@@ -132,7 +132,7 @@ SkScalar SkPoint::Length(SkScalar dx, SkScalar dy) {
} else {
double xx = dx;
double yy = dy;
- return (float)sqrt(xx * xx + yy * yy);
+ return sk_double_to_float(sqrt(xx * xx + yy * yy));
}
}