Open Bug 828741 Opened 12 years ago Updated 3 years ago

CheckedInt.h IsInRangeImpl() warning: logical 'and' of mutually exclusive tests is always false

Categories

(Core :: MFBT, defect)

ARM
Android
defect

Tracking

()

People

(Reporter: cpeterson, Unassigned)

References

Details

When compiling Firefox for Android with NDK r8c's gcc 4.6 (and manually adding -Wlogical-op to my mozconfig's CXXFLAGS), I get the following warning from CheckedInt.h. gcc warns that the expression `x >= 0 && x <= U(MaxValue<T>::value)` is a "logical 'and' of mutually exclusive tests is always false" when T = unsigned int, U = int, and x = 2. If I am reading the code correctly, this expression becomes `2 >= 0 and 2 <= int(uint32_t(~0))` which is `2 >= 0 && 2 <= -1`. In file included from mozilla/inbound/content/base/src/nsDOMBlobBuilder.h:11:0, from xmozilla/inbound/js/xpconnect/loader/mozJSComponentLoader.cpp:46: ../../../dist/include/mozilla/CheckedInt.h: In static member function 'static bool mozilla::detail::IsInRangeImpl<T, U, false, true, false>::run(U) [with T = unsigned int, U = int]': ../../../dist/include/mozilla/CheckedInt.h:355:36: instantiated from 'bool mozilla::detail::IsInRange(U) [with T = unsigned int, U = int]' ../../../dist/include/mozilla/CheckedInt.h:579:45: instantiated from 'mozilla::CheckedInt<T>::CheckedInt(U) [with U = int, T = unsigned int]' ../../../dist/include/mozilla/CheckedInt.h:743:44: instantiated from 'static mozilla::CheckedInt<T> mozilla::detail::CastToCheckedIntImpl<T, U>::run(U) [with T = unsigned int, U = int]' ../../../dist/include/mozilla/CheckedInt.h:759:51: instantiated from 'typename mozilla::detail::CastToCheckedIntImpl<T, U>::ReturnType mozilla::castToCheckedInt(U) [with T = unsigned int, U = int, typename mozilla::detail::CastToCheckedIntImpl<T, U>::ReturnType = mozilla::CheckedInt<unsigned int>]' ../../../dist/include/mozilla/CheckedInt.h:782:94: instantiated from 'mozilla::CheckedInt<T>& mozilla::CheckedInt<T>::operator*=(U) [with U = int, T = unsigned int]' mozilla/inbound/content/base/src/nsDOMBlobBuilder.h:131:20: instantiated from here ../../../dist/include/mozilla/CheckedInt.h:347:51: warning: logical 'and' of mutually exclusive tests is always false [-Wlogical-op]
(In reply to Chris Peterson (:cpeterson) from comment #0) > gcc warns that the expression `x >= 0 && x <= U(MaxValue<T>::value)` is a > "logical 'and' of mutually exclusive tests is always false" when T = > unsigned int, U = int, and x = 2. If I am reading the code correctly, this > expression becomes `2 >= 0 and 2 <= int(uint32_t(~0))` which is `2 >= 0 && 2 > <= -1`. int(uint32_t(~0)) is int(value greater than int range), and cast to signed int has defined behavior only when the input value is within the range of the target type. So there might be two issues here, possibly, or something (I'm only skimming here).
Blocks: 829344

I guess this refers to what's https://searchfox.org/mozilla-central/rev/ffdb6a4d934b3f5294f18cf0e1df618109ccb36b/mfbt/CheckedInt.h#263 now. Even though this changed from using MaxValue to std::numeric_limits, the underlying issue seems to persist.

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.