[llvm] [Flang-rt][build] fixes building warnings under gcc: (PR #173955)
Eugene Epshteyn via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 30 17:08:58 PST 2025
================
@@ -452,7 +452,13 @@ float RTNAME(Rand)(int *i, const char *sourceFile, int line) {
if (radix == 2) {
mask = ~(unsigned)0u << (32 - digits + 1);
} else if (radix == 16) {
- mask = ~(unsigned)0u << ((8 - digits) * 4 + 1);
+ int shift_val = ((8 - digits) * 4 + 1);
+ if (shift_val < 0) {
+ Terminator terminator{sourceFile, line};
+ terminator.Crash("Radix 16: negative shift for mask. digits value maybe invalid.");
+ } else {
+ mask = ~(unsigned)0u << shift_val;
+ }
----------------
eugeneepshteyn wrote:
This table doesn't cover `radix == 16`. For hexadecimal representation, there are 2 digits per byte and `sizeof(float)` is typically 4 bytes, so there should be no problem with `8 - digits`.
If you really want to be extra careful, I would recommend not assigning to `mask` (keeping it at 0) if either `8 - digits` or `32 - digits` is negative. Then have one check for the whole function that `mask` is not zero and output one message, e.g., "rand: unknown floating point properties". This will also cover the case of unknown `radix`.
Tagging the original `Rand` PR author @JDPailleux
https://github.com/llvm/llvm-project/pull/173955
More information about the llvm-commits
mailing list