| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/3rdparty/masm/wtf/CheckedArithmetic.h |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | namespace WTF { | - | ||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | enum class CheckedState | - | ||||||||||||||||||||||||
| 4 | { | - | ||||||||||||||||||||||||
| 5 | DidOverflow, | - | ||||||||||||||||||||||||
| 6 | DidNotOverflow | - | ||||||||||||||||||||||||
| 7 | } ; | - | ||||||||||||||||||||||||
| 8 | - | |||||||||||||||||||||||||
| 9 | class CrashOnOverflow { | - | ||||||||||||||||||||||||
| 10 | public: | - | ||||||||||||||||||||||||
| 11 | static void overflowed() | - | ||||||||||||||||||||||||
| 12 | { | - | ||||||||||||||||||||||||
| 13 | (qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap()); | - | ||||||||||||||||||||||||
| 14 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 15 | - | |||||||||||||||||||||||||
| 16 | void clearOverflow() { } | - | ||||||||||||||||||||||||
| 17 | - | |||||||||||||||||||||||||
| 18 | public: | - | ||||||||||||||||||||||||
| 19 | bool hasOverflowed() const { return executed 16160016 times by 153 tests: false;return false;Executed by:
executed 16160016 times by 153 tests: }return false;Executed by:
| 16160016 | ||||||||||||||||||||||||
| 20 | }; | - | ||||||||||||||||||||||||
| 21 | - | |||||||||||||||||||||||||
| 22 | class RecordOverflow { | - | ||||||||||||||||||||||||
| 23 | protected: | - | ||||||||||||||||||||||||
| 24 | RecordOverflow() | - | ||||||||||||||||||||||||
| 25 | : m_overflowed(false) | - | ||||||||||||||||||||||||
| 26 | { | - | ||||||||||||||||||||||||
| 27 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 28 | - | |||||||||||||||||||||||||
| 29 | void overflowed() | - | ||||||||||||||||||||||||
| 30 | { | - | ||||||||||||||||||||||||
| 31 | m_overflowed = true; | - | ||||||||||||||||||||||||
| 32 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||
| 34 | void clearOverflow() | - | ||||||||||||||||||||||||
| 35 | { | - | ||||||||||||||||||||||||
| 36 | m_overflowed = false; | - | ||||||||||||||||||||||||
| 37 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 38 | - | |||||||||||||||||||||||||
| 39 | public: | - | ||||||||||||||||||||||||
| 40 | bool hasOverflowed() const { return never executed: m_overflowed;return m_overflowed;never executed: }return m_overflowed; | 0 | ||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | private: | - | ||||||||||||||||||||||||
| 43 | unsigned char m_overflowed; | - | ||||||||||||||||||||||||
| 44 | }; | - | ||||||||||||||||||||||||
| 45 | - | |||||||||||||||||||||||||
| 46 | template <typename T, class OverflowHandler = CrashOnOverflow> class Checked; | - | ||||||||||||||||||||||||
| 47 | template <typename T> struct RemoveChecked; | - | ||||||||||||||||||||||||
| 48 | template <typename T> struct RemoveChecked<Checked<T> >; | - | ||||||||||||||||||||||||
| 49 | - | |||||||||||||||||||||||||
| 50 | template <typename Target, typename Source, bool targetSigned = std::numeric_limits<Target>::is_signed, bool sourceSigned = std::numeric_limits<Source>::is_signed> struct BoundsChecker; | - | ||||||||||||||||||||||||
| 51 | template <typename Target, typename Source> struct BoundsChecker<Target, Source, false, false> { | - | ||||||||||||||||||||||||
| 52 | static bool inBounds(Source value) | - | ||||||||||||||||||||||||
| 53 | { | - | ||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | return never executed: value <= std::numeric_limits<Target>::max();return value <= std::numeric_limits<Target>::max();never executed: return value <= std::numeric_limits<Target>::max(); | 0 | ||||||||||||||||||||||||
| 57 | } | - | ||||||||||||||||||||||||
| 58 | }; | - | ||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||
| 60 | template <typename Target, typename Source> struct BoundsChecker<Target, Source, true, true> { | - | ||||||||||||||||||||||||
| 61 | static bool inBounds(Source value) | - | ||||||||||||||||||||||||
| 62 | { | - | ||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||
| 65 | return executed 325 times by 3 tests: std::numeric_limits<Target>::min() <= value && value <= std::numeric_limits<Target>::max();return std::numeric_limits<Target>::min() <= value && value <= std::numeric_limits<Target>::max();Executed by:
executed 325 times by 3 tests: return std::numeric_limits<Target>::min() <= value && value <= std::numeric_limits<Target>::max();Executed by:
| 325 | ||||||||||||||||||||||||
| 66 | } | - | ||||||||||||||||||||||||
| 67 | }; | - | ||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | template <typename Target, typename Source> struct BoundsChecker<Target, Source, false, true> { | - | ||||||||||||||||||||||||
| 70 | static bool inBounds(Source value) | - | ||||||||||||||||||||||||
| 71 | { | - | ||||||||||||||||||||||||
| 72 | - | |||||||||||||||||||||||||
| 73 | if (value < 0
| 0-2379627 | ||||||||||||||||||||||||
| 74 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||
| 77 | if (sizeof(Target) >= sizeof(Source)
| 0-2379720 | ||||||||||||||||||||||||
| 78 | return executed 2379713 times by 9 tests: static_cast<Target>(value) <= std::numeric_limits<Target>::max();return static_cast<Target>(value) <= std::numeric_limits<Target>::max();Executed by:
executed 2379713 times by 9 tests: return static_cast<Target>(value) <= std::numeric_limits<Target>::max();Executed by:
| 2379713 | ||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||
| 80 | - | |||||||||||||||||||||||||
| 81 | return never executed: value <= static_cast<Source>(std::numeric_limits<Target>::max());return value <= static_cast<Source>(std::numeric_limits<Target>::max());never executed: return value <= static_cast<Source>(std::numeric_limits<Target>::max()); | 0 | ||||||||||||||||||||||||
| 82 | } | - | ||||||||||||||||||||||||
| 83 | }; | - | ||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||
| 85 | template <typename Target, typename Source> struct BoundsChecker<Target, Source, true, false> { | - | ||||||||||||||||||||||||
| 86 | static bool inBounds(Source value) | - | ||||||||||||||||||||||||
| 87 | { | - | ||||||||||||||||||||||||
| 88 | - | |||||||||||||||||||||||||
| 89 | if (sizeof(Target) <= sizeof(Source)
| 0 | ||||||||||||||||||||||||
| 90 | return never executed: value <= static_cast<Source>(std::numeric_limits<Target>::max());return value <= static_cast<Source>(std::numeric_limits<Target>::max());never executed: return value <= static_cast<Source>(std::numeric_limits<Target>::max()); | 0 | ||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | - | |||||||||||||||||||||||||
| 93 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 94 | } | - | ||||||||||||||||||||||||
| 95 | }; | - | ||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | template <typename Target, typename Source, bool CanElide = IsSameType<Target, Source>::value || (sizeof(Target) > sizeof(Source)) > struct BoundsCheckElider; | - | ||||||||||||||||||||||||
| 98 | template <typename Target, typename Source> struct BoundsCheckElider<Target, Source, true> { | - | ||||||||||||||||||||||||
| 99 | static bool inBounds(Source) { return executed 3472520 times by 153 tests: true;return true;Executed by:
executed 3472520 times by 153 tests: }return true;Executed by:
| 3472520 | ||||||||||||||||||||||||
| 100 | }; | - | ||||||||||||||||||||||||
| 101 | template <typename Target, typename Source> struct BoundsCheckElider<Target, Source, false> : public BoundsChecker<Target, Source> { | - | ||||||||||||||||||||||||
| 102 | }; | - | ||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||
| 104 | template <typename Target, typename Source> static inline bool isInBounds(Source value) | - | ||||||||||||||||||||||||
| 105 | { | - | ||||||||||||||||||||||||
| 106 | return executed 5851156 times by 153 tests: BoundsCheckElider<Target, Source>::inBounds(value);return BoundsCheckElider<Target, Source>::inBounds(value);Executed by:
executed 5851156 times by 153 tests: return BoundsCheckElider<Target, Source>::inBounds(value);Executed by:
| 5851156 | ||||||||||||||||||||||||
| 107 | } | - | ||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||
| 109 | template <typename T> struct RemoveChecked { | - | ||||||||||||||||||||||||
| 110 | typedef T CleanType; | - | ||||||||||||||||||||||||
| 111 | static const CleanType DefaultValue = 0; | - | ||||||||||||||||||||||||
| 112 | }; | - | ||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||
| 114 | template <typename T> struct RemoveChecked<Checked<T, CrashOnOverflow> > { | - | ||||||||||||||||||||||||
| 115 | typedef typename RemoveChecked<T>::CleanType CleanType; | - | ||||||||||||||||||||||||
| 116 | static const CleanType DefaultValue = 0; | - | ||||||||||||||||||||||||
| 117 | }; | - | ||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||
| 119 | template <typename T> struct RemoveChecked<Checked<T, RecordOverflow> > { | - | ||||||||||||||||||||||||
| 120 | typedef typename RemoveChecked<T>::CleanType CleanType; | - | ||||||||||||||||||||||||
| 121 | static const CleanType DefaultValue = 0; | - | ||||||||||||||||||||||||
| 122 | }; | - | ||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||
| 125 | - | |||||||||||||||||||||||||
| 126 | template <typename U, typename V, bool uIsBigger = (sizeof(U) > sizeof(V)), bool sameSize = (sizeof(U) == sizeof(V))> struct ResultBase; | - | ||||||||||||||||||||||||
| 127 | template <typename U, typename V> struct ResultBase<U, V, true, false> { | - | ||||||||||||||||||||||||
| 128 | typedef U ResultType; | - | ||||||||||||||||||||||||
| 129 | }; | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | template <typename U, typename V> struct ResultBase<U, V, false, false> { | - | ||||||||||||||||||||||||
| 132 | typedef V ResultType; | - | ||||||||||||||||||||||||
| 133 | }; | - | ||||||||||||||||||||||||
| 134 | - | |||||||||||||||||||||||||
| 135 | template <typename U> struct ResultBase<U, U, false, true> { | - | ||||||||||||||||||||||||
| 136 | typedef U ResultType; | - | ||||||||||||||||||||||||
| 137 | }; | - | ||||||||||||||||||||||||
| 138 | - | |||||||||||||||||||||||||
| 139 | template <typename U, typename V, bool uIsSigned = std::numeric_limits<U>::is_signed, bool vIsSigned = std::numeric_limits<V>::is_signed> struct SignednessSelector; | - | ||||||||||||||||||||||||
| 140 | template <typename U, typename V> struct SignednessSelector<U, V, true, true> { | - | ||||||||||||||||||||||||
| 141 | typedef U ResultType; | - | ||||||||||||||||||||||||
| 142 | }; | - | ||||||||||||||||||||||||
| 143 | - | |||||||||||||||||||||||||
| 144 | template <typename U, typename V> struct SignednessSelector<U, V, false, false> { | - | ||||||||||||||||||||||||
| 145 | typedef U ResultType; | - | ||||||||||||||||||||||||
| 146 | }; | - | ||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||
| 148 | template <typename U, typename V> struct SignednessSelector<U, V, true, false> { | - | ||||||||||||||||||||||||
| 149 | typedef V ResultType; | - | ||||||||||||||||||||||||
| 150 | }; | - | ||||||||||||||||||||||||
| 151 | - | |||||||||||||||||||||||||
| 152 | template <typename U, typename V> struct SignednessSelector<U, V, false, true> { | - | ||||||||||||||||||||||||
| 153 | typedef U ResultType; | - | ||||||||||||||||||||||||
| 154 | }; | - | ||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||
| 156 | template <typename U, typename V> struct ResultBase<U, V, false, true> { | - | ||||||||||||||||||||||||
| 157 | typedef typename SignednessSelector<U, V>::ResultType ResultType; | - | ||||||||||||||||||||||||
| 158 | }; | - | ||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||
| 160 | template <typename U, typename V> struct Result : ResultBase<typename RemoveChecked<U>::CleanType, typename RemoveChecked<V>::CleanType> { | - | ||||||||||||||||||||||||
| 161 | }; | - | ||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||
| 163 | template <typename LHS, typename RHS, typename ResultType = typename Result<LHS, RHS>::ResultType, | - | ||||||||||||||||||||||||
| 164 | bool lhsSigned = std::numeric_limits<LHS>::is_signed, bool rhsSigned = std::numeric_limits<RHS>::is_signed> struct ArithmeticOperations; | - | ||||||||||||||||||||||||
| 165 | - | |||||||||||||||||||||||||
| 166 | template <typename LHS, typename RHS, typename ResultType> struct ArithmeticOperations<LHS, RHS, ResultType, true, true> { | - | ||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | - | |||||||||||||||||||||||||
| 170 | static inline bool signsMatch(LHS lhs, RHS rhs) | - | ||||||||||||||||||||||||
| 171 | { | - | ||||||||||||||||||||||||
| 172 | return executed 647 times by 3 tests: (lhs ^ rhs) >= 0;return (lhs ^ rhs) >= 0;Executed by:
executed 647 times by 3 tests: return (lhs ^ rhs) >= 0;Executed by:
| 647 | ||||||||||||||||||||||||
| 173 | } | - | ||||||||||||||||||||||||
| 174 | - | |||||||||||||||||||||||||
| 175 | static inline bool add(LHS lhs, RHS rhs, ResultType& result) __attribute__ ((warn_unused_result)) | - | ||||||||||||||||||||||||
| 176 | { | - | ||||||||||||||||||||||||
| 177 | if (signsMatch(lhs, rhs)
| 0-326 | ||||||||||||||||||||||||
| 178 | if (lhs >= 0
| 0 | ||||||||||||||||||||||||
| 179 | if ((
| 0 | ||||||||||||||||||||||||
| 180 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 181 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 182 | ResultType temp = lhs - std::numeric_limits<ResultType>::min(); | - | ||||||||||||||||||||||||
| 183 | if (rhs < -temp
| 0 | ||||||||||||||||||||||||
| 184 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 185 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 186 | } | - | ||||||||||||||||||||||||
| 187 | result = lhs + rhs; | - | ||||||||||||||||||||||||
| 188 | return executed 323 times by 3 tests: true;return true;Executed by:
executed 323 times by 3 tests: return true;Executed by:
| 323 | ||||||||||||||||||||||||
| 189 | } | - | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | static inline bool sub(LHS lhs, RHS rhs, ResultType& result) __attribute__ ((warn_unused_result)) | - | ||||||||||||||||||||||||
| 192 | { | - | ||||||||||||||||||||||||
| 193 | if (!signsMatch(lhs, rhs)
| 0 | ||||||||||||||||||||||||
| 194 | if (lhs >= 0
| 0 | ||||||||||||||||||||||||
| 195 | if (lhs > std::numeric_limits<ResultType>::max() + rhs
| 0 | ||||||||||||||||||||||||
| 196 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 197 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 198 | if (rhs > std::numeric_limits<ResultType>::max() + lhs
| 0 | ||||||||||||||||||||||||
| 199 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 200 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 201 | } | - | ||||||||||||||||||||||||
| 202 | result = lhs - rhs; | - | ||||||||||||||||||||||||
| 203 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 204 | } | - | ||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||
| 206 | static inline bool multiply(LHS lhs, RHS rhs, ResultType& result) __attribute__ ((warn_unused_result)) | - | ||||||||||||||||||||||||
| 207 | { | - | ||||||||||||||||||||||||
| 208 | if (signsMatch(lhs, rhs)
| 92-230 | ||||||||||||||||||||||||
| 209 | if (lhs >= 0
| 0-233 | ||||||||||||||||||||||||
| 210 | if (lhs
| 0-230 | ||||||||||||||||||||||||
| 211 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 212 | } executed 230 times by 3 tests: else {end of blockExecuted by:
| 230 | ||||||||||||||||||||||||
| 213 | if (static_cast<
| 0 | ||||||||||||||||||||||||
| 214 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 215 | if ((
| 0 | ||||||||||||||||||||||||
| 216 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 217 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 218 | } else { | - | ||||||||||||||||||||||||
| 219 | if (lhs < 0
| 0-92 | ||||||||||||||||||||||||
| 220 | if (rhs
| 0-92 | ||||||||||||||||||||||||
| 221 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 222 | } executed 92 times by 1 test: else {end of blockExecuted by:
| 92 | ||||||||||||||||||||||||
| 223 | if (lhs
| 0 | ||||||||||||||||||||||||
| 224 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 225 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 226 | } | - | ||||||||||||||||||||||||
| 227 | result = lhs * rhs; | - | ||||||||||||||||||||||||
| 228 | return executed 322 times by 3 tests: true;return true;Executed by:
executed 322 times by 3 tests: return true;Executed by:
| 322 | ||||||||||||||||||||||||
| 229 | } | - | ||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||
| 231 | static inline bool equals(LHS lhs, RHS rhs) { return never executed: lhs == rhs;return lhs == rhs;never executed: }return lhs == rhs; | 0 | ||||||||||||||||||||||||
| 232 | - | |||||||||||||||||||||||||
| 233 | }; | - | ||||||||||||||||||||||||
| 234 | - | |||||||||||||||||||||||||
| 235 | template <typename LHS, typename RHS, typename ResultType> struct ArithmeticOperations<LHS, RHS, ResultType, false, false> { | - | ||||||||||||||||||||||||
| 236 | - | |||||||||||||||||||||||||
| 237 | static inline bool add(LHS lhs, RHS rhs, ResultType& result) __attribute__ ((warn_unused_result)) | - | ||||||||||||||||||||||||
| 238 | { | - | ||||||||||||||||||||||||
| 239 | ResultType temp = lhs + rhs; | - | ||||||||||||||||||||||||
| 240 | if (temp < lhs
| 0-2374303 | ||||||||||||||||||||||||
| 241 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 242 | result = temp; | - | ||||||||||||||||||||||||
| 243 | return executed 2374285 times by 9 tests: true;return true;Executed by:
executed 2374285 times by 9 tests: return true;Executed by:
| 2374285 | ||||||||||||||||||||||||
| 244 | } | - | ||||||||||||||||||||||||
| 245 | - | |||||||||||||||||||||||||
| 246 | static inline bool sub(LHS lhs, RHS rhs, ResultType& result) __attribute__ ((warn_unused_result)) | - | ||||||||||||||||||||||||
| 247 | { | - | ||||||||||||||||||||||||
| 248 | ResultType temp = lhs - rhs; | - | ||||||||||||||||||||||||
| 249 | if (temp > lhs
| 0-1154659 | ||||||||||||||||||||||||
| 250 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 251 | result = temp; | - | ||||||||||||||||||||||||
| 252 | return executed 1154827 times by 153 tests: true;return true;Executed by:
executed 1154827 times by 153 tests: return true;Executed by:
| 1154827 | ||||||||||||||||||||||||
| 253 | } | - | ||||||||||||||||||||||||
| 254 | - | |||||||||||||||||||||||||
| 255 | static inline bool multiply(LHS lhs, RHS rhs, ResultType& result) __attribute__ ((warn_unused_result)) | - | ||||||||||||||||||||||||
| 256 | { | - | ||||||||||||||||||||||||
| 257 | if (!lhs
| 0 | ||||||||||||||||||||||||
| 258 | result = 0; | - | ||||||||||||||||||||||||
| 259 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 260 | } | - | ||||||||||||||||||||||||
| 261 | if (std::numeric_limits<ResultType>::max() / lhs < rhs
| 0 | ||||||||||||||||||||||||
| 262 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 263 | result = lhs * rhs; | - | ||||||||||||||||||||||||
| 264 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 265 | } | - | ||||||||||||||||||||||||
| 266 | - | |||||||||||||||||||||||||
| 267 | static inline bool equals(LHS lhs, RHS rhs) { return executed 2199 times by 8 tests: lhs == rhs;return lhs == rhs;Executed by:
executed 2199 times by 8 tests: }return lhs == rhs;Executed by:
| 2199 | ||||||||||||||||||||||||
| 268 | - | |||||||||||||||||||||||||
| 269 | }; | - | ||||||||||||||||||||||||
| 270 | - | |||||||||||||||||||||||||
| 271 | template <typename ResultType> struct ArithmeticOperations<int, unsigned, ResultType, true, false> { | - | ||||||||||||||||||||||||
| 272 | static inline bool add(int64_t lhs, int64_t rhs, ResultType& result) | - | ||||||||||||||||||||||||
| 273 | { | - | ||||||||||||||||||||||||
| 274 | int64_t temp = lhs + rhs; | - | ||||||||||||||||||||||||
| 275 | if (temp < std::numeric_limits<ResultType>::min()
| 0 | ||||||||||||||||||||||||
| 276 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 277 | if (temp > std::numeric_limits<ResultType>::max()
| 0 | ||||||||||||||||||||||||
| 278 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 279 | result = static_cast<ResultType>(temp); | - | ||||||||||||||||||||||||
| 280 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 281 | } | - | ||||||||||||||||||||||||
| 282 | - | |||||||||||||||||||||||||
| 283 | static inline bool sub(int64_t lhs, int64_t rhs, ResultType& result) | - | ||||||||||||||||||||||||
| 284 | { | - | ||||||||||||||||||||||||
| 285 | int64_t temp = lhs - rhs; | - | ||||||||||||||||||||||||
| 286 | if (temp < std::numeric_limits<ResultType>::min()
| 0 | ||||||||||||||||||||||||
| 287 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 288 | if (temp > std::numeric_limits<ResultType>::max()
| 0 | ||||||||||||||||||||||||
| 289 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 290 | result = static_cast<ResultType>(temp); | - | ||||||||||||||||||||||||
| 291 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 292 | } | - | ||||||||||||||||||||||||
| 293 | - | |||||||||||||||||||||||||
| 294 | static inline bool multiply(int64_t lhs, int64_t rhs, ResultType& result) | - | ||||||||||||||||||||||||
| 295 | { | - | ||||||||||||||||||||||||
| 296 | int64_t temp = lhs * rhs; | - | ||||||||||||||||||||||||
| 297 | if (temp < std::numeric_limits<ResultType>::min()
| 0 | ||||||||||||||||||||||||
| 298 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 299 | if (temp > std::numeric_limits<ResultType>::max()
| 0 | ||||||||||||||||||||||||
| 300 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 301 | result = static_cast<ResultType>(temp); | - | ||||||||||||||||||||||||
| 302 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 303 | } | - | ||||||||||||||||||||||||
| 304 | - | |||||||||||||||||||||||||
| 305 | static inline bool equals(int lhs, unsigned rhs) | - | ||||||||||||||||||||||||
| 306 | { | - | ||||||||||||||||||||||||
| 307 | return executed 5548009 times by 9 tests: static_cast<int64_t>(lhs) == static_cast<int64_t>(rhs);return static_cast<int64_t>(lhs) == static_cast<int64_t>(rhs);Executed by:
executed 5548009 times by 9 tests: return static_cast<int64_t>(lhs) == static_cast<int64_t>(rhs);Executed by:
| 5548009 | ||||||||||||||||||||||||
| 308 | } | - | ||||||||||||||||||||||||
| 309 | }; | - | ||||||||||||||||||||||||
| 310 | - | |||||||||||||||||||||||||
| 311 | template <typename ResultType> struct ArithmeticOperations<unsigned, int, ResultType, false, true> { | - | ||||||||||||||||||||||||
| 312 | static inline bool add(int64_t lhs, int64_t rhs, ResultType& result) | - | ||||||||||||||||||||||||
| 313 | { | - | ||||||||||||||||||||||||
| 314 | return never executed: ArithmeticOperations<int, unsigned, ResultType>::add(rhs, lhs, result);return ArithmeticOperations<int, unsigned, ResultType>::add(rhs, lhs, result);never executed: return ArithmeticOperations<int, unsigned, ResultType>::add(rhs, lhs, result); | 0 | ||||||||||||||||||||||||
| 315 | } | - | ||||||||||||||||||||||||
| 316 | - | |||||||||||||||||||||||||
| 317 | static inline bool sub(int64_t lhs, int64_t rhs, ResultType& result) | - | ||||||||||||||||||||||||
| 318 | { | - | ||||||||||||||||||||||||
| 319 | return never executed: ArithmeticOperations<int, unsigned, ResultType>::sub(lhs, rhs, result);return ArithmeticOperations<int, unsigned, ResultType>::sub(lhs, rhs, result);never executed: return ArithmeticOperations<int, unsigned, ResultType>::sub(lhs, rhs, result); | 0 | ||||||||||||||||||||||||
| 320 | } | - | ||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | static inline bool multiply(int64_t lhs, int64_t rhs, ResultType& result) | - | ||||||||||||||||||||||||
| 323 | { | - | ||||||||||||||||||||||||
| 324 | return never executed: ArithmeticOperations<int, unsigned, ResultType>::multiply(rhs, lhs, result);return ArithmeticOperations<int, unsigned, ResultType>::multiply(rhs, lhs, result);never executed: return ArithmeticOperations<int, unsigned, ResultType>::multiply(rhs, lhs, result); | 0 | ||||||||||||||||||||||||
| 325 | } | - | ||||||||||||||||||||||||
| 326 | - | |||||||||||||||||||||||||
| 327 | static inline bool equals(unsigned lhs, int rhs) | - | ||||||||||||||||||||||||
| 328 | { | - | ||||||||||||||||||||||||
| 329 | return executed 5549732 times by 9 tests: ArithmeticOperations<int, unsigned, ResultType>::equals(rhs, lhs);return ArithmeticOperations<int, unsigned, ResultType>::equals(rhs, lhs);Executed by:
executed 5549732 times by 9 tests: return ArithmeticOperations<int, unsigned, ResultType>::equals(rhs, lhs);Executed by:
| 5549732 | ||||||||||||||||||||||||
| 330 | } | - | ||||||||||||||||||||||||
| 331 | }; | - | ||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||
| 333 | template <typename U, typename V, typename R> static inline bool safeAdd(U lhs, V rhs, R& result) | - | ||||||||||||||||||||||||
| 334 | { | - | ||||||||||||||||||||||||
| 335 | return executed 2374703 times by 9 tests: ArithmeticOperations<U, V, R>::add(lhs, rhs, result);return ArithmeticOperations<U, V, R>::add(lhs, rhs, result);Executed by:
executed 2374703 times by 9 tests: return ArithmeticOperations<U, V, R>::add(lhs, rhs, result);Executed by:
| 2374703 | ||||||||||||||||||||||||
| 336 | } | - | ||||||||||||||||||||||||
| 337 | - | |||||||||||||||||||||||||
| 338 | template <typename U, typename V, typename R> static inline bool safeSub(U lhs, V rhs, R& result) | - | ||||||||||||||||||||||||
| 339 | { | - | ||||||||||||||||||||||||
| 340 | return executed 1154956 times by 153 tests: ArithmeticOperations<U, V, R>::sub(lhs, rhs, result);return ArithmeticOperations<U, V, R>::sub(lhs, rhs, result);Executed by:
executed 1154956 times by 153 tests: return ArithmeticOperations<U, V, R>::sub(lhs, rhs, result);Executed by:
| 1154956 | ||||||||||||||||||||||||
| 341 | } | - | ||||||||||||||||||||||||
| 342 | - | |||||||||||||||||||||||||
| 343 | template <typename U, typename V, typename R> static inline bool safeMultiply(U lhs, V rhs, R& result) | - | ||||||||||||||||||||||||
| 344 | { | - | ||||||||||||||||||||||||
| 345 | return executed 324 times by 3 tests: ArithmeticOperations<U, V, R>::multiply(lhs, rhs, result);return ArithmeticOperations<U, V, R>::multiply(lhs, rhs, result);Executed by:
executed 324 times by 3 tests: return ArithmeticOperations<U, V, R>::multiply(lhs, rhs, result);Executed by:
| 324 | ||||||||||||||||||||||||
| 346 | } | - | ||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | template <typename U, typename V> static inline bool safeEquals(U lhs, V rhs) | - | ||||||||||||||||||||||||
| 349 | { | - | ||||||||||||||||||||||||
| 350 | return executed 5551264 times by 9 tests: ArithmeticOperations<U, V>::equals(lhs, rhs);return ArithmeticOperations<U, V>::equals(lhs, rhs);Executed by:
executed 5551264 times by 9 tests: return ArithmeticOperations<U, V>::equals(lhs, rhs);Executed by:
| 5551264 | ||||||||||||||||||||||||
| 351 | } | - | ||||||||||||||||||||||||
| 352 | - | |||||||||||||||||||||||||
| 353 | enum ResultOverflowedTag { ResultOverflowed }; | - | ||||||||||||||||||||||||
| 354 | - | |||||||||||||||||||||||||
| 355 | - | |||||||||||||||||||||||||
| 356 | static inline bool workAroundClangBug() { return never executed: true;return true;never executed: }return true; | 0 | ||||||||||||||||||||||||
| 357 | - | |||||||||||||||||||||||||
| 358 | template <typename T, class OverflowHandler> class Checked : public OverflowHandler { | - | ||||||||||||||||||||||||
| 359 | public: | - | ||||||||||||||||||||||||
| 360 | template <typename _T, class _OverflowHandler> friend class Checked; | - | ||||||||||||||||||||||||
| 361 | Checked() | - | ||||||||||||||||||||||||
| 362 | : m_value(0) | - | ||||||||||||||||||||||||
| 363 | { | - | ||||||||||||||||||||||||
| 364 | } executed 2379668 times by 9 tests: end of blockExecuted by:
| 2379668 | ||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||
| 366 | Checked(ResultOverflowedTag) | - | ||||||||||||||||||||||||
| 367 | : m_value(0) | - | ||||||||||||||||||||||||
| 368 | { | - | ||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||
| 370 | if (workAroundClangBug()
| 0 | ||||||||||||||||||||||||
| 371 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 372 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 373 | - | |||||||||||||||||||||||||
| 374 | template <typename U> Checked(U value) | - | ||||||||||||||||||||||||
| 375 | { | - | ||||||||||||||||||||||||
| 376 | if (!isInBounds<T>(value)
| 0-5851402 | ||||||||||||||||||||||||
| 377 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 378 | m_value = static_cast<T>(value); | - | ||||||||||||||||||||||||
| 379 | } executed 5851010 times by 153 tests: end of blockExecuted by:
| 5851010 | ||||||||||||||||||||||||
| 380 | - | |||||||||||||||||||||||||
| 381 | template <typename V> Checked(const Checked<T, V>& rhs) | - | ||||||||||||||||||||||||
| 382 | : m_value(rhs.m_value) | - | ||||||||||||||||||||||||
| 383 | { | - | ||||||||||||||||||||||||
| 384 | if (rhs.hasOverflowed()
| 0 | ||||||||||||||||||||||||
| 385 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 386 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 387 | - | |||||||||||||||||||||||||
| 388 | template <typename U> Checked(const Checked<U, OverflowHandler>& rhs) | - | ||||||||||||||||||||||||
| 389 | : OverflowHandler(rhs) | - | ||||||||||||||||||||||||
| 390 | { | - | ||||||||||||||||||||||||
| 391 | if (!isInBounds<T>(rhs.m_value)
| 0-649 | ||||||||||||||||||||||||
| 392 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 393 | m_value = static_cast<T>(rhs.m_value); | - | ||||||||||||||||||||||||
| 394 | } executed 650 times by 3 tests: end of blockExecuted by:
| 650 | ||||||||||||||||||||||||
| 395 | - | |||||||||||||||||||||||||
| 396 | template <typename U, typename V> Checked(const Checked<U, V>& rhs) | - | ||||||||||||||||||||||||
| 397 | { | - | ||||||||||||||||||||||||
| 398 | if (rhs.hasOverflowed()
| 0 | ||||||||||||||||||||||||
| 399 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 400 | if (!isInBounds<T>(rhs.m_value)
| 0 | ||||||||||||||||||||||||
| 401 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 402 | m_value = static_cast<T>(rhs.m_value); | - | ||||||||||||||||||||||||
| 403 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 404 | - | |||||||||||||||||||||||||
| 405 | const Checked& operator=(Checked rhs) | - | ||||||||||||||||||||||||
| 406 | { | - | ||||||||||||||||||||||||
| 407 | this->clearOverflow(); | - | ||||||||||||||||||||||||
| 408 | if (rhs.hasOverflowed()
| 0-2386172 | ||||||||||||||||||||||||
| 409 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 410 | m_value = static_cast<T>(rhs.m_value); | - | ||||||||||||||||||||||||
| 411 | return executed 2386201 times by 9 tests: *this;return *this;Executed by:
executed 2386201 times by 9 tests: return *this;Executed by:
| 2386201 | ||||||||||||||||||||||||
| 412 | } | - | ||||||||||||||||||||||||
| 413 | - | |||||||||||||||||||||||||
| 414 | template <typename U> const Checked& operator=(U value) | - | ||||||||||||||||||||||||
| 415 | { | - | ||||||||||||||||||||||||
| 416 | return executed 2384862 times by 9 tests: *this = Checked(value);return *this = Checked(value);Executed by:
executed 2384862 times by 9 tests: return *this = Checked(value);Executed by:
| 2384862 | ||||||||||||||||||||||||
| 417 | } | - | ||||||||||||||||||||||||
| 418 | - | |||||||||||||||||||||||||
| 419 | template <typename U, typename V> const Checked& operator=(const Checked<U, V>& rhs) | - | ||||||||||||||||||||||||
| 420 | { | - | ||||||||||||||||||||||||
| 421 | return never executed: *this = Checked(rhs);return *this = Checked(rhs);never executed: return *this = Checked(rhs); | 0 | ||||||||||||||||||||||||
| 422 | } | - | ||||||||||||||||||||||||
| 423 | - | |||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||
| 425 | const Checked& operator++() | - | ||||||||||||||||||||||||
| 426 | { | - | ||||||||||||||||||||||||
| 427 | if (m_value == std::numeric_limits<T>::max()
| 0 | ||||||||||||||||||||||||
| 428 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 429 | m_value++; | - | ||||||||||||||||||||||||
| 430 | return never executed: *this;return *this;never executed: return *this; | 0 | ||||||||||||||||||||||||
| 431 | } | - | ||||||||||||||||||||||||
| 432 | - | |||||||||||||||||||||||||
| 433 | const Checked& operator--() | - | ||||||||||||||||||||||||
| 434 | { | - | ||||||||||||||||||||||||
| 435 | if (m_value == std::numeric_limits<T>::min()
| 0 | ||||||||||||||||||||||||
| 436 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 437 | m_value--; | - | ||||||||||||||||||||||||
| 438 | return never executed: *this;return *this;never executed: return *this; | 0 | ||||||||||||||||||||||||
| 439 | } | - | ||||||||||||||||||||||||
| 440 | - | |||||||||||||||||||||||||
| 441 | - | |||||||||||||||||||||||||
| 442 | const Checked operator++(int) | - | ||||||||||||||||||||||||
| 443 | { | - | ||||||||||||||||||||||||
| 444 | if (m_value == std::numeric_limits<T>::max()
| 0 | ||||||||||||||||||||||||
| 445 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 446 | return never executed: Checked(m_value++);return Checked(m_value++);never executed: return Checked(m_value++); | 0 | ||||||||||||||||||||||||
| 447 | } | - | ||||||||||||||||||||||||
| 448 | - | |||||||||||||||||||||||||
| 449 | const Checked operator--(int) | - | ||||||||||||||||||||||||
| 450 | { | - | ||||||||||||||||||||||||
| 451 | if (m_value == std::numeric_limits<T>::min()
| 0 | ||||||||||||||||||||||||
| 452 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 453 | return never executed: Checked(m_value--);return Checked(m_value--);never executed: return Checked(m_value--); | 0 | ||||||||||||||||||||||||
| 454 | } | - | ||||||||||||||||||||||||
| 455 | - | |||||||||||||||||||||||||
| 456 | - | |||||||||||||||||||||||||
| 457 | bool operator!() const | - | ||||||||||||||||||||||||
| 458 | { | - | ||||||||||||||||||||||||
| 459 | if (this->hasOverflowed()
| 0 | ||||||||||||||||||||||||
| 460 | ( never executed: qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap());(qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap());never executed: (qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap()); | 0 | ||||||||||||||||||||||||
| 461 | return never executed: !m_value;return !m_value;never executed: return !m_value; | 0 | ||||||||||||||||||||||||
| 462 | } | - | ||||||||||||||||||||||||
| 463 | - | |||||||||||||||||||||||||
| 464 | typedef void* (Checked::*UnspecifiedBoolType); | - | ||||||||||||||||||||||||
| 465 | operator UnspecifiedBoolType*() const | - | ||||||||||||||||||||||||
| 466 | { | - | ||||||||||||||||||||||||
| 467 | if (this->hasOverflowed()
| 0 | ||||||||||||||||||||||||
| 468 | ( never executed: qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap());(qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap());never executed: (qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap()); | 0 | ||||||||||||||||||||||||
| 469 | return never executed: (m_value) ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0;return (m_value) ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0;never executed: return (m_value) ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0; | 0 | ||||||||||||||||||||||||
| 470 | } | - | ||||||||||||||||||||||||
| 471 | - | |||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | T unsafeGet() const | - | ||||||||||||||||||||||||
| 474 | { | - | ||||||||||||||||||||||||
| 475 | if (this->hasOverflowed()
| 0-3545872 | ||||||||||||||||||||||||
| 476 | ( never executed: qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap());(qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap());never executed: (qmlWTFReportBacktrace(), qmlWTFInvokeCrashHook(), (*(int *)(uintptr_t)0xbbadbeef = 0), __builtin_trap()); | 0 | ||||||||||||||||||||||||
| 477 | return executed 3545940 times by 153 tests: m_value;return m_value;Executed by:
executed 3545940 times by 153 tests: return m_value;Executed by:
| 3545940 | ||||||||||||||||||||||||
| 478 | } | - | ||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | inline CheckedState safeGet(T& value) const __attribute__ ((warn_unused_result)) | - | ||||||||||||||||||||||||
| 481 | { | - | ||||||||||||||||||||||||
| 482 | value = m_value; | - | ||||||||||||||||||||||||
| 483 | if (this->hasOverflowed()
| 0-2310717 | ||||||||||||||||||||||||
| 484 | return never executed: CheckedState::DidOverflow;return CheckedState::DidOverflow;never executed: return CheckedState::DidOverflow; | 0 | ||||||||||||||||||||||||
| 485 | return executed 2310801 times by 153 tests: CheckedState::DidNotOverflow;return CheckedState::DidNotOverflow;Executed by:
executed 2310801 times by 153 tests: return CheckedState::DidNotOverflow;Executed by:
| 2310801 | ||||||||||||||||||||||||
| 486 | } | - | ||||||||||||||||||||||||
| 487 | - | |||||||||||||||||||||||||
| 488 | - | |||||||||||||||||||||||||
| 489 | template <typename U> const Checked operator+=(U rhs) | - | ||||||||||||||||||||||||
| 490 | { | - | ||||||||||||||||||||||||
| 491 | if (!safeAdd(m_value, rhs, m_value)
| 0-2374335 | ||||||||||||||||||||||||
| 492 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 493 | return executed 2374282 times by 9 tests: *this;return *this;Executed by:
executed 2374282 times by 9 tests: return *this;Executed by:
| 2374282 | ||||||||||||||||||||||||
| 494 | } | - | ||||||||||||||||||||||||
| 495 | - | |||||||||||||||||||||||||
| 496 | template <typename U> const Checked operator-=(U rhs) | - | ||||||||||||||||||||||||
| 497 | { | - | ||||||||||||||||||||||||
| 498 | if (!safeSub(m_value, rhs, m_value)
| 0 | ||||||||||||||||||||||||
| 499 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 500 | return never executed: *this;return *this;never executed: return *this; | 0 | ||||||||||||||||||||||||
| 501 | } | - | ||||||||||||||||||||||||
| 502 | - | |||||||||||||||||||||||||
| 503 | template <typename U> const Checked operator*=(U rhs) | - | ||||||||||||||||||||||||
| 504 | { | - | ||||||||||||||||||||||||
| 505 | if (!safeMultiply(m_value, rhs, m_value)
| 0 | ||||||||||||||||||||||||
| 506 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 507 | return never executed: *this;return *this;never executed: return *this; | 0 | ||||||||||||||||||||||||
| 508 | } | - | ||||||||||||||||||||||||
| 509 | - | |||||||||||||||||||||||||
| 510 | const Checked operator*=(double rhs) | - | ||||||||||||||||||||||||
| 511 | { | - | ||||||||||||||||||||||||
| 512 | double result = rhs * m_value; | - | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | if (!(std::numeric_limits<T>::min() <= result
| 0 | ||||||||||||||||||||||||
| 515 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 516 | m_value = (T)result; | - | ||||||||||||||||||||||||
| 517 | return never executed: *this;return *this;never executed: return *this; | 0 | ||||||||||||||||||||||||
| 518 | } | - | ||||||||||||||||||||||||
| 519 | - | |||||||||||||||||||||||||
| 520 | const Checked operator*=(float rhs) | - | ||||||||||||||||||||||||
| 521 | { | - | ||||||||||||||||||||||||
| 522 | return never executed: *this *= (double)rhs;return *this *= (double)rhs;never executed: return *this *= (double)rhs; | 0 | ||||||||||||||||||||||||
| 523 | } | - | ||||||||||||||||||||||||
| 524 | - | |||||||||||||||||||||||||
| 525 | template <typename U, typename V> const Checked operator+=(Checked<U, V> rhs) | - | ||||||||||||||||||||||||
| 526 | { | - | ||||||||||||||||||||||||
| 527 | if (rhs.hasOverflowed()
| 0-2371625 | ||||||||||||||||||||||||
| 528 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 529 | return executed 2371600 times by 9 tests: *this += rhs.m_value;return *this += rhs.m_value;Executed by:
executed 2371600 times by 9 tests: return *this += rhs.m_value;Executed by:
| 2371600 | ||||||||||||||||||||||||
| 530 | } | - | ||||||||||||||||||||||||
| 531 | - | |||||||||||||||||||||||||
| 532 | template <typename U, typename V> const Checked operator-=(Checked<U, V> rhs) | - | ||||||||||||||||||||||||
| 533 | { | - | ||||||||||||||||||||||||
| 534 | if (rhs.hasOverflowed()
| 0 | ||||||||||||||||||||||||
| 535 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 536 | return never executed: *this -= rhs.m_value;return *this -= rhs.m_value;never executed: return *this -= rhs.m_value; | 0 | ||||||||||||||||||||||||
| 537 | } | - | ||||||||||||||||||||||||
| 538 | - | |||||||||||||||||||||||||
| 539 | template <typename U, typename V> const Checked operator*=(Checked<U, V> rhs) | - | ||||||||||||||||||||||||
| 540 | { | - | ||||||||||||||||||||||||
| 541 | if (rhs.hasOverflowed()
| 0 | ||||||||||||||||||||||||
| 542 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 543 | return never executed: *this *= rhs.m_value;return *this *= rhs.m_value;never executed: return *this *= rhs.m_value; | 0 | ||||||||||||||||||||||||
| 544 | } | - | ||||||||||||||||||||||||
| 545 | - | |||||||||||||||||||||||||
| 546 | - | |||||||||||||||||||||||||
| 547 | template <typename V> bool operator==(Checked<T, V> rhs) | - | ||||||||||||||||||||||||
| 548 | { | - | ||||||||||||||||||||||||
| 549 | return never executed: unsafeGet() == rhs.unsafeGet();return unsafeGet() == rhs.unsafeGet();never executed: return unsafeGet() == rhs.unsafeGet(); | 0 | ||||||||||||||||||||||||
| 550 | } | - | ||||||||||||||||||||||||
| 551 | - | |||||||||||||||||||||||||
| 552 | template <typename U> bool operator==(U rhs) | - | ||||||||||||||||||||||||
| 553 | { | - | ||||||||||||||||||||||||
| 554 | if (this->hasOverflowed()
| 0-5551254 | ||||||||||||||||||||||||
| 555 | this->overflowed(); never executed: this->overflowed(); | 0 | ||||||||||||||||||||||||
| 556 | return executed 5551322 times by 9 tests: safeEquals(m_value, rhs);return safeEquals(m_value, rhs);Executed by:
executed 5551322 times by 9 tests: return safeEquals(m_value, rhs);Executed by:
| 5551322 | ||||||||||||||||||||||||
| 557 | } | - | ||||||||||||||||||||||||
| 558 | - | |||||||||||||||||||||||||
| 559 | template <typename U, typename V> const Checked operator==(Checked<U, V> rhs) | - | ||||||||||||||||||||||||
| 560 | { | - | ||||||||||||||||||||||||
| 561 | return never executed: unsafeGet() == Checked(rhs.unsafeGet());return unsafeGet() == Checked(rhs.unsafeGet());never executed: return unsafeGet() == Checked(rhs.unsafeGet()); | 0 | ||||||||||||||||||||||||
| 562 | } | - | ||||||||||||||||||||||||
| 563 | - | |||||||||||||||||||||||||
| 564 | template <typename U> bool operator!=(U rhs) | - | ||||||||||||||||||||||||
| 565 | { | - | ||||||||||||||||||||||||
| 566 | return executed 791344 times by 8 tests: !(*this == rhs);return !(*this == rhs);Executed by:
executed 791344 times by 8 tests: return !(*this == rhs);Executed by:
| 791344 | ||||||||||||||||||||||||
| 567 | } | - | ||||||||||||||||||||||||
| 568 | - | |||||||||||||||||||||||||
| 569 | private: | - | ||||||||||||||||||||||||
| 570 | - | |||||||||||||||||||||||||
| 571 | Checked(float); | - | ||||||||||||||||||||||||
| 572 | Checked(double); | - | ||||||||||||||||||||||||
| 573 | void operator=(float); | - | ||||||||||||||||||||||||
| 574 | void operator=(double); | - | ||||||||||||||||||||||||
| 575 | void operator+=(float); | - | ||||||||||||||||||||||||
| 576 | void operator+=(double); | - | ||||||||||||||||||||||||
| 577 | void operator-=(float); | - | ||||||||||||||||||||||||
| 578 | void operator-=(double); | - | ||||||||||||||||||||||||
| 579 | T m_value; | - | ||||||||||||||||||||||||
| 580 | }; | - | ||||||||||||||||||||||||
| 581 | - | |||||||||||||||||||||||||
| 582 | template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator+(Checked<U, OverflowHandler> lhs, Checked<V, OverflowHandler> rhs) | - | ||||||||||||||||||||||||
| 583 | { | - | ||||||||||||||||||||||||
| 584 | U x = 0; | - | ||||||||||||||||||||||||
| 585 | V y = 0; | - | ||||||||||||||||||||||||
| 586 | bool overflowed = lhs.safeGet(x) == CheckedState::DidOverflow
| 0-325 | ||||||||||||||||||||||||
| 587 | typename Result<U, V>::ResultType result = 0; | - | ||||||||||||||||||||||||
| 588 | overflowed |= !safeAdd(x, y, result); | - | ||||||||||||||||||||||||
| 589 | if (overflowed
| 0-323 | ||||||||||||||||||||||||
| 590 | return never executed: ResultOverflowed;return ResultOverflowed;never executed: return ResultOverflowed; | 0 | ||||||||||||||||||||||||
| 591 | return executed 325 times by 3 tests: result;return result;Executed by:
executed 325 times by 3 tests: return result;Executed by:
| 325 | ||||||||||||||||||||||||
| 592 | } | - | ||||||||||||||||||||||||
| 593 | - | |||||||||||||||||||||||||
| 594 | template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator-(Checked<U, OverflowHandler> lhs, Checked<V, OverflowHandler> rhs) | - | ||||||||||||||||||||||||
| 595 | { | - | ||||||||||||||||||||||||
| 596 | U x = 0; | - | ||||||||||||||||||||||||
| 597 | V y = 0; | - | ||||||||||||||||||||||||
| 598 | bool overflowed = lhs.safeGet(x) == CheckedState::DidOverflow
| 0-1155001 | ||||||||||||||||||||||||
| 599 | typename Result<U, V>::ResultType result = 0; | - | ||||||||||||||||||||||||
| 600 | overflowed |= !safeSub(x, y, result); | - | ||||||||||||||||||||||||
| 601 | if (overflowed
| 0-1154104 | ||||||||||||||||||||||||
| 602 | return never executed: ResultOverflowed;return ResultOverflowed;never executed: return ResultOverflowed; | 0 | ||||||||||||||||||||||||
| 603 | return executed 1154018 times by 153 tests: result;return result;Executed by:
executed 1154018 times by 153 tests: return result;Executed by:
| 1154018 | ||||||||||||||||||||||||
| 604 | } | - | ||||||||||||||||||||||||
| 605 | - | |||||||||||||||||||||||||
| 606 | template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator*(Checked<U, OverflowHandler> lhs, Checked<V, OverflowHandler> rhs) | - | ||||||||||||||||||||||||
| 607 | { | - | ||||||||||||||||||||||||
| 608 | U x = 0; | - | ||||||||||||||||||||||||
| 609 | V y = 0; | - | ||||||||||||||||||||||||
| 610 | bool overflowed = lhs.safeGet(x) == CheckedState::DidOverflow
| 0-323 | ||||||||||||||||||||||||
| 611 | typename Result<U, V>::ResultType result = 0; | - | ||||||||||||||||||||||||
| 612 | overflowed |= !safeMultiply(x, y, result); | - | ||||||||||||||||||||||||
| 613 | if (overflowed
| 0-322 | ||||||||||||||||||||||||
| 614 | return never executed: ResultOverflowed;return ResultOverflowed;never executed: return ResultOverflowed; | 0 | ||||||||||||||||||||||||
| 615 | return executed 323 times by 3 tests: result;return result;Executed by:
executed 323 times by 3 tests: return result;Executed by:
| 323 | ||||||||||||||||||||||||
| 616 | } | - | ||||||||||||||||||||||||
| 617 | - | |||||||||||||||||||||||||
| 618 | template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator+(Checked<U, OverflowHandler> lhs, V rhs) | - | ||||||||||||||||||||||||
| 619 | { | - | ||||||||||||||||||||||||
| 620 | return never executed: lhs + Checked<V, OverflowHandler>(rhs);return lhs + Checked<V, OverflowHandler>(rhs);never executed: return lhs + Checked<V, OverflowHandler>(rhs); | 0 | ||||||||||||||||||||||||
| 621 | } | - | ||||||||||||||||||||||||
| 622 | - | |||||||||||||||||||||||||
| 623 | template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator-(Checked<U, OverflowHandler> lhs, V rhs) | - | ||||||||||||||||||||||||
| 624 | { | - | ||||||||||||||||||||||||
| 625 | return executed 1154917 times by 153 tests: lhs - Checked<V, OverflowHandler>(rhs);return lhs - Checked<V, OverflowHandler>(rhs);Executed by:
executed 1154917 times by 153 tests: return lhs - Checked<V, OverflowHandler>(rhs);Executed by:
| 1154917 | ||||||||||||||||||||||||
| 626 | } | - | ||||||||||||||||||||||||
| 627 | - | |||||||||||||||||||||||||
| 628 | template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator*(Checked<U, OverflowHandler> lhs, V rhs) | - | ||||||||||||||||||||||||
| 629 | { | - | ||||||||||||||||||||||||
| 630 | return executed 323 times by 3 tests: lhs * Checked<V, OverflowHandler>(rhs);return lhs * Checked<V, OverflowHandler>(rhs);Executed by:
executed 323 times by 3 tests: return lhs * Checked<V, OverflowHandler>(rhs);Executed by:
| 323 | ||||||||||||||||||||||||
| 631 | } | - | ||||||||||||||||||||||||
| 632 | - | |||||||||||||||||||||||||
| 633 | template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator+(U lhs, Checked<V, OverflowHandler> rhs) | - | ||||||||||||||||||||||||
| 634 | { | - | ||||||||||||||||||||||||
| 635 | return executed 324 times by 3 tests: Checked<U, OverflowHandler>(lhs) + rhs;return Checked<U, OverflowHandler>(lhs) + rhs;Executed by:
executed 324 times by 3 tests: return Checked<U, OverflowHandler>(lhs) + rhs;Executed by:
| 324 | ||||||||||||||||||||||||
| 636 | } | - | ||||||||||||||||||||||||
| 637 | - | |||||||||||||||||||||||||
| 638 | template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator-(U lhs, Checked<V, OverflowHandler> rhs) | - | ||||||||||||||||||||||||
| 639 | { | - | ||||||||||||||||||||||||
| 640 | return never executed: Checked<U, OverflowHandler>(lhs) - rhs;return Checked<U, OverflowHandler>(lhs) - rhs;never executed: return Checked<U, OverflowHandler>(lhs) - rhs; | 0 | ||||||||||||||||||||||||
| 641 | } | - | ||||||||||||||||||||||||
| 642 | - | |||||||||||||||||||||||||
| 643 | template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator*(U lhs, Checked<V, OverflowHandler> rhs) | - | ||||||||||||||||||||||||
| 644 | { | - | ||||||||||||||||||||||||
| 645 | return never executed: Checked<U, OverflowHandler>(lhs) * rhs;return Checked<U, OverflowHandler>(lhs) * rhs;never executed: return Checked<U, OverflowHandler>(lhs) * rhs; | 0 | ||||||||||||||||||||||||
| 646 | } | - | ||||||||||||||||||||||||
| 647 | - | |||||||||||||||||||||||||
| 648 | } | - | ||||||||||||||||||||||||
| 649 | - | |||||||||||||||||||||||||
| 650 | using WTF::Checked; | - | ||||||||||||||||||||||||
| 651 | using WTF::CheckedState; | - | ||||||||||||||||||||||||
| 652 | using WTF::RecordOverflow; | - | ||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |