Bug 1442967 - When doing a comparison against a 64-bit constant in code run only in 64-bit builds, but compiled in 32-bit builds, cast it to uintptr_t so that the comparison isn't clearly false in 32-bit builds. rs=froydnj by suggestion on IRC a=test-only
authorJeff Walden <jwalden@mit.edu>
Mon, 12 Mar 2018 13:36:44 -0700
changeset 462625 960411415e42b8cadfeb60a49e58af3b0dd260d8
parent 462624 5b5c5f82c6d8e49d310687de369649aac6b67c69
child 462626 e485f830866050893a002e7dcfd5e2ff202b10cc
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, test-only
bugs1442967
milestone60.0
Bug 1442967 - When doing a comparison against a 64-bit constant in code run only in 64-bit builds, but compiled in 32-bit builds, cast it to uintptr_t so that the comparison isn't clearly false in 32-bit builds. rs=froydnj by suggestion on IRC a=test-only
mfbt/tests/TestEndian.cpp
--- a/mfbt/tests/TestEndian.cpp
+++ b/mfbt/tests/TestEndian.cpp
@@ -1,24 +1,22 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Assertions.h"
 #include "mozilla/EndianUtils.h"
-#include "mozilla/MathAlgorithms.h"
 
 #include <stddef.h>
 
 using mozilla::BigEndian;
 using mozilla::LittleEndian;
 using mozilla::NativeEndian;
-using mozilla::RotateRight;
 
 template<typename T>
 void
 TestSingleSwap(T aValue, T aSwappedValue)
 {
 #if MOZ_LITTLE_ENDIAN
   MOZ_RELEASE_ASSERT(NativeEndian::swapToBigEndian(aValue) == aSwappedValue);
   MOZ_RELEASE_ASSERT(NativeEndian::swapFromBigEndian(aValue) == aSwappedValue);
@@ -365,30 +363,22 @@ main()
     BigEndian::readUint32(&unsigned_bytes[0]) == 0x01020304U);
 
   MOZ_RELEASE_ASSERT(
     LittleEndian::readUint64(&unsigned_bytes[0]) == 0x0807060504030201ULL);
   MOZ_RELEASE_ASSERT(
     BigEndian::readUint64(&unsigned_bytes[0]) == 0x0102030405060708ULL);
 
   if (sizeof(uintptr_t) == 8) {
-    // Comparing a uint32_t (in 32-bit builds) against a non-uint32_t uint64_t
-    // value causes constantly-false compiler warnings with some compilers.
-    // Hack around this by ensuring both sides are uint64_t, then rotating by
-    // identical amounts to fake out compiler range analysis.
-    //
-    // C++17 adds an |if constexpr(...)| statement construct that compilers use
-    // to not-compile things like invalid template uses, that may eventually
-    // allow a clean fix for this.
     MOZ_RELEASE_ASSERT(
-      RotateRight(uint64_t(LittleEndian::readUintptr(&unsigned_bytes[0])), 5) ==
-      RotateRight(0x0807060504030201ULL, 5));
+      LittleEndian::readUintptr(&unsigned_bytes[0]) ==
+      static_cast<uintptr_t>(0x0807060504030201ULL));
     MOZ_RELEASE_ASSERT(
-      RotateRight(uint64_t(BigEndian::readUintptr(&unsigned_bytes[0])), 5) ==
-      RotateRight(0x0102030405060708ULL, 5));
+      BigEndian::readUintptr(&unsigned_bytes[0]) ==
+      static_cast<uintptr_t>(0x0102030405060708ULL));
   } else {
     MOZ_RELEASE_ASSERT(
       LittleEndian::readUintptr(&unsigned_bytes[0]) == 0x04030201U);
     MOZ_RELEASE_ASSERT(
       BigEndian::readUintptr(&unsigned_bytes[0]) == 0x01020304U);
   }
 
   LittleEndian::writeUint16(&buffer[0], 0x0201);