Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "pointless comparison of unsigned integer to zero" warning from fmt memory_buffer #1372

Open
kennyweiss opened this issue Jun 28, 2024 · 0 comments
Labels
bug Something isn't working compiler Related to various compilers and their quirks Reviewed User Request Issues related to user requests

Comments

@kennyweiss
Copy link
Member

A user reported the following warning from axom's fmt using clang on LLNL's rzansel:

.../clang-ibm-16.0.6-cuda-11.2.0-gcc-8.3.1/axom/0.9.1a-cuda/include/axom/fmt/core.h(411): warning: pointless comparison of unsigned integer with zero
          detected during:
            instantiation of "auto axom::fmt::v9::detail::to_unsigned(Int)->std::make_unsigned<Int>::type [with Int=size_t]"
.../clang-ibm-16.0.6-cuda-11.2.0-gcc-8.3.1/axom/0.9.1a-cuda/include/axom/fmt/format.h(570): here
            instantiation of "auto axom::fmt::v9::detail::fill_n(T *, Size, char)->T * [with T=char, Size=size_t]"
.../clang-ibm-16.0.6-cuda-11.2.0-gcc-8.3.1/axom/0.9.1a-cuda/include/axom/fmt/format.h(843): here
            instantiation of "axom::fmt::v9::basic_memory_buffer<T, SIZE, Allocator>::basic_memory_buffer(const Allocator &) [with T=char, SIZE=500UL, Allocator=std::allocator<char>]"
.../clang-ibm-16.0.6-cuda-11.2.0-gcc-8.3.1/axom/0.9.1a-cuda/include/axom/fmt/format-inl.h(72): here

This seems to arise from the following fmt function when adding a (compile time) empty string to a memory_buffer:

// <algorithm> is spectacularly slow to compile in C++20 so use a simple fill_n
// instead (#1998).
template <typename OutputIt, typename Size, typename T>
FMT_CONSTEXPR auto fill_n(OutputIt out, Size count, const T& value)
    -> OutputIt {
  for (Size i = 0; i < count; ++i) *out++ = value;
  return out;
}

https://sourcegraph.com/github.com/fmtlib/fmt@b61c8c3d23b7e6fdf9d44593877dba1c8a291be1/-/blob/include/fmt/format.h?L573
called from:
https://sourcegraph.com/github.com/fmtlib/fmt/-/blob/include/fmt/format.h?L872

Once we can reproduce the warning, some possible proposals for resolving it include:

  • avoid adding a compile-time detectable empty string to a memory_buffer, if we can find the source of this warning
  • attempting to patch the function to avoid the comparison (if possible), e.g. wrapping it with
     if(count>0) {...}
    under the assumption (guess) that the compiler will not issue a warning for the explicit conditional
  • adding a pragma to disable this warning, e.g.
  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wtype-limits"
    {...}
  #pragma GCC diagnostic pop
@kennyweiss kennyweiss added bug Something isn't working User Request Issues related to user requests compiler Related to various compilers and their quirks labels Jun 28, 2024
@kennyweiss kennyweiss changed the title Fix "pointless comparison of unsigned integer to zero" warning from ftm memory_buffer Fix "pointless comparison of unsigned integer to zero" warning from fmt memory_buffer Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Related to various compilers and their quirks Reviewed User Request Issues related to user requests
Projects
None yet
Development

No branches or pull requests

2 participants