[all-commits] [llvm/llvm-project] 80079c: [libc] Fix new warning in DyadicFloat::as_mantissa...

Simon Tatham via All-commits all-commits at lists.llvm.org
Fri Mar 14 04:57:47 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 80079c9c2f55ddfc5b1d5235d5ed6a2981fa6a97
      https://github.com/llvm/llvm-project/commit/80079c9c2f55ddfc5b1d5235d5ed6a2981fa6a97
  Author: Simon Tatham <simon.tatham at arm.com>
  Date:   2025-03-14 (Fri, 14 Mar 2025)

  Changed paths:
    M libc/src/__support/FPUtil/dyadic_float.h

  Log Message:
  -----------
  [libc] Fix new warning in DyadicFloat::as_mantissa_type_rounded (#131148)

The affected line of code converts a float's exponent from `int` to
`size_t`, negating it in the process. Following clang commit
773e88f9d61399c, this provokes a warning, presumably because the
conversion goes wrong if `size_t` is wider than `int` and the input
value is `INT_MIN`: negating it within the `int` type is undefined
behavior, with the likely (though not guaranteed) effect of leaving it
still at `INT_MIN` and then sign-extending that on promotion to
`size_t`.

This fix adds a cast so that the promotion to `size_t` happens _before_
the negation, so that the negative input value will _always_ be
sign-extended, and then the negation will make it positive again.

(I don't believe this case will actually come up. `DyadicFloat` is a
helper system used in processing ordinary float formats, so nothing is
expected to generate an exponent with even a 16-bit absolute value, let
alone 31. But it's as easy to fix it to be robust as it is to just
suppress the warning!)



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list