diff --git a/src/dawn/CPPLINT.cfg b/src/dawn/CPPLINT.cfg index d4594ba0ed..a15f154dff 100644 --- a/src/dawn/CPPLINT.cfg +++ b/src/dawn/CPPLINT.cfg @@ -3,4 +3,3 @@ filter=-readability/casting filter=-readability/todo filter=-runtime/explicit filter=-runtime/indentation_namespace -filter=-runtime/int diff --git a/src/dawn/common/BitSetIterator.h b/src/dawn/common/BitSetIterator.h index 5f250d5abb..0f1997cef9 100644 --- a/src/dawn/common/BitSetIterator.h +++ b/src/dawn/common/BitSetIterator.h @@ -22,7 +22,8 @@ #include "dawn/common/Math.h" #include "dawn/common/UnderlyingType.h" -// This is ANGLE's BitSetIterator class with a customizable return type +// This is ANGLE's BitSetIterator class with a customizable return type. +// Types have been updated to be more specific. // TODO(crbug.com/dawn/306): it could be optimized, in particular when N <= 64 template @@ -53,12 +54,12 @@ class BitSetIterator final { } private: - unsigned long getNextBit(); + uint32_t getNextBit(); static constexpr size_t kBitsPerWord = sizeof(uint32_t) * 8; std::bitset mBits; - unsigned long mCurrentBit; - unsigned long mOffset; + uint32_t mCurrentBit; + uint32_t mOffset; }; Iterator begin() const { @@ -92,7 +93,7 @@ BitSetIterator::Iterator::Iterator(const std::bitset& bits) if (bits.any()) { mCurrentBit = getNextBit(); } else { - mOffset = static_cast(roundUp(N, kBitsPerWord)); + mOffset = static_cast(roundUp(N, kBitsPerWord)); } } @@ -115,7 +116,7 @@ bool BitSetIterator::Iterator::operator!=(const Iterator& other) const { } template -unsigned long BitSetIterator::Iterator::getNextBit() { +uint32_t BitSetIterator::Iterator::getNextBit() { static std::bitset wordMask(std::numeric_limits::max()); while (mOffset < N) { diff --git a/src/dawn/common/HashUtils.h b/src/dawn/common/HashUtils.h index aed3cff720..1fa421c724 100644 --- a/src/dawn/common/HashUtils.h +++ b/src/dawn/common/HashUtils.h @@ -75,7 +75,7 @@ void HashCombine(size_t* hash, const T& value, const Args&... args) { #if defined(_GLIBCXX_DEBUG) template size_t Hash(const std::bitset& value) { - constexpr size_t kWindowSize = sizeof(unsigned long long); + constexpr size_t kWindowSize = sizeof(uint64_t); std::bitset bits = value; size_t hash = 0; diff --git a/src/dawn/common/Math.cpp b/src/dawn/common/Math.cpp index 1215eb8b55..f0dd0a1ff0 100644 --- a/src/dawn/common/Math.cpp +++ b/src/dawn/common/Math.cpp @@ -28,6 +28,7 @@ uint32_t ScanForward(uint32_t bits) { ASSERT(bits != 0); #if defined(DAWN_COMPILER_MSVC) + // NOLINTNEXTLINE(runtime/int) unsigned long firstBitIndex = 0ul; unsigned char ret = _BitScanForward(&firstBitIndex, bits); ASSERT(ret != 0); @@ -40,6 +41,7 @@ uint32_t ScanForward(uint32_t bits) { uint32_t Log2(uint32_t value) { ASSERT(value != 0); #if defined(DAWN_COMPILER_MSVC) + // NOLINTNEXTLINE(runtime/int) unsigned long firstBitIndex = 0ul; unsigned char ret = _BitScanReverse(&firstBitIndex, value); ASSERT(ret != 0); @@ -53,11 +55,13 @@ uint32_t Log2(uint64_t value) { ASSERT(value != 0); #if defined(DAWN_COMPILER_MSVC) # if defined(DAWN_PLATFORM_64_BIT) + // NOLINTNEXTLINE(runtime/int) unsigned long firstBitIndex = 0ul; unsigned char ret = _BitScanReverse64(&firstBitIndex, value); ASSERT(ret != 0); return firstBitIndex; # else // defined(DAWN_PLATFORM_64_BIT) + // NOLINTNEXTLINE(runtime/int) unsigned long firstBitIndex = 0ul; if (_BitScanReverse(&firstBitIndex, value >> 32)) { return firstBitIndex + 32; diff --git a/src/dawn/common/ityp_bitset.h b/src/dawn/common/ityp_bitset.h index 7c5909dda6..fcc585a19d 100644 --- a/src/dawn/common/ityp_bitset.h +++ b/src/dawn/common/ityp_bitset.h @@ -39,7 +39,7 @@ namespace ityp { constexpr bitset() noexcept : Base() { } - constexpr bitset(unsigned long long value) noexcept : Base(value) { + constexpr bitset(uint64_t value) noexcept : Base(value) { } constexpr bool operator[](Index i) const { @@ -147,6 +147,7 @@ Index GetHighestBitIndexPlusOne(const ityp::bitset& bitset) { #if defined(DAWN_COMPILER_MSVC) if constexpr (N > 32) { # if defined(DAWN_PLATFORM_64_BIT) + // NOLINTNEXTLINE(runtime/int) unsigned long firstBitIndex = 0ul; unsigned char ret = _BitScanReverse64(&firstBitIndex, bitset.to_ullong()); if (ret == 0) { @@ -165,6 +166,7 @@ Index GetHighestBitIndexPlusOne(const ityp::bitset& bitset) { UNREACHABLE(); # endif // defined(DAWN_PLATFORM_64_BIT) } else { + // NOLINTNEXTLINE(runtime/int) unsigned long firstBitIndex = 0ul; unsigned char ret = _BitScanReverse(&firstBitIndex, bitset.to_ulong()); if (ret == 0) { diff --git a/src/dawn/fuzzers/StandaloneFuzzerMain.cpp b/src/dawn/fuzzers/StandaloneFuzzerMain.cpp index 33411991e9..47cc7e168f 100644 --- a/src/dawn/fuzzers/StandaloneFuzzerMain.cpp +++ b/src/dawn/fuzzers/StandaloneFuzzerMain.cpp @@ -46,7 +46,7 @@ int main(int argc, char** argv) { } fseek(file, 0, SEEK_END); - long tellFileSize = ftell(file); + int32_t tellFileSize = ftell(file); if (tellFileSize <= 0) { std::cerr << "Input file of incorrect size: " << filename << std::endl; return 1; diff --git a/src/dawn/native/d3d12/CommandBufferD3D12.cpp b/src/dawn/native/d3d12/CommandBufferD3D12.cpp index a37f2573db..8f5fc8d86d 100644 --- a/src/dawn/native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn/native/d3d12/CommandBufferD3D12.cpp @@ -1404,7 +1404,8 @@ namespace dawn::native::d3d12 { uint32_t height = renderPass->height; D3D12_VIEWPORT viewport = { 0.f, 0.f, static_cast(width), static_cast(height), 0.f, 1.f}; - D3D12_RECT scissorRect = {0, 0, static_cast(width), static_cast(height)}; + D3D12_RECT scissorRect = {0, 0, static_cast(width), + static_cast(height)}; commandList->RSSetViewports(1, &viewport); commandList->RSSetScissorRects(1, &scissorRect); diff --git a/src/dawn/node/binding/Errors.cpp b/src/dawn/node/binding/Errors.cpp index 62def5d588..fd13ba6ebb 100644 --- a/src/dawn/node/binding/Errors.cpp +++ b/src/dawn/node/binding/Errors.cpp @@ -50,7 +50,7 @@ namespace wgpu::binding { static Napi::Error New(Napi::Env env, std::string name, std::string message, - unsigned short code = 0) { + uint16_t code = 0) { auto err = Napi::Error::New(env); err.Set("name", name); err.Set("message", message.empty() ? name : message); diff --git a/src/dawn/platform/tracing/TraceEvent.h b/src/dawn/platform/tracing/TraceEvent.h index 2dc1351296..9eac668067 100644 --- a/src/dawn/platform/tracing/TraceEvent.h +++ b/src/dawn/platform/tracing/TraceEvent.h @@ -761,7 +761,7 @@ namespace dawn::platform::TraceEvent { // Specify these values when the corresponding argument of addTraceEvent is not // used. const int zeroNumArgs = 0; - const unsigned long long noEventId = 0; + const uint64_t noEventId = 0; // TraceID encapsulates an ID that can either be an integer or pointer. Pointers // are mangled with the Process ID so that they are unlikely to collide when the @@ -769,58 +769,47 @@ namespace dawn::platform::TraceEvent { class TraceID { public: explicit TraceID(const void* id, unsigned char* flags) - : m_data(static_cast(reinterpret_cast(id))) { + : m_data(static_cast(reinterpret_cast(id))) { *flags |= TRACE_EVENT_FLAG_MANGLE_ID; } - explicit TraceID(unsigned long long id, unsigned char* flags) : m_data(id) { + explicit TraceID(uint64_t id, unsigned char* flags) : m_data(id) { (void)flags; } - explicit TraceID(unsigned long id, unsigned char* flags) : m_data(id) { + explicit TraceID(uint32_t id, unsigned char* flags) : m_data(id) { (void)flags; } - explicit TraceID(unsigned int id, unsigned char* flags) : m_data(id) { - (void)flags; - } - explicit TraceID(unsigned short id, unsigned char* flags) : m_data(id) { + explicit TraceID(uint16_t id, unsigned char* flags) : m_data(id) { (void)flags; } explicit TraceID(unsigned char id, unsigned char* flags) : m_data(id) { (void)flags; } - explicit TraceID(long long id, unsigned char* flags) - : m_data(static_cast(id)) { + explicit TraceID(int64_t id, unsigned char* flags) : m_data(static_cast(id)) { (void)flags; } - explicit TraceID(long id, unsigned char* flags) - : m_data(static_cast(id)) { + explicit TraceID(int32_t id, unsigned char* flags) : m_data(static_cast(id)) { (void)flags; } - explicit TraceID(int id, unsigned char* flags) - : m_data(static_cast(id)) { + explicit TraceID(int16_t id, unsigned char* flags) : m_data(static_cast(id)) { (void)flags; } - explicit TraceID(short id, unsigned char* flags) - : m_data(static_cast(id)) { - (void)flags; - } - explicit TraceID(signed char id, unsigned char* flags) - : m_data(static_cast(id)) { + explicit TraceID(signed char id, unsigned char* flags) : m_data(static_cast(id)) { (void)flags; } - unsigned long long data() const { + uint64_t data() const { return m_data; } private: - unsigned long long m_data; + uint64_t m_data; }; - // Simple union to store various types as unsigned long long. + // Simple union to store various types as uint64_t. union TraceValueUnion { bool m_bool; - unsigned long long m_uint; - long long m_int; + uint64_t m_uint; + int64_t m_int; double m_double; const void* m_pointer; const char* m_string; @@ -853,17 +842,16 @@ namespace dawn::platform::TraceEvent { #define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, value_type_id) \ static inline void setTraceValue(actual_type arg, unsigned char* type, uint64_t* value) { \ *type = value_type_id; \ - *value = static_cast(arg); \ + *value = static_cast(arg); \ } - INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) - INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long, TRACE_VALUE_TYPE_UINT) - INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT) - INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT) + INTERNAL_DECLARE_SET_TRACE_VALUE_INT(uint64_t, TRACE_VALUE_TYPE_UINT) + INTERNAL_DECLARE_SET_TRACE_VALUE_INT(uint32_t, TRACE_VALUE_TYPE_UINT) + INTERNAL_DECLARE_SET_TRACE_VALUE_INT(uint16_t, TRACE_VALUE_TYPE_UINT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT) - INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT) - INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT) - INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT) + INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int64_t, TRACE_VALUE_TYPE_INT) + INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int32_t, TRACE_VALUE_TYPE_INT) + INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int16_t, TRACE_VALUE_TYPE_INT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT) INTERNAL_DECLARE_SET_TRACE_VALUE(bool, m_bool, TRACE_VALUE_TYPE_BOOL) INTERNAL_DECLARE_SET_TRACE_VALUE(double, m_double, TRACE_VALUE_TYPE_DOUBLE) @@ -893,7 +881,7 @@ namespace dawn::platform::TraceEvent { char phase, const unsigned char* categoryEnabled, const char* name, - unsigned long long id, + uint64_t id, unsigned char flags, int /*unused, helps avoid empty __VA_ARGS__*/) { return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id, @@ -906,7 +894,7 @@ namespace dawn::platform::TraceEvent { char phase, const unsigned char* categoryEnabled, const char* name, - unsigned long long id, + uint64_t id, unsigned char flags, int /*unused, helps avoid empty __VA_ARGS__*/, const char* arg1Name, @@ -925,7 +913,7 @@ namespace dawn::platform::TraceEvent { char phase, const unsigned char* categoryEnabled, const char* name, - unsigned long long id, + uint64_t id, unsigned char flags, int /*unused, helps avoid empty __VA_ARGS__*/, const char* arg1Name, diff --git a/src/dawn/tests/unittests/BitSetIteratorTests.cpp b/src/dawn/tests/unittests/BitSetIteratorTests.cpp index b3b9d0c35f..b1c2a0c765 100644 --- a/src/dawn/tests/unittests/BitSetIteratorTests.cpp +++ b/src/dawn/tests/unittests/BitSetIteratorTests.cpp @@ -27,18 +27,18 @@ class BitSetIteratorTest : public testing::Test { // Simple iterator test. TEST_F(BitSetIteratorTest, Iterator) { - std::set originalValues; + std::set originalValues; originalValues.insert(2); originalValues.insert(6); originalValues.insert(8); originalValues.insert(35); - for (unsigned long value : originalValues) { + for (uint32_t value : originalValues) { mStateBits.set(value); } - std::set readValues; - for (unsigned long bit : IterateBitSet(mStateBits)) { + std::set readValues; + for (uint32_t bit : IterateBitSet(mStateBits)) { EXPECT_EQ(1u, originalValues.count(bit)); EXPECT_EQ(0u, readValues.count(bit)); readValues.insert(bit); @@ -52,7 +52,7 @@ TEST_F(BitSetIteratorTest, EmptySet) { // We don't use the FAIL gtest macro here since it returns immediately, // causing an unreachable code warning in MSVC bool sawBit = false; - for (unsigned long bit : IterateBitSet(mStateBits)) { + for (uint32_t bit : IterateBitSet(mStateBits)) { DAWN_UNUSED(bit); sawBit = true; } @@ -73,9 +73,9 @@ TEST_F(BitSetIteratorTest, NonLValueBitset) { otherBits.set(3); otherBits.set(5); - std::set seenBits; + std::set seenBits; - for (unsigned long bit : IterateBitSet(mStateBits & otherBits)) { + for (uint32_t bit : IterateBitSet(mStateBits & otherBits)) { EXPECT_EQ(0u, seenBits.count(bit)); seenBits.insert(bit); EXPECT_TRUE(mStateBits[bit]);