Bug 1540357 - Fix implicit int truncation in dom/canvas's mfbt/* includes. r=froydnj
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 02 Apr 2019 17:00:53 +0000
changeset 467637 093c37e856fbcfa76a3ae067fbd99278303b62b9
parent 467636 54d64288d7de94ed6ea0f1f6e5be9bdb605e3a29
child 467638 9cbe81319d8704833d63598994f716c583556ccd
push id112638
push userdvarga@mozilla.com
push dateWed, 03 Apr 2019 06:18:49 +0000
treeherdermozilla-inbound@7dd52a4bdab5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1540357
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1540357 - Fix implicit int truncation in dom/canvas's mfbt/* includes. r=froydnj Depends on D25500 Differential Revision: https://phabricator.services.mozilla.com/D25501
mfbt/EnumSet.h
mfbt/MathAlgorithms.h
--- a/mfbt/EnumSet.h
+++ b/mfbt/EnumSet.h
@@ -276,17 +276,17 @@ class EnumSet {
   ConstIterator begin() const { return ConstIterator(*this, 0); }
 
   ConstIterator end() const { return ConstIterator(*this, kMaxBits); }
 
  private:
   constexpr static Serialized bitFor(T aEnum) {
     auto bitNumber = static_cast<Serialized>(aEnum);
     MOZ_DIAGNOSTIC_ASSERT(bitNumber < kMaxBits);
-    return Serialized(1) << bitNumber;
+    return static_cast<Serialized>(Serialized{1} << bitNumber);
   }
 
   constexpr void incVersion() {
 #ifdef DEBUG
     mVersion++;
 #endif
   }
 
--- a/mfbt/MathAlgorithms.h
+++ b/mfbt/MathAlgorithms.h
@@ -255,37 +255,37 @@ inline uint_fast8_t CountTrailingZeroes6
 #    if !__has_builtin(__builtin_ctz) || !__has_builtin(__builtin_clz)
 #      error "A clang providing __builtin_c[lt]z is required to build"
 #    endif
 #  else
 // gcc has had __builtin_clz and friends since 3.4: no need to check.
 #  endif
 
 inline uint_fast8_t CountLeadingZeroes32(uint32_t aValue) {
-  return __builtin_clz(aValue);
+  return static_cast<uint_fast8_t>(__builtin_clz(aValue));
 }
 
 inline uint_fast8_t CountTrailingZeroes32(uint32_t aValue) {
-  return __builtin_ctz(aValue);
+  return static_cast<uint_fast8_t>(__builtin_ctz(aValue));
 }
 
 inline uint_fast8_t CountPopulation32(uint32_t aValue) {
-  return __builtin_popcount(aValue);
+  return static_cast<uint_fast8_t>(__builtin_popcount(aValue));
 }
 
 inline uint_fast8_t CountPopulation64(uint64_t aValue) {
-  return __builtin_popcountll(aValue);
+  return static_cast<uint_fast8_t>(__builtin_popcountll(aValue));
 }
 
 inline uint_fast8_t CountLeadingZeroes64(uint64_t aValue) {
-  return __builtin_clzll(aValue);
+  return static_cast<uint_fast8_t>(__builtin_clzll(aValue));
 }
 
 inline uint_fast8_t CountTrailingZeroes64(uint64_t aValue) {
-  return __builtin_ctzll(aValue);
+  return static_cast<uint_fast8_t>(__builtin_ctzll(aValue));
 }
 
 #else
 #  error "Implement these!"
 inline uint_fast8_t CountLeadingZeroes32(uint32_t aValue) = delete;
 inline uint_fast8_t CountTrailingZeroes32(uint32_t aValue) = delete;
 inline uint_fast8_t CountPopulation32(uint32_t aValue) = delete;
 inline uint_fast8_t CountPopulation64(uint64_t aValue) = delete;