Skip to content

Commit f2344cc

Browse files
authored
Merge pull request #138 from ethereum/fix_conversion_warnings
Fix conversion warnings
2 parents b6da2b3 + a35e6b8 commit f2344cc

File tree

9 files changed

+26
-22
lines changed

9 files changed

+26
-22
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ find_package(ethash CONFIG REQUIRED)
3333
option(EVMC_TEST_TOOLS "Build EVMC test tools" ${EVMONE_TESTING})
3434
add_subdirectory(evmc)
3535

36-
cable_configure_compiler(NO_PEDANTIC NO_CONVERSION_WARNINGS)
36+
cable_configure_compiler()
3737
if(CABLE_COMPILER_GNULIKE)
3838
add_compile_options(-Wno-attributes) # Allow using unknown attributes.
3939

lib/evmone/analysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ inline constexpr evmc_call_kind op2call_kind(uint8_t opcode) noexcept
1515
{
1616
switch (opcode)
1717
{
18+
default:
1819
case OP_CREATE:
1920
return EVMC_CREATE;
2021
case OP_CALL:
@@ -25,8 +26,6 @@ inline constexpr evmc_call_kind op2call_kind(uint8_t opcode) noexcept
2526
return EVMC_DELEGATECALL;
2627
case OP_CREATE2:
2728
return EVMC_CREATE2;
28-
default:
29-
return evmc_call_kind(-1);
3029
}
3130
}
3231

lib/evmone/analysis.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ inline int find_jumpdest(const code_analysis& analysis, int offset) noexcept
196196
const auto begin = std::begin(analysis.jumpdest_offsets);
197197
const auto end = std::end(analysis.jumpdest_offsets);
198198
const auto it = std::lower_bound(begin, end, offset);
199-
return (it != end && *it == offset) ? analysis.jumpdest_targets[it - begin] : -1;
199+
return (it != end && *it == offset) ?
200+
analysis.jumpdest_targets[static_cast<size_t>(it - begin)] :
201+
-1;
200202
}
201203

202204
EVMC_EXPORT code_analysis analyze(

lib/evmone/instructions.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ constexpr auto word_size = 32;
2121

2222
/// Returns number of words what would fit to provided number of bytes,
2323
/// i.e. it rounds up the number bytes to number of words.
24-
constexpr int64_t num_words(size_t size_in_bytes) noexcept
24+
constexpr int64_t num_words(uint64_t size_in_bytes) noexcept
2525
{
2626
return (static_cast<int64_t>(size_in_bytes) + (word_size - 1)) / word_size;
2727
}
2828

29-
inline bool check_memory(execution_state& state, const uint256& offset, int64_t size) noexcept
29+
inline bool check_memory(execution_state& state, const uint256& offset, uint64_t size) noexcept
3030
{
3131
if (offset > max_buffer_size)
3232
{
3333
state.exit(EVMC_OUT_OF_GAS);
3434
return false;
3535
}
3636

37-
const auto new_size = static_cast<int64_t>(offset) + size;
38-
const auto current_size = static_cast<int64_t>(state.memory.size());
37+
const auto new_size = static_cast<uint64_t>(offset) + size;
38+
const auto current_size = state.memory.size();
3939
if (new_size > current_size)
4040
{
4141
const auto new_words = num_words(new_size);
42-
const auto current_words = current_size / 32; // Memory always has full words.
42+
const auto current_words = static_cast<int64_t>(current_size / 32);
4343
const auto new_cost = 3 * new_words + new_words * new_words / 512;
4444
const auto current_cost = 3 * current_words + current_words * current_words / 512;
4545
const auto cost = new_cost - current_cost;
@@ -68,7 +68,7 @@ inline bool check_memory(
6868
return false;
6969
}
7070

71-
return check_memory(state, offset, static_cast<int64_t>(size));
71+
return check_memory(state, offset, static_cast<uint64_t>(size));
7272
}
7373

7474

@@ -144,7 +144,8 @@ void op_exp(execution_state& state, instr_argument) noexcept
144144
const auto base = state.stack.pop();
145145
auto& exponent = state.stack.top();
146146

147-
const auto exponent_significant_bytes = intx::count_significant_words<uint8_t>(exponent);
147+
const auto exponent_significant_bytes =
148+
static_cast<int>(intx::count_significant_words<uint8_t>(exponent));
148149
const auto exponent_cost = state.rev >= EVMC_SPURIOUS_DRAGON ? 50 : 10;
149150
const auto additional_cost = exponent_significant_bytes * exponent_cost;
150151
if ((state.gas_left -= additional_cost) < 0)

test/bench/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if(NOT HAVE_FILESYSTEM)
2929
INSTALL_COMMAND ""
3030
)
3131

32-
target_include_directories(evmone-bench PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
32+
target_include_directories(evmone-bench SYSTEM PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
3333
add_dependencies(evmone-bench ghcfilesystem)
3434
elseif(UNIX AND NOT APPLE)
3535
target_link_libraries(evmone-bench PRIVATE stdc++fs)

test/bench/bench.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ constexpr auto fn_table = evmone::exec_fn_table{};
6565

6666
void analyse(State& state, bytes_view code) noexcept
6767
{
68-
auto bytes_analysed = int64_t{0};
68+
auto bytes_analysed = uint64_t{0};
6969
for (auto _ : state)
7070
{
7171
auto r = evmone::analyze(fn_table, EVMC_PETERSBURG, code.data(), code.size());

test/unittests/evm_test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <algorithm>
1010
#include <numeric>
1111

12+
using namespace evmc::literals;
1213
using namespace intx;
1314

1415
constexpr auto max_code_size = 0x6000;
@@ -755,7 +756,7 @@ TEST_F(evm, log)
755756
EXPECT_EQ(last_log.data[0], 0x77);
756757
EXPECT_EQ(last_log.data[1], 0);
757758
ASSERT_EQ(last_log.topics.size(), n);
758-
for (int i = 0; i < n; ++i)
759+
for (size_t i = 0; i < static_cast<size_t>(n); ++i)
759760
{
760761
EXPECT_EQ(last_log.topics[i].bytes[31], 4 - i);
761762
}
@@ -904,7 +905,7 @@ TEST_F(evm, extcode)
904905
{
905906
auto addr = evmc_address{};
906907
std::fill(std::begin(addr.bytes), std::end(addr.bytes), uint8_t{0xff});
907-
addr.bytes[19] -= 1;
908+
addr.bytes[19]--;
908909

909910
accounts[addr].code = {'a', 'b', 'c', 'd'};
910911

@@ -1179,9 +1180,8 @@ TEST_F(evm, extcodecopy_memory_cost)
11791180

11801181
TEST_F(evm, extcodecopy_nonzero_index)
11811182
{
1182-
auto addr = evmc_address{};
1183-
addr.bytes[19] = 0xa;
1184-
auto index = 15;
1183+
constexpr auto addr = 0x000000000000000000000000000000000000000a_address;
1184+
constexpr auto index = 15;
11851185

11861186
auto& extcode = accounts[addr].code;
11871187
extcode.assign(16, 0x00);

test/utils/host_mock.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class MockedHost : public evmc::Host
125125
record_account_access(addr);
126126
const auto it = accounts.find(addr);
127127
if (it == accounts.end())
128-
return static_cast<evmc_storage_status>(-1);
128+
return EVMC_STORAGE_UNCHANGED;
129129

130130
auto& old = it->second.storage[key];
131131

test/utils/utils.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bytes from_hexx(const std::string& hexx)
5050
const auto re = std::regex{R"(\((\d+)x([^)]+)\))"};
5151

5252
auto hex = hexx;
53-
auto position_correction = int{0};
53+
auto position_correction = size_t{0};
5454
for (auto it = std::sregex_iterator{hexx.begin(), hexx.end(), re}; it != std::sregex_iterator{};
5555
++it)
5656
{
@@ -59,8 +59,10 @@ bytes from_hexx(const std::string& hexx)
5959
while (num_repetitions-- > 0)
6060
replacement += (*it)[2];
6161

62-
hex.replace(it->position() + position_correction, it->length(), replacement);
63-
position_correction += static_cast<int>(replacement.length() - it->length());
62+
const auto pos = static_cast<size_t>(it->position()) + position_correction;
63+
const auto length = static_cast<size_t>(it->length());
64+
hex.replace(pos, length, replacement);
65+
position_correction += replacement.length() - length;
6466
}
6567
return from_hex(hex);
6668
}

0 commit comments

Comments
 (0)