[all-commits] [llvm/llvm-project] 466df9: [APFloat] Fix sign bit corrupting exponent in unsi...

Cheng-Chieh Liu via All-commits all-commits at lists.llvm.org
Mon Sep 21 04:50:47 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 466df937833ef60bc9f549a01059869ca7143d32
      https://github.com/llvm/llvm-project/commit/466df937833ef60bc9f549a01059869ca7143d32
  Author: Cheng-Chieh Liu <jay87406 at gmail.com>
  Date:   2026-09-21 (Mon, 21 Sep 2026)

  Changed paths:
    M llvm/lib/Support/APFloat.cpp
    M llvm/unittests/ADT/APFloatTest.cpp

  Log Message:
  -----------
  [APFloat] Fix sign bit corrupting exponent in unsigned FP8 formats (#223286)

`convertIEEEFloatToAPInt` unconditionally ORs the sign bit into the top
bit of the encoded value. `Float8E8M0FNU` and `Float8E5M3FNU` have no
sign bit (`hasSignedRepr = false`), so that top bit actually belongs to
the exponent field. Encoding a value with sign set therefore corrupts
the exponent, in one case colliding with the reserved NaN bit pattern.

Guard the OR with `hasSignedRepr`, matching the existing check in the
decode path (`initFromIEEEAPInt`).

Extend `ConvertLosesUnrepresentableSignAndZero` to also check
`bitcastToAPInt()` after dropping an unrepresentable sign, using `-1.0`
instead of `-2.0` so the corruption is actually visible in the bits.



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