Revert "[11/N] Enable clang-tidy warnings on c10/util/*.h (#116353)"

This reverts commit 37aae5932c.

Reverted https://github.com/pytorch/pytorch/pull/116353 on behalf of https://github.com/izaitsevfb due to Reverting, breaks internal builds: error: implicit conversion from 'long long' to 'float' may lose precision [-Werror,-Wimplicit-int-float-conversion] ([comment](https://github.com/pytorch/pytorch/pull/116353#issuecomment-1876045800))
This commit is contained in:
PyTorch MergeBot 2024-01-03 22:22:11 +00:00
parent 0aa50909f3
commit 1c69d0bdb5
22 changed files with 120 additions and 80 deletions

View File

@ -245,7 +245,6 @@ include_patterns = [
'aten/src/ATen/core/*.cpp',
'c10/**/*.cpp',
'c10/core/**/*.h',
'c10/util/**/*.h',
'torch/csrc/**/*.cpp',
]
exclude_patterns = [
@ -256,16 +255,6 @@ exclude_patterns = [
'**/*pb.h',
'**/*CUDA*',
'**/cuda/*pp',
'c10/util/complex_math.h',
'c10/util/complex_utils.h',
'c10/util/flat_hash_map.h',
'c10/util/Float8*.h',
'c10/util/logging*.h',
'c10/util/hash.h',
'c10/util/strong_type.h',
'c10/util/SmallVector.h',
'c10/util/win32-headers.h',
'c10/util/*inl.h',
'aten/src/ATen/core/TensorImpl_test.cpp',
'third_party/**/*',
'torch/csrc/api/**',

View File

@ -7,10 +7,14 @@
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <ctime>
#include <functional>
#include <type_traits>
#include <ctime>
#ifndef _WIN32
#include <ctime>
#endif
#if defined(C10_IOS) && defined(C10_MOBILE)
#include <sys/time.h> // for gettimeofday()
#endif

View File

@ -125,7 +125,6 @@ class ArrayRef final {
/// Construct an ArrayRef from a C array.
template <size_t N>
// NOLINTNEXTLINE(*c-arrays*)
/* implicit */ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}
/// Construct an ArrayRef from a std::initializer_list.
@ -239,7 +238,6 @@ class ArrayRef final {
/// continues to select the move assignment operator.
template <typename U>
std::enable_if_t<std::is_same_v<U, T>, ArrayRef<T>>& operator=(
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
U&& Temporary) = delete;
/// Disallow accidental assignment from a temporary.
@ -332,7 +330,6 @@ ArrayRef<T>& makeArrayRef(ArrayRef<T>& Vec) {
/// Construct an ArrayRef from a C array.
template <typename T, size_t N>
// NOLINTNEXTLINE(*c-arrays*)
ArrayRef<T> makeArrayRef(const T (&Arr)[N]) {
return ArrayRef<T>(Arr);
}

View File

@ -8,7 +8,6 @@
namespace c10::util {
namespace detail {
// NOLINTNEXTLINE(*c-arrays*)
constexpr uint64_t crc64_table[] = {
0x0000000000000000, 0x7ad870c830358979, 0xf5b0e190606b12f2,
0x8f689158505e9b8b, 0xc038e5739841b68f, 0xbae095bba8743ff6,

View File

@ -55,7 +55,10 @@ struct ExclusivelyOwnedTraits;
template <typename T>
class ExclusivelyOwned {
using EOT = ExclusivelyOwnedTraits<T>;
typename ExclusivelyOwnedTraits<T>::repr_type repr_;
union {
char dummy_;
typename ExclusivelyOwnedTraits<T>::repr_type repr_;
};
public:
ExclusivelyOwned() : repr_(EOT::nullRepr()) {}

View File

@ -18,8 +18,10 @@
#if defined(__cplusplus) && (__cplusplus >= 201103L)
#include <cmath>
#include <cstdint>
#elif !defined(__OPENCL_VERSION__)
#include <math.h>
#include <stdint.h>
#endif
#ifdef _MSC_VER

View File

@ -1,5 +1,6 @@
#pragma once
#include <c10/macros/Macros.h>
#include <cstddef>
#include <functional>
#include <utility>

View File

@ -126,7 +126,6 @@ class MaybeOwned final {
}
MaybeOwned(MaybeOwned&& rhs) noexcept(
// NOLINTNEXTLINE(*-noexcept-move-*)
std::is_nothrow_move_constructible_v<T> &&
std::is_nothrow_move_assignable_v<borrow_type>)
: isBorrowed_(rhs.isBorrowed_) {
@ -141,7 +140,6 @@ class MaybeOwned final {
std::is_nothrow_move_assignable_v<T> &&
std::is_nothrow_move_assignable_v<borrow_type> &&
std::is_nothrow_move_constructible_v<T> &&
// NOLINTNEXTLINE(*-noexcept-move-*)
std::is_nothrow_destructible_v<T> &&
std::is_nothrow_destructible_v<borrow_type>) {
if (this == &rhs) {
@ -182,7 +180,6 @@ class MaybeOwned final {
}
~MaybeOwned() noexcept(
// NOLINTNEXTLINE(*-noexcept-destructor)
std::is_nothrow_destructible_v<T> &&
std::is_nothrow_destructible_v<borrow_type>) {
if (C10_UNLIKELY(!isBorrowed_)) {

View File

@ -7,17 +7,14 @@
// Macros.h is not needed, but it does namespace shenanigans that lots
// of downstream code seems to rely on. Feel free to remove it and fix
// up builds.
#include <c10/macros/Macros.h>
#include <c10/util/Metaprogramming.h>
namespace c10 {
// NOLINTNEXTLINE(misc-unused-using-decls)
using std::bad_optional_access;
// NOLINTNEXTLINE(misc-unused-using-decls)
using std::make_optional;
// NOLINTNEXTLINE(misc-unused-using-decls)
using std::nullopt;
// NOLINTNEXTLINE(misc-unused-using-decls)
using std::nullopt_t;
// NOLINTNEXTLINE(misc-unused-using-decls)
using std::optional;
namespace detail_ {

View File

@ -110,13 +110,13 @@ class OptionalArrayRef final {
return *this;
}
template <
typename U = ArrayRef<T>,
typename = std::enable_if_t<
!std::is_same_v<std::decay_t<U>, OptionalArrayRef> &&
template <typename U = ArrayRef<T>>
constexpr std::enable_if_t<
!std::is_same_v<std::decay_t<U>, OptionalArrayRef> &&
std::is_constructible_v<ArrayRef<T>, U&&> &&
std::is_assignable_v<ArrayRef<T>&, U&&>>>
constexpr OptionalArrayRef& operator=(U&& value) noexcept(
std::is_assignable_v<ArrayRef<T>&, U&&>,
OptionalArrayRef&>
operator=(U&& value) noexcept(
std::is_nothrow_constructible_v<ArrayRef<T>, U&&> &&
std::is_nothrow_assignable_v<ArrayRef<T>&, U&&>) {
wrapped_opt_array_ref = std::forward<U>(value);

View File

@ -15,7 +15,9 @@ class scope_exit {
public:
template <typename Fp>
// NOLINTNEXTLINE(bugprone-forwarding-reference-overload)
// constructor accepting a forwarding reference can hide the
// move constructor
// @lint-ignore CLANGTIDY
explicit scope_exit(Fp&& F) : ExitFunction(std::forward<Fp>(F)) {}
scope_exit(scope_exit&& Rhs) noexcept

View File

@ -9,6 +9,12 @@
#include <ostream>
#include <sstream>
#include <string>
#include <vector>
C10_CLANG_DIAGNOSTIC_PUSH()
#if C10_CLANG_HAS_WARNING("-Wshorten-64-to-32")
C10_CLANG_DIAGNOSTIC_IGNORE("-Wshorten-64-to-32")
#endif
namespace c10 {
@ -35,7 +41,6 @@ struct CanonicalizeStrTypes {
};
template <size_t N>
// NOLINTNEXTLINE(*c-arrays*)
struct CanonicalizeStrTypes<char[N]> {
using type = const char*;
};
@ -176,15 +181,11 @@ inline void printQuotedString(std::ostream& stmt, const string_view str) {
} else {
// C++ io has stateful formatting settings. Messing with
// them is probably worse than doing this manually.
// NOLINTNEXTLINE(*c-arrays*)
char buf[4] = "000";
// NOLINTNEXTLINE(*narrowing-conversions)
buf[2] += s % 8;
s /= 8;
// NOLINTNEXTLINE(*narrowing-conversions)
buf[1] += s % 8;
s /= 8;
// NOLINTNEXTLINE(*narrowing-conversions)
buf[0] += s;
stmt << "\\" << buf;
}
@ -196,4 +197,6 @@ inline void printQuotedString(std::ostream& stmt, const string_view str) {
} // namespace c10
C10_CLANG_DIAGNOSTIC_POP()
#endif // C10_UTIL_STRINGUTIL_H_

View File

@ -6,10 +6,17 @@
#include <c10/util/Float8_e5m2.h>
#include <c10/util/Float8_e5m2fnuz.h>
#include <c10/util/Half.h>
#include <c10/util/complex.h>
#include <type_traits>
C10_CLANG_DIAGNOSTIC_PUSH()
#if C10_CLANG_HAS_WARNING("-Wimplicit-float-conversion")
C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-float-conversion")
#endif
#if C10_CLANG_HAS_WARNING("-Wimplicit-int-float-conversion")
C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-int-float-conversion")
#endif
namespace c10 {
template <typename dest_t, typename src_t>
@ -156,4 +163,6 @@ To checked_convert(From f, const char* name) {
} // namespace c10
C10_CLANG_DIAGNOSTIC_POP()
// Trigger tests for D25440771. TODO: Remove this line any time you want.

View File

@ -4,6 +4,14 @@
#include <limits>
#include <type_traits>
C10_CLANG_DIAGNOSTIC_PUSH()
#if C10_CLANG_HAS_WARNING("-Wstring-conversion")
C10_CLANG_DIAGNOSTIC_IGNORE("-Wstring-conversion")
#endif
#if C10_CLANG_HAS_WARNING("-Wimplicit-int-float-conversion")
C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-int-float-conversion")
#endif
namespace c10 {
/// Returns false since we cannot have x < 0 if x is unsigned.
@ -132,3 +140,5 @@ inline constexpr bool less_than_lowest(const T& x) {
}
} // namespace c10
C10_CLANG_DIAGNOSTIC_POP()

View File

@ -2,13 +2,11 @@
#pragma once
#include <c10/util/Exception.h>
#include <cstdint>
#include <functional>
#include <c10/util/ArrayRef.h>
#include <iterator>
#include <numeric>
#include <type_traits>
#include <utility>
namespace c10 {

View File

@ -8,7 +8,6 @@
// - make sherwood_v3_table::convertible_to_iterator public because GCC5 seems
// to have issues with it otherwise
// - fix compiler warnings in operator templated_iterator<const value_type>
// - make use of 'if constexpr' and eliminate AssignIfTrue template
// Copyright Malte Skarupke 2017.
// Distributed under the Boost Software License, Version 1.0.
@ -27,6 +26,11 @@
#include <type_traits>
#include <utility>
C10_CLANG_DIAGNOSTIC_PUSH()
#if C10_CLANG_HAS_WARNING("-Wimplicit-int-float-conversion")
C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-int-float-conversion")
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(push)
#pragma warning(disable : 4624) // destructor was implicitly defined as deleted
@ -172,7 +176,6 @@ struct sherwood_v3_entry {
};
inline int8_t log2(uint64_t value) {
// NOLINTNEXTLINE(*c-arrays*)
static constexpr int8_t table[64] = {
63, 0, 58, 1, 59, 47, 53, 2, 60, 39, 48, 27, 54, 33, 42, 3,
61, 51, 37, 40, 49, 18, 28, 20, 55, 30, 34, 11, 43, 14, 22, 4,
@ -187,6 +190,21 @@ inline int8_t log2(uint64_t value) {
return table[((value - (value >> 1)) * 0x07EDD5E59A4E28C2) >> 58];
}
template <typename T, bool>
struct AssignIfTrue {
void operator()(T& lhs, const T& rhs) {
lhs = rhs;
}
void operator()(T& lhs, T&& rhs) {
lhs = std::move(rhs);
}
};
template <typename T>
struct AssignIfTrue<T, false> {
void operator()(T&, const T&) {}
void operator()(T&, T&&) {}
};
inline uint64_t next_power_of_two(uint64_t i) {
--i;
i |= i >> 1;
@ -371,13 +389,15 @@ class sherwood_v3_table : private EntryAlloc,
return *this;
clear();
if constexpr (AllocatorTraits::propagate_on_container_copy_assignment::
value) {
if (AllocatorTraits::propagate_on_container_copy_assignment::value) {
if (static_cast<EntryAlloc&>(*this) !=
static_cast<const EntryAlloc&>(other)) {
reset_to_empty_state();
}
static_cast<EntryAlloc&>(*this) = other;
AssignIfTrue<
EntryAlloc,
AllocatorTraits::propagate_on_container_copy_assignment::value>()(
*this, other);
}
_max_load_factor = other._max_load_factor;
static_cast<DetailHasher&>(*this) = other;
@ -389,11 +409,13 @@ class sherwood_v3_table : private EntryAlloc,
sherwood_v3_table& operator=(sherwood_v3_table&& other) noexcept {
if (this == std::addressof(other))
return *this;
else if constexpr (AllocatorTraits::propagate_on_container_move_assignment::
value) {
else if (AllocatorTraits::propagate_on_container_move_assignment::value) {
clear();
reset_to_empty_state();
static_cast<EntryAlloc&>(*this) = std::move(other);
AssignIfTrue<
EntryAlloc,
AllocatorTraits::propagate_on_container_move_assignment::value>()(
*this, std::move(other));
swap_pointers(other);
} else if (
static_cast<EntryAlloc&>(*this) == static_cast<EntryAlloc&>(other)) {
@ -521,7 +543,6 @@ class sherwood_v3_table : private EntryAlloc,
return end();
}
const_iterator find(const FindKey& key) const {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<sherwood_v3_table*>(this)->find(key);
}
uint64_t count(const FindKey& key) const {
@ -774,8 +795,7 @@ class sherwood_v3_table : private EntryAlloc,
uint64_t num_buckets_for_reserve(uint64_t num_elements_) const {
return static_cast<uint64_t>(std::ceil(
static_cast<double>(num_elements_) /
std::min(0.5, static_cast<double>(_max_load_factor))));
num_elements_ / std::min(0.5, static_cast<double>(_max_load_factor))));
}
void rehash_for_other_container(const sherwood_v3_table& other) {
rehash(
@ -1466,7 +1486,6 @@ struct prime_number_hash_policy {
// ClosestPrime(p * 2^(1/3)) and ClosestPrime(p * 2^(2/3)) and put those in
// the gaps
// 5. get PrevPrime(2^64) and put it at the end
// NOLINTNEXTLINE(*c-arrays*)
static constexpr const uint64_t prime_list[] = {
2llu,
3llu,
@ -1654,7 +1673,6 @@ struct prime_number_hash_policy {
11493228998133068689llu,
14480561146010017169llu,
18446744073709551557llu};
// NOLINTNEXTLINE(*c-arrays*)
static constexpr uint64_t (*const mod_functions[])(uint64_t) = {
&mod0,
&mod2,
@ -1893,7 +1911,7 @@ struct fibonacci_hash_policy {
int8_t next_size_over(uint64_t& size) const {
size = std::max(uint64_t(2), detailv3::next_power_of_two(size));
return static_cast<int8_t>(64 - detailv3::log2(size));
return 64 - detailv3::log2(size);
}
void commit(int8_t shift_) {
shift = shift_;
@ -2002,7 +2020,9 @@ class flat_hash_map
return false;
for (const typename Table::value_type& value : lhs) {
auto found = rhs.find(value.first);
if (found == rhs.end() || value.second != found->second)
if (found == rhs.end())
return false;
else if (value.second != found->second)
return false;
}
return true;
@ -2090,6 +2110,8 @@ struct power_of_two_std_hash : std::hash<T> {
} // end namespace ska
C10_CLANG_DIAGNOSTIC_POP()
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(pop)
#endif

View File

@ -388,7 +388,8 @@ class intrusive_ptr final {
if (this == &rhs) {
return *this;
}
// NOLINTNEXTLINE(*assign-operator, *assignment-signature)
// NOLINTNEXTLINE(misc-unconventional-assign-operator,
// cppcoreguidelines-c-copy-assignment-signature)
return operator= <TTarget, NullType>(rhs);
}

View File

@ -283,8 +283,7 @@ T findLastSet(T Val, ZeroBehavior ZB = ZB_Max) {
/// Macro compressed bit reversal table for 256 bits.
///
/// http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable
/// NOLINTNEXTLINE(*c-arrays*)
static constexpr unsigned char BitReverseTable256[256] = {
static const unsigned char BitReverseTable256[256] = {
#define R2(n) n, n + 2 * 64, n + 1 * 64, n + 3 * 64
#define R4(n) R2(n), R2(n + 2 * 16), R2(n + 1 * 16), R2(n + 3 * 16)
#define R6(n) R4(n), R4(n + 2 * 4), R4(n + 1 * 4), R4(n + 3 * 4)
@ -300,9 +299,7 @@ static constexpr unsigned char BitReverseTable256[256] = {
/// Reverse the bits in \p Val.
template <typename T>
T reverseBits(T Val) {
// NOLINTNEXTLINE(*c-arrays*)
unsigned char in[sizeof(Val)];
// NOLINTNEXTLINE(*c-arrays*)
unsigned char out[sizeof(Val)];
std::memcpy(in, &Val, sizeof(Val));
for (unsigned i = 0; i < sizeof(Val); ++i)
@ -423,7 +420,7 @@ inline uint64_t maxUIntN(uint64_t N) {
/// Gets the minimum value for a N-bit signed integer.
inline int64_t minIntN(int64_t N) {
assert(N > 0 && N <= 64 && "integer width out of range");
// NOLINTNEXTLINE(*-narrowing-conversions)
return -(UINT64_C(1) << (N - 1));
}
@ -437,7 +434,6 @@ inline int64_t maxIntN(int64_t N) {
// This relies on two's complement wraparound when N == 64, so we convert to
// int64_t only at the very end to avoid UB.
// NOLINTNEXTLINE(*-narrowing-conversions)
return (UINT64_C(1) << (N - 1)) - 1;
}

View File

@ -8,7 +8,6 @@
// - make sherwood_v3_table::convertible_to_iterator public because GCC5 seems
// to have issues with it otherwise
// - fix compiler warnings in operator templated_iterator<const value_type>
// - make use of 'if constexpr' and eliminate AssignIfTrue template
// Copyright Malte Skarupke 2017.
// Distributed under the Boost Software License, Version 1.0.
@ -140,11 +139,9 @@ struct KeyOrValueEquality : functor_storage<bool, key_equal> {
static constexpr int8_t min_lookups = 4;
template <typename T>
struct sherwood_v3_entry {
// NOLINTNEXTLINE(modernize-use-equals-default)
sherwood_v3_entry() {}
sherwood_v3_entry(int8_t distance_from_desired)
: distance_from_desired(distance_from_desired) {}
// NOLINTNEXTLINE(modernize-use-equals-default)
~sherwood_v3_entry() {}
bool has_value() const {
@ -191,6 +188,21 @@ inline int8_t log2(uint64_t value) {
return table[((value - (value >> 1)) * 0x07EDD5E59A4E28C2) >> 58];
}
template <typename T, bool>
struct AssignIfTrue {
void operator()(T& lhs, const T& rhs) {
lhs = rhs;
}
void operator()(T& lhs, T&& rhs) {
lhs = std::move(rhs);
}
};
template <typename T>
struct AssignIfTrue<T, false> {
void operator()(T&, const T&) {}
void operator()(T&, T&&) {}
};
inline uint64_t next_power_of_two(uint64_t i) {
--i;
i |= i >> 1;
@ -371,13 +383,15 @@ class sherwood_v3_table : private EntryAlloc, private Hasher, private Equal {
return *this;
clear();
if constexpr (AllocatorTraits::propagate_on_container_copy_assignment::
value) {
if (AllocatorTraits::propagate_on_container_copy_assignment::value) {
if (static_cast<EntryAlloc&>(*this) !=
static_cast<const EntryAlloc&>(other)) {
reset_to_empty_state();
}
static_cast<EntryAlloc&>(*this) = other;
AssignIfTrue<
EntryAlloc,
AllocatorTraits::propagate_on_container_copy_assignment::value>()(
*this, other);
}
_max_load_factor = other._max_load_factor;
static_cast<Hasher&>(*this) = other;
@ -389,11 +403,13 @@ class sherwood_v3_table : private EntryAlloc, private Hasher, private Equal {
sherwood_v3_table& operator=(sherwood_v3_table&& other) noexcept {
if (this == std::addressof(other))
return *this;
else if constexpr (AllocatorTraits::propagate_on_container_move_assignment::
value) {
else if (AllocatorTraits::propagate_on_container_move_assignment::value) {
clear();
reset_to_empty_state();
static_cast<EntryAlloc&>(*this) = std::move(other);
AssignIfTrue<
EntryAlloc,
AllocatorTraits::propagate_on_container_move_assignment::value>()(
*this, std::move(other));
swap_pointers(other);
} else if (
static_cast<EntryAlloc&>(*this) == static_cast<EntryAlloc&>(other)) {

View File

@ -98,7 +98,6 @@ class C10_API FatalSignalHandler {
struct sigaction previous;
};
// NOLINTNEXTLINE(*c-arrays*)
static signal_handler kSignalHandlers[];
};

View File

@ -4,15 +4,10 @@
namespace c10 {
// NOLINTNEXTLINE(misc-unused-using-decls)
using std::stod;
// NOLINTNEXTLINE(misc-unused-using-decls)
using std::stoi;
// NOLINTNEXTLINE(misc-unused-using-decls)
using std::stoll;
// NOLINTNEXTLINE(misc-unused-using-decls)
using std::stoull;
// NOLINTNEXTLINE(misc-unused-using-decls)
using std::to_string;
} // namespace c10

View File

@ -1,6 +1,6 @@
#pragma once
#include <c10/macros/Macros.h>
#include <c10/util/Optional.h>
#include <string>
#include <vector>