[libc-commits] [libc] [llvm] [libc][math] Refactor fsqrt to Header Only (PR #175444)
Muhammad Bassiouni via libc-commits
libc-commits at lists.llvm.org
Sun Jan 11 14:42:14 PST 2026
bassiounix 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 alt="Image" width="1258" height="536" src="https://private-user-images.githubusercontent.com/85361959/534376355-d190fb08-683e-4972-ae9c-14146924f3ad.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjgxNzEzMDgsIm5iZiI6MTc2ODE3MTAwOCwicGF0aCI6Ii84NTM2MTk1OS81MzQzNzYzNTUtZDE5MGZiMDgtNjgzZS00OTcyLWFlOWMtMTQxNDY5MjRmM2FkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAxMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMTExVDIyMzY0OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM3N2MxZTc2ZTY1OTZmMjA0NmFjNGEzYjE1ZWM1YmM0YjEzZmJlNWNjODQwOTA3ZGM0ZTM3ZGY1NzkyOTBhZDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.dbJKCf30zcGHa9D-GrJm_g0209YU2rzQYudA2dqPVOQ">
Could you state from where and how did you encounter this error?
https://github.com/llvm/llvm-project/pull/175444
More information about the libc-commits
mailing list