[llvm] [Flang-rt][build] fixes building warnings under gcc: (PR #173955)
Eugene Epshteyn via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 29 22:34:34 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:
`digits` is known at compile time, thus at most this should be `static_assert`.
Also, the value of `digits` comes from system headers, and if the system headers give us wrong values, then we have bigger problems than building flang...
In addition, I'm curious why gcc had problem with `8 - digits` and not `32 - digits`.
https://github.com/llvm/llvm-project/pull/173955
More information about the llvm-commits
mailing list