[PATCH] D38132: [Support] mapped_file_region: avoid tautological comparison.

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 06:41:15 PDT 2017


lebedev.ri created this revision.

Found when testing stage-2 build with https://reviews.llvm.org/D38101.

  In file included from /build/llvm/lib/Support/Path.cpp:1045:
  /build/llvm/lib/Support/Unix/Path.inc:648:14: error: comparison 'uint64_t' (aka 'unsigned long') > 18446744073709551615 is always false [-Werror,-Wtautological-constant-compare]
    if (length > std::numeric_limits<size_t>::max()) {
        ~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`size_t` is `uint64_t` here, apparently, thus any `uint64_t` value
always fits into `size_t`.

I suppose there may be cases where `size_t` is smaller (32-bit?),
so i wrapped the `if()` into preprocessor `#if`. Not sure what
better solution there could be.


Repository:
  rL LLVM

https://reviews.llvm.org/D38132

Files:
  lib/Support/Unix/Path.inc


Index: lib/Support/Unix/Path.inc
===================================================================
--- lib/Support/Unix/Path.inc
+++ lib/Support/Unix/Path.inc
@@ -644,11 +644,16 @@
 mapped_file_region::mapped_file_region(int fd, mapmode mode, uint64_t length,
                                        uint64_t offset, std::error_code &ec)
     : Size(length), Mapping() {
+  static_assert(std::numeric_limits<size_t>::max() == SIZE_MAX, "");
+  static_assert(std::numeric_limits<uint64_t>::max() == UINT64_MAX, "");
+
+#if UINT64_MAX > SIZE_MAX
   // Make sure that the requested size fits within SIZE_T.
   if (length > std::numeric_limits<size_t>::max()) {
     ec = make_error_code(errc::invalid_argument);
     return;
   }
+#endif
 
   ec = init(fd, offset, mode);
   if (ec)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38132.116177.patch
Type: text/x-patch
Size: 782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170921/e4e6adf4/attachment.bin>


More information about the llvm-commits mailing list