[flang-commits] [flang] 50386fe - [flang] Fix narrowing warning on macos
Tim Keith via flang-commits
flang-commits at lists.llvm.org
Mon Apr 12 09:41:11 PDT 2021
Author: Tim Keith
Date: 2021-04-12T09:40:52-07:00
New Revision: 50386fe1db3ce57f762c9621b83445a4ffd80b26
URL: https://github.com/llvm/llvm-project/commit/50386fe1db3ce57f762c9621b83445a4ffd80b26
DIFF: https://github.com/llvm/llvm-project/commit/50386fe1db3ce57f762c9621b83445a4ffd80b26.diff
LOG: [flang] Fix narrowing warning on macos
With clang 11 on macos we were getting this warning:
```
flang/runtime/random.cpp:61:30: error: non-constant-expression cannot be narrowed from type 'unsigned long long' to 'runtime::GeneratedWord' (aka 'unsigned int') in initializer list [-Wc++11-narrowing]
GeneratedWord word{(generator() - generator.min()) & rangeMask};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flang/runtime/random.cpp:99:5: note: in instantiation of function template specialization 'runtime::Generate<double, 53>' requested here
Generate<CppTypeFor<TypeCategory::Real, 8>, 53>(harvest);
^
```
Changing the type of `rangeMask` fixes it.
Differential Revision: https://reviews.llvm.org/D100320
Added:
Modified:
flang/runtime/random.cpp
Removed:
################################################################################
diff --git a/flang/runtime/random.cpp b/flang/runtime/random.cpp
index b5158d07c816..4d2297ad5564 100644
--- a/flang/runtime/random.cpp
+++ b/flang/runtime/random.cpp
@@ -57,7 +57,7 @@ inline void Generate(const Descriptor &harvest) {
Int fraction{generator()};
if constexpr (words > 1) {
for (std::size_t k{1}; k < words; ++k) {
- static constexpr Int rangeMask{(Int{1} << rangeBits) - 1};
+ static constexpr auto rangeMask{(GeneratedWord{1} << rangeBits) - 1};
GeneratedWord word{(generator() - generator.min()) & rangeMask};
fraction = (fraction << rangeBits) | word;
}
More information about the flang-commits
mailing list