[PATCH] D100320: [flang] Fix narrowing warning on macos

Tim Keith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 12 09:31:15 PDT 2021


tskeith created this revision.
tskeith added a reviewer: klausler.
tskeith added a project: Flang.
Herald added a subscriber: jdoerfert.
tskeith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100320

Files:
  flang/runtime/random.cpp


Index: flang/runtime/random.cpp
===================================================================
--- flang/runtime/random.cpp
+++ flang/runtime/random.cpp
@@ -57,7 +57,7 @@
       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;
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100320.336866.patch
Type: text/x-patch
Size: 586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210412/f612661b/attachment.bin>


More information about the llvm-commits mailing list