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

Cleanup warnings with nvhpc/21.9. #2582

Merged
merged 5 commits into from
Nov 5, 2021
Merged

Conversation

olupton
Copy link
Contributor

@olupton olupton commented Nov 4, 2021

This squashes a couple of warnings when building fmt 8.0.1 with version 21.9 of the NVIDIA HPC compiler.

"{path}/fmt/include/fmt/core.h", line 313: warning #1676-D: unrecognized GCC pragma
  FMT_GCC_PRAGMA("GCC optimize(\"Og\")")
  ^

"{path}/fmt/include/fmt/format.h", line 948: warning #185-D: dynamic initialization in unreachable code
    int num_digits = 0;
        ^
          detected during:
            instantiation of "auto fmt::v8::detail::count_digits<BITS,UInt>(UInt)->int [with BITS=4, UInt=uint32_t]" at line 1499
            instantiation of "auto fmt::v8::detail::write_int(OutputIt, fmt::v8::detail::write_int_arg<T>, const fmt::v8::basic_format_specs<Char> &, fmt::v8::detail::locale_ref)->OutputIt [with Char=char
, OutputIt=fmt::v8::detail::buffer_appender<char>, T=uint32_t]" at line 1540
            instantiation of "auto fmt::v8::detail::write(OutputIt, T, const fmt::v8::basic_format_specs<Char> &, fmt::v8::detail::locale_ref)->OutputIt [with Char=char, OutputIt=fmt::v8::detail::buffer_a
ppender<char>, T=int, <unnamed>=0]" at line 1912
            instantiation of "auto fmt::v8::detail::write(OutputIt, T, const fmt::v8::basic_format_specs<Char> &, fmt::v8::detail::locale_ref)->OutputIt [with Char=char, OutputIt=fmt::v8::detail::buffer_a
ppender<char>, T=bool, <unnamed>=0]" at line 1969
            instantiation of "auto fmt::v8::detail::default_arg_formatter<Char>::operator()(T)->fmt::v8::detail::default_arg_formatter<Char>::iterator [with Char=char, T=bool]" at line 1465 of "{path}/fmt/include/fmt/core.h"
            instantiation of "auto fmt::v8::visit_format_arg(Visitor &&, const fmt::v8::basic_format_arg<Context> &)->decltype((<expression>)) [with Visitor=fmt::v8::detail::default_arg_formatter<char>, C
ontext=fmt::v8::format_context]" at line 2649
            instantiation of "void fmt::v8::detail::vformat_to(fmt::v8::detail::buffer<Char> &, fmt::v8::basic_string_view<Char>, fmt::v8::basic_format_args<fmt::v8::basic_format_context<fmt::v8::detail::
buffer_appender<fmt::v8::type_identity_t<Char>>, fmt::v8::type_identity_t<Char>>>, fmt::v8::detail::locale_ref) [with Char=char]" at line 2895 of "{path}/fmt/include/fmt/core.h"
            instantiation of "auto fmt::v8::vformat_to(OutputIt, fmt::v8::string_view, fmt::v8::format_args)->OutputIt [with OutputIt=std::back_insert_iterator<spdlog::memory_buf_t>, <unnamed>=0]" at line
 2915 of "{path}/fmt/include/fmt/core.h"
            instantiation of "auto fmt::v8::format_to(OutputIt, fmt::v8::format_string<T...>, T &&...)->OutputIt [with OutputIt=std::back_insert_iterator<spdlog::memory_buf_t>, T=<int &>, <unnamed>=0]" at
 line 58 of "{path}/spdlog/include/spdlog/details/fmt_helper.h"

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

include/fmt/core.h Outdated Show resolved Hide resolved
@@ -967,14 +967,17 @@ FMT_CONSTEXPR20 inline auto count_digits(uint64_t n) -> int {
template <int BITS, typename UInt>
FMT_CONSTEXPR auto count_digits(UInt n) -> int {
#ifdef FMT_BUILTIN_CLZ
if (num_bits<UInt>() == 32)
if (num_bits<UInt>() == 32) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wrap the condition in const_check instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template <int BITS, typename UInt>
FMT_CONSTEXPR auto count_digits(UInt n) -> int {
#ifdef FMT_BUILTIN_CLZ
  if (const_check(num_bits<UInt>() == 32))
    return (FMT_BUILTIN_CLZ(static_cast<uint32_t>(n) | 1) ^ 31) / BITS + 1;
#endif
  int num_digits = 0;

doesn't squash the warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's unfortunate but I think the suppression with extra blocks is too messy. Is there another way to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eafdd3e is another way -- I wouldn't say it's a particularly nice way...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is clearly worse =(. Does moving the definition of num_digits to the beginning of the function suppress the warning?

  int num_digits = 0;
#ifdef FMT_BUILTIN_CLZ
  if (const_check(num_bits<UInt>() == 32))
    return (FMT_BUILTIN_CLZ(static_cast<uint32_t>(n) | 1) ^ 31) / BITS + 1;
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea, but that just gives

warning #128-D: loop is not reachable

on the do { line. And I would be a little worried about other compilers giving an unused variable warning too...

I pushed yet another attempt, with an immediately executed lambda, which seems to work...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks better but please fix the CI issues.

@vitaut vitaut merged commit e67f92c into fmtlib:master Nov 5, 2021
@vitaut
Copy link
Contributor

vitaut commented Nov 5, 2021

Thanks

PoetaKodu pushed a commit to pacc-repo/fmt that referenced this pull request Nov 11, 2021
* Cleanup warnings with nvhpc/21.9.

* Move __NVCOMPILER check.

* Be more explicit.

* Immediately executed lambda.

* Fix shadowing warning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants