[libc-commits] [libc] [llvm] [libc][math] Refactor fsqrt to Header Only (PR #175444)
Jolynn Wee Zhuo Lin via libc-commits
libc-commits at lists.llvm.org
Sun Jan 11 09:24:38 PST 2026
jolwnn wrote:
While working on the `fsqrt` header refactor, I encountered a pre-existing bug in cast.h that was exposed by my changes. The error triggered was:
```
/home/gha/actions-runner/_work/llvm-project/llvm-project/libc/src/__support/FPUtil/cast.h:55:18: error: shift count is negative [-Werror,-Wshift-count-negative]
55 | x_mant >>= InFPBits::FRACTION_LEN - OutFPBits::FRACTION_LEN;
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
This occurs when casting a NaN from a narrower type (e.g., `_Float16`) to a wider type (e.g., `float`), causing the shift count to be negative. The code only handled the case where the input type was wider, but not the reverse. My changes caused this template instantiation path to be compiled, revealing the bug. I am leaving this note for future investigation.
<img width="1258" height="536" alt="Image" src="https://github.com/user-attachments/assets/d190fb08-683e-4972-ae9c-14146924f3ad" />
https://github.com/llvm/llvm-project/pull/175444
More information about the libc-commits
mailing list