vmtester: better way to avoid compiler optimisations
#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);
@@ -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)
