Unverified Commit 569879b2 authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #715 from capnproto/arm64-workaround

Work around apparent Clang optimization bug on arm64.
parents 1e56a130 8a046f6e
......@@ -1725,11 +1725,21 @@ int64_t unsignedToSigned<int64_t>(unsigned long long value) {
template <typename T, typename U>
T checkRoundTrip(U value) {
KJ_REQUIRE(T(value) == value, "Value out-of-range for requested type.", value) {
#if __aarch64__
// Work around an apparently broken compiler optimization on Clang / arm64. It appears that
// for T = int8_t, U = double, and value = 128, the compiler incorrectly believes that the
// round-trip does not change the value, where in fact it should change to -128. Similar problems
// exist for various other types and inputs -- json-test seems to exercise several problem cases.
// The problem only exists when compiling with optimization. In any case, declaring the variable
// `volatile` kills the optimization.
volatile
#endif
T result = value;
KJ_REQUIRE(U(result) == value, "Value out-of-range for requested type.", value) {
// Use it anyway.
break;
}
return value;
return result;
}
} // namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment