Skip to content

Commit

Permalink
vmtester: better way to avoid compiler optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Apr 24, 2019
1 parent a2b011e commit cd993e1
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions test/vmtester/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@
#include <array>
#include <cstring>

namespace
{
// NOTE: this is to avoid compiler optimisations when reading the buffer
uint8_t read_uint8(const volatile uint8_t* p)
{
return *p;
}

void read_buffer(const uint8_t* ptr, size_t size)
{
for (size_t i = 0; i < size; i++)
{
read_uint8(&ptr[i]);
}
}

} // namespace

TEST_F(evmc_vm_test, abi_version_match)
{
ASSERT_EQ(vm->abi_version, EVMC_ABI_VERSION);
Expand Down Expand Up @@ -49,10 +67,7 @@ TEST_F(evmc_vm_test, execute)
else
{
EXPECT_NE(result.output_size, 0);

// Dereference pointer.
uint8_t tmp = result.output_data[0];
(void)tmp;
read_buffer(result.output_data, result.output_size);
}

if (result.release)
Expand Down

0 comments on commit cd993e1

Please sign in to comment.