Fix runtime/int issues.

This CL fixes up various runtime/int types to be more specific.

Bug: dawn:1339
Change-Id: I61c8ecc89abd0373173b95bfb594c75d05a5d505
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86865
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2022-04-20 02:05:24 +00:00 committed by Dawn LUCI CQ
parent 36af06343c
commit 09ce76b0d5
10 changed files with 50 additions and 55 deletions

View File

@ -3,4 +3,3 @@ filter=-readability/casting
filter=-readability/todo filter=-readability/todo
filter=-runtime/explicit filter=-runtime/explicit
filter=-runtime/indentation_namespace filter=-runtime/indentation_namespace
filter=-runtime/int

View File

@ -22,7 +22,8 @@
#include "dawn/common/Math.h" #include "dawn/common/Math.h"
#include "dawn/common/UnderlyingType.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 // TODO(crbug.com/dawn/306): it could be optimized, in particular when N <= 64
template <typename T> template <typename T>
@ -53,12 +54,12 @@ class BitSetIterator final {
} }
private: private:
unsigned long getNextBit(); uint32_t getNextBit();
static constexpr size_t kBitsPerWord = sizeof(uint32_t) * 8; static constexpr size_t kBitsPerWord = sizeof(uint32_t) * 8;
std::bitset<N> mBits; std::bitset<N> mBits;
unsigned long mCurrentBit; uint32_t mCurrentBit;
unsigned long mOffset; uint32_t mOffset;
}; };
Iterator begin() const { Iterator begin() const {
@ -92,7 +93,7 @@ BitSetIterator<N, T>::Iterator::Iterator(const std::bitset<N>& bits)
if (bits.any()) { if (bits.any()) {
mCurrentBit = getNextBit(); mCurrentBit = getNextBit();
} else { } else {
mOffset = static_cast<unsigned long>(roundUp(N, kBitsPerWord)); mOffset = static_cast<uint32_t>(roundUp(N, kBitsPerWord));
} }
} }
@ -115,7 +116,7 @@ bool BitSetIterator<N, T>::Iterator::operator!=(const Iterator& other) const {
} }
template <size_t N, typename T> template <size_t N, typename T>
unsigned long BitSetIterator<N, T>::Iterator::getNextBit() { uint32_t BitSetIterator<N, T>::Iterator::getNextBit() {
static std::bitset<N> wordMask(std::numeric_limits<uint32_t>::max()); static std::bitset<N> wordMask(std::numeric_limits<uint32_t>::max());
while (mOffset < N) { while (mOffset < N) {

View File

@ -75,7 +75,7 @@ void HashCombine(size_t* hash, const T& value, const Args&... args) {
#if defined(_GLIBCXX_DEBUG) #if defined(_GLIBCXX_DEBUG)
template <size_t N> template <size_t N>
size_t Hash(const std::bitset<N>& value) { size_t Hash(const std::bitset<N>& value) {
constexpr size_t kWindowSize = sizeof(unsigned long long); constexpr size_t kWindowSize = sizeof(uint64_t);
std::bitset<N> bits = value; std::bitset<N> bits = value;
size_t hash = 0; size_t hash = 0;

View File

@ -28,6 +28,7 @@
uint32_t ScanForward(uint32_t bits) { uint32_t ScanForward(uint32_t bits) {
ASSERT(bits != 0); ASSERT(bits != 0);
#if defined(DAWN_COMPILER_MSVC) #if defined(DAWN_COMPILER_MSVC)
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul; unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanForward(&firstBitIndex, bits); unsigned char ret = _BitScanForward(&firstBitIndex, bits);
ASSERT(ret != 0); ASSERT(ret != 0);
@ -40,6 +41,7 @@ uint32_t ScanForward(uint32_t bits) {
uint32_t Log2(uint32_t value) { uint32_t Log2(uint32_t value) {
ASSERT(value != 0); ASSERT(value != 0);
#if defined(DAWN_COMPILER_MSVC) #if defined(DAWN_COMPILER_MSVC)
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul; unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanReverse(&firstBitIndex, value); unsigned char ret = _BitScanReverse(&firstBitIndex, value);
ASSERT(ret != 0); ASSERT(ret != 0);
@ -53,11 +55,13 @@ uint32_t Log2(uint64_t value) {
ASSERT(value != 0); ASSERT(value != 0);
#if defined(DAWN_COMPILER_MSVC) #if defined(DAWN_COMPILER_MSVC)
# if defined(DAWN_PLATFORM_64_BIT) # if defined(DAWN_PLATFORM_64_BIT)
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul; unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanReverse64(&firstBitIndex, value); unsigned char ret = _BitScanReverse64(&firstBitIndex, value);
ASSERT(ret != 0); ASSERT(ret != 0);
return firstBitIndex; return firstBitIndex;
# else // defined(DAWN_PLATFORM_64_BIT) # else // defined(DAWN_PLATFORM_64_BIT)
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul; unsigned long firstBitIndex = 0ul;
if (_BitScanReverse(&firstBitIndex, value >> 32)) { if (_BitScanReverse(&firstBitIndex, value >> 32)) {
return firstBitIndex + 32; return firstBitIndex + 32;

View File

@ -39,7 +39,7 @@ namespace ityp {
constexpr bitset() noexcept : Base() { 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 { constexpr bool operator[](Index i) const {
@ -147,6 +147,7 @@ Index GetHighestBitIndexPlusOne(const ityp::bitset<Index, N>& bitset) {
#if defined(DAWN_COMPILER_MSVC) #if defined(DAWN_COMPILER_MSVC)
if constexpr (N > 32) { if constexpr (N > 32) {
# if defined(DAWN_PLATFORM_64_BIT) # if defined(DAWN_PLATFORM_64_BIT)
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul; unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanReverse64(&firstBitIndex, bitset.to_ullong()); unsigned char ret = _BitScanReverse64(&firstBitIndex, bitset.to_ullong());
if (ret == 0) { if (ret == 0) {
@ -165,6 +166,7 @@ Index GetHighestBitIndexPlusOne(const ityp::bitset<Index, N>& bitset) {
UNREACHABLE(); UNREACHABLE();
# endif // defined(DAWN_PLATFORM_64_BIT) # endif // defined(DAWN_PLATFORM_64_BIT)
} else { } else {
// NOLINTNEXTLINE(runtime/int)
unsigned long firstBitIndex = 0ul; unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanReverse(&firstBitIndex, bitset.to_ulong()); unsigned char ret = _BitScanReverse(&firstBitIndex, bitset.to_ulong());
if (ret == 0) { if (ret == 0) {

View File

@ -46,7 +46,7 @@ int main(int argc, char** argv) {
} }
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
long tellFileSize = ftell(file); int32_t tellFileSize = ftell(file);
if (tellFileSize <= 0) { if (tellFileSize <= 0) {
std::cerr << "Input file of incorrect size: " << filename << std::endl; std::cerr << "Input file of incorrect size: " << filename << std::endl;
return 1; return 1;

View File

@ -1404,7 +1404,8 @@ namespace dawn::native::d3d12 {
uint32_t height = renderPass->height; uint32_t height = renderPass->height;
D3D12_VIEWPORT viewport = { D3D12_VIEWPORT viewport = {
0.f, 0.f, static_cast<float>(width), static_cast<float>(height), 0.f, 1.f}; 0.f, 0.f, static_cast<float>(width), static_cast<float>(height), 0.f, 1.f};
D3D12_RECT scissorRect = {0, 0, static_cast<long>(width), static_cast<long>(height)}; D3D12_RECT scissorRect = {0, 0, static_cast<int32_t>(width),
static_cast<int32_t>(height)};
commandList->RSSetViewports(1, &viewport); commandList->RSSetViewports(1, &viewport);
commandList->RSSetScissorRects(1, &scissorRect); commandList->RSSetScissorRects(1, &scissorRect);

View File

@ -50,7 +50,7 @@ namespace wgpu::binding {
static Napi::Error New(Napi::Env env, static Napi::Error New(Napi::Env env,
std::string name, std::string name,
std::string message, std::string message,
unsigned short code = 0) { uint16_t code = 0) {
auto err = Napi::Error::New(env); auto err = Napi::Error::New(env);
err.Set("name", name); err.Set("name", name);
err.Set("message", message.empty() ? name : message); err.Set("message", message.empty() ? name : message);

View File

@ -761,7 +761,7 @@ namespace dawn::platform::TraceEvent {
// Specify these values when the corresponding argument of addTraceEvent is not // Specify these values when the corresponding argument of addTraceEvent is not
// used. // used.
const int zeroNumArgs = 0; 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 // 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 // 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 { class TraceID {
public: public:
explicit TraceID(const void* id, unsigned char* flags) explicit TraceID(const void* id, unsigned char* flags)
: m_data(static_cast<unsigned long long>(reinterpret_cast<uintptr_t>(id))) { : m_data(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(id))) {
*flags |= TRACE_EVENT_FLAG_MANGLE_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; (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; (void)flags;
} }
explicit TraceID(unsigned int id, unsigned char* flags) : m_data(id) { explicit TraceID(uint16_t id, unsigned char* flags) : m_data(id) {
(void)flags;
}
explicit TraceID(unsigned short id, unsigned char* flags) : m_data(id) {
(void)flags; (void)flags;
} }
explicit TraceID(unsigned char id, unsigned char* flags) : m_data(id) { explicit TraceID(unsigned char id, unsigned char* flags) : m_data(id) {
(void)flags; (void)flags;
} }
explicit TraceID(long long id, unsigned char* flags) explicit TraceID(int64_t id, unsigned char* flags) : m_data(static_cast<uint64_t>(id)) {
: m_data(static_cast<unsigned long long>(id)) {
(void)flags; (void)flags;
} }
explicit TraceID(long id, unsigned char* flags) explicit TraceID(int32_t id, unsigned char* flags) : m_data(static_cast<uint64_t>(id)) {
: m_data(static_cast<unsigned long long>(id)) {
(void)flags; (void)flags;
} }
explicit TraceID(int id, unsigned char* flags) explicit TraceID(int16_t id, unsigned char* flags) : m_data(static_cast<uint64_t>(id)) {
: m_data(static_cast<unsigned long long>(id)) {
(void)flags; (void)flags;
} }
explicit TraceID(short id, unsigned char* flags) explicit TraceID(signed char id, unsigned char* flags) : m_data(static_cast<uint64_t>(id)) {
: m_data(static_cast<unsigned long long>(id)) {
(void)flags;
}
explicit TraceID(signed char id, unsigned char* flags)
: m_data(static_cast<unsigned long long>(id)) {
(void)flags; (void)flags;
} }
unsigned long long data() const { uint64_t data() const {
return m_data; return m_data;
} }
private: 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 { union TraceValueUnion {
bool m_bool; bool m_bool;
unsigned long long m_uint; uint64_t m_uint;
long long m_int; int64_t m_int;
double m_double; double m_double;
const void* m_pointer; const void* m_pointer;
const char* m_string; const char* m_string;
@ -853,17 +842,16 @@ namespace dawn::platform::TraceEvent {
#define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, value_type_id) \ #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) { \ static inline void setTraceValue(actual_type arg, unsigned char* type, uint64_t* value) { \
*type = value_type_id; \ *type = value_type_id; \
*value = static_cast<unsigned long long>(arg); \ *value = static_cast<uint64_t>(arg); \
} }
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(uint64_t, TRACE_VALUE_TYPE_UINT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long, TRACE_VALUE_TYPE_UINT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(uint32_t, TRACE_VALUE_TYPE_UINT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(uint16_t, TRACE_VALUE_TYPE_UINT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, 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(int64_t, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int32_t, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, 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_INT(signed char, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE(bool, m_bool, TRACE_VALUE_TYPE_BOOL) INTERNAL_DECLARE_SET_TRACE_VALUE(bool, m_bool, TRACE_VALUE_TYPE_BOOL)
INTERNAL_DECLARE_SET_TRACE_VALUE(double, m_double, TRACE_VALUE_TYPE_DOUBLE) INTERNAL_DECLARE_SET_TRACE_VALUE(double, m_double, TRACE_VALUE_TYPE_DOUBLE)
@ -893,7 +881,7 @@ namespace dawn::platform::TraceEvent {
char phase, char phase,
const unsigned char* categoryEnabled, const unsigned char* categoryEnabled,
const char* name, const char* name,
unsigned long long id, uint64_t id,
unsigned char flags, unsigned char flags,
int /*unused, helps avoid empty __VA_ARGS__*/) { int /*unused, helps avoid empty __VA_ARGS__*/) {
return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id, return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id,
@ -906,7 +894,7 @@ namespace dawn::platform::TraceEvent {
char phase, char phase,
const unsigned char* categoryEnabled, const unsigned char* categoryEnabled,
const char* name, const char* name,
unsigned long long id, uint64_t id,
unsigned char flags, unsigned char flags,
int /*unused, helps avoid empty __VA_ARGS__*/, int /*unused, helps avoid empty __VA_ARGS__*/,
const char* arg1Name, const char* arg1Name,
@ -925,7 +913,7 @@ namespace dawn::platform::TraceEvent {
char phase, char phase,
const unsigned char* categoryEnabled, const unsigned char* categoryEnabled,
const char* name, const char* name,
unsigned long long id, uint64_t id,
unsigned char flags, unsigned char flags,
int /*unused, helps avoid empty __VA_ARGS__*/, int /*unused, helps avoid empty __VA_ARGS__*/,
const char* arg1Name, const char* arg1Name,

View File

@ -27,18 +27,18 @@ class BitSetIteratorTest : public testing::Test {
// Simple iterator test. // Simple iterator test.
TEST_F(BitSetIteratorTest, Iterator) { TEST_F(BitSetIteratorTest, Iterator) {
std::set<unsigned long> originalValues; std::set<uint32_t> originalValues;
originalValues.insert(2); originalValues.insert(2);
originalValues.insert(6); originalValues.insert(6);
originalValues.insert(8); originalValues.insert(8);
originalValues.insert(35); originalValues.insert(35);
for (unsigned long value : originalValues) { for (uint32_t value : originalValues) {
mStateBits.set(value); mStateBits.set(value);
} }
std::set<unsigned long> readValues; std::set<uint32_t> readValues;
for (unsigned long bit : IterateBitSet(mStateBits)) { for (uint32_t bit : IterateBitSet(mStateBits)) {
EXPECT_EQ(1u, originalValues.count(bit)); EXPECT_EQ(1u, originalValues.count(bit));
EXPECT_EQ(0u, readValues.count(bit)); EXPECT_EQ(0u, readValues.count(bit));
readValues.insert(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, // We don't use the FAIL gtest macro here since it returns immediately,
// causing an unreachable code warning in MSVC // causing an unreachable code warning in MSVC
bool sawBit = false; bool sawBit = false;
for (unsigned long bit : IterateBitSet(mStateBits)) { for (uint32_t bit : IterateBitSet(mStateBits)) {
DAWN_UNUSED(bit); DAWN_UNUSED(bit);
sawBit = true; sawBit = true;
} }
@ -73,9 +73,9 @@ TEST_F(BitSetIteratorTest, NonLValueBitset) {
otherBits.set(3); otherBits.set(3);
otherBits.set(5); otherBits.set(5);
std::set<unsigned long> seenBits; std::set<uint32_t> seenBits;
for (unsigned long bit : IterateBitSet(mStateBits & otherBits)) { for (uint32_t bit : IterateBitSet(mStateBits & otherBits)) {
EXPECT_EQ(0u, seenBits.count(bit)); EXPECT_EQ(0u, seenBits.count(bit));
seenBits.insert(bit); seenBits.insert(bit);
EXPECT_TRUE(mStateBits[bit]); EXPECT_TRUE(mStateBits[bit]);