[libc-commits] [libc] [libc] Fix gcc warnings. (PR #240958)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Wed Nov 11 00:03:35 PST 2026


================
@@ -199,16 +199,20 @@ extract_decimal_digit(T &value) {
   constexpr Word HALFWORD_MASK = ((Word(1) << HALFWORD_BITS) - 1);
   // Sum both halves of all words except the low one.
   for (size_t i = 1; i < T::WORD_COUNT; i++) {
-    acc_remainder += value.val[i] >> HALFWORD_BITS;
-    acc_remainder += value.val[i] & HALFWORD_MASK;
+    acc_remainder =
+        static_cast<Word>(acc_remainder + (value.val[i] >> HALFWORD_BITS));
+    acc_remainder =
+        static_cast<Word>(acc_remainder + (value.val[i] & HALFWORD_MASK));
   }
   // Add the high half of the low word. Then we have everything that needs to
   // be multiplied by 6, so do that.
-  acc_remainder += value.val[0] >> HALFWORD_BITS;
-  acc_remainder *= 6;
+  acc_remainder =
+      static_cast<Word>(acc_remainder + (value.val[0] >> HALFWORD_BITS));
----------------
labath wrote:

Would this be equivalent to 
```suggestion
  acc_remainder +=
      static_cast<Word>(value.val[0] >> HALFWORD_BITS);
```

.. which is closer to the original code, and less of a mouthful.

https://github.com/llvm/llvm-project/pull/240958


More information about the libc-commits mailing list