Fixes for 32-bit build of fuzzers

This change resolves some type-related issues that were leading to
loss-of-precision warnings when compiling for i386 in OSS-Fuzz.

Change-Id: I77912d6b3824a0f942d0f54f1e62914f69e14d7d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66000
Auto-Submit: Alastair Donaldson <afdx@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
Alastair Donaldson 2021-10-06 17:54:28 +00:00 committed by Tint LUCI CQ
parent 71763c84c2
commit 08146e2300
5 changed files with 10 additions and 8 deletions

View File

@ -191,8 +191,8 @@ void PrintHelpMessage(const char* help_message) {
} }
bool ParseUint32(const char* param, uint32_t* out) { bool ParseUint32(const char* param, uint32_t* out) {
auto value = strtoul(param, nullptr, 10); uint64_t value = static_cast<uint64_t>(strtoul(param, nullptr, 10));
if (value > std::numeric_limits<uint32_t>::max()) { if (value > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) {
return false; return false;
} }
*out = static_cast<uint32_t>(value); *out = static_cast<uint32_t>(value);

View File

@ -70,7 +70,8 @@ std::unique_ptr<Mutator> CreateMutator(const std::vector<uint32_t>& binary,
assert(!types.empty() && "At least one mutator type must be specified"); assert(!types.empty() && "At least one mutator type must be specified");
RandomGenerator generator(seed); RandomGenerator generator(seed);
auto mutator_type = types[generator.GetUInt64(types.size())]; auto mutator_type =
types[generator.GetUInt32(static_cast<uint32_t>(types.size()))];
const auto& mutator_params = context->params.mutator_params; const auto& mutator_params = context->params.mutator_params;
switch (mutator_type) { switch (mutator_type) {

View File

@ -105,7 +105,8 @@ SpirvOptMutator::Result SpirvOptMutator::Mutate() {
std::vector<std::string> passes; std::vector<std::string> passes;
while (passes.size() < num_of_passes) { while (passes.size() < num_of_passes) {
auto idx = generator_.GetUInt64(opt_passes_.size()); auto idx =
generator_.GetUInt32(static_cast<uint32_t>(opt_passes_.size()));
passes.push_back(opt_passes_[idx]); passes.push_back(opt_passes_[idx]);
} }

View File

@ -73,14 +73,14 @@ class SpirvReduceMutator : public Mutator {
template <typename T> template <typename T>
T* GetRandomElement(std::vector<T>* arr) { T* GetRandomElement(std::vector<T>* arr) {
assert(!arr->empty() && "Can't get random element from an empty vector"); assert(!arr->empty() && "Can't get random element from an empty vector");
auto index = generator_.GetUInt64(arr->size()); auto index = generator_.GetUInt32(static_cast<uint32_t>(arr->size()));
return &(*arr)[index]; return &(*arr)[index];
} }
template <typename T> template <typename T>
T* GetRandomElement(std::vector<std::unique_ptr<T>>* arr) { T* GetRandomElement(std::vector<std::unique_ptr<T>>* arr) {
assert(!arr->empty() && "Can't get random element from an empty vector"); assert(!arr->empty() && "Can't get random element from an empty vector");
auto index = generator_.GetUInt64(arr->size()); auto index = generator_.GetUInt32(static_cast<uint32_t>(arr->size()));
return (*arr)[index].get(); return (*arr)[index].get();
} }

View File

@ -129,7 +129,7 @@ bool ReadBinary(const std::string& path, std::vector<uint32_t>* out) {
return false; return false;
} }
auto size = file.tellg(); size_t size = static_cast<size_t>(file.tellg());
if (!file) { if (!file) {
return false; return false;
} }
@ -139,7 +139,7 @@ bool ReadBinary(const std::string& path, std::vector<uint32_t>* out) {
return false; return false;
} }
std::vector<char> binary(static_cast<size_t>(size)); std::vector<char> binary(size);
if (!file.read(binary.data(), size)) { if (!file.read(binary.data(), size)) {
return false; return false;
} }