Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable more and fix compiler warnings #184

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
# Copyright 2018-2019 Pawel Bylica.
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

cmake_minimum_required(VERSION 3.13.4)
Expand All @@ -26,6 +26,14 @@ if(CABLE_COMPILER_GNULIKE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og")

add_compile_options(
-Wcast-qual
-Wsign-conversion
-Wundef
$<$<COMPILE_LANGUAGE:C>:-Wmissing-prototypes>
$<$<CXX_COMPILER_ID:Clang>:-Wnewline-eof>
)

option(ETHASH_NATIVE "Build for native CPU" OFF)
if(ETHASH_NATIVE)
add_compile_options(-march=native)
Expand Down
2 changes: 1 addition & 1 deletion lib/global_context/global_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#if __has_cpp_attribute(gnu::noinline)
#define ATTRIBUTE_NOINLINE [[gnu::noinline]]
#elif _MSC_VER
#elif defined(_MSC_VER)
#define ATTRIBUTE_NOINLINE __declspec(noinline)
#else
#define ATTRIBUTE_NOINLINE
Expand Down
6 changes: 3 additions & 3 deletions lib/support/attributes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2018-2019 Pawel Bylica.
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#pragma once
Expand All @@ -15,7 +15,7 @@
#endif

// [[always_inline]]
#if _MSC_VER
#if defined(_MSC_VER)
#define ALWAYS_INLINE __forceinline
#elif __has_attribute(always_inline)
#define ALWAYS_INLINE __attribute__((always_inline))
Expand All @@ -24,7 +24,7 @@
#endif

// [[no_sanitize()]]
#if __clang__
#if defined(__clang__)
#define NO_SANITIZE(sanitizer) __attribute__((no_sanitize(sanitizer)))
#else
#define NO_SANITIZE(sanitizer)
Expand Down
5 changes: 3 additions & 2 deletions test/benchmarks/ethash_benchmarks.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2018-2019 Pawel Bylica.
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#include "../unittests/helpers.hpp"
Expand Down Expand Up @@ -55,7 +55,8 @@ static void light_cache(benchmark::State& state)
const auto num_items = ethash::calculate_light_cache_num_items(epoch_number);
const auto seed = ethash::calculate_epoch_seed(epoch_number);

std::unique_ptr<ethash::hash512[]> light_cache{new ethash::hash512[num_items]};
std::unique_ptr<ethash::hash512[]> light_cache{
new ethash::hash512[static_cast<size_t>(num_items)]};

for (auto _ : state)
{
Expand Down
2 changes: 1 addition & 1 deletion test/benchmarks/keccak_benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

void fake_keccakf1600(uint64_t* state) noexcept
{
// Do nothing to measure performance of the code outside of keccakf function.
// Do nothing to measure performance of the code outside the keccakf function.
(void)state;
}

Expand Down
10 changes: 6 additions & 4 deletions test/benchmarks/keccak_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// Copyright 2018 Pawel Bylica.
// SPDX-License-Identifier: Apache-2.0

#include "keccak_utils.hpp"
#include <cstdint>
#include <cstring>

#define fix_endianness(X) X

void fake_keccakf1600(uint64_t* state) noexcept;
#pragma GCC diagnostic ignored "-Wcast-qual"
#pragma clang diagnostic ignored "-Wcast-qual"
#pragma clang diagnostic ignored "-Wcast-align"

#define fix_endianness(X) X

namespace
{
Expand Down Expand Up @@ -101,7 +103,7 @@ inline void keccak_default(uint64_t* out, const uint8_t* data, size_t size) noex
}

/// Loads 64-bit integer from given memory location.
inline uint64_t load_le(const uint8_t *data) noexcept
inline uint64_t load_le(const uint8_t* data) noexcept
{
// memcpy is the best way of expressing the intention. Every compiler will
// optimize is to single load instruction if the target architecture
Expand Down
1 change: 1 addition & 0 deletions test/benchmarks/keccak_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ void fake_keccak256_default(uint64_t* out, const uint8_t* data, size_t size) noe
void fake_keccak256_default_aligned(uint64_t* out, const uint8_t* data, size_t size) noexcept;
void fake_keccak256_fastest(uint64_t *out, const uint8_t *data, size_t size) noexcept;
void fake_keccak256_fastest_word4(uint64_t out[4], const uint64_t data[4]) noexcept;
void fake_keccakf1600(uint64_t* state) noexcept;
11 changes: 3 additions & 8 deletions test/benchmarks/threadsync_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2018-2019 Pawel Bylica.
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#include "threadsync_utils.hpp"
Expand All @@ -22,15 +22,10 @@ std::shared_ptr<fake_cache> build_fake_cache(int id) noexcept
return handle;
}

std::shared_ptr<fake_cache> build_sentinel() noexcept
static std::shared_ptr<fake_cache> build_sentinel() noexcept
{
static thread_local fake_cache sentinel;
return std::shared_ptr<fake_cache>(&sentinel, [](fake_cache*){});
}

std::shared_ptr<fake_cache> build_sentinel2() noexcept
{
return std::make_shared<fake_cache>();
return std::shared_ptr<fake_cache>(&sentinel, [](fake_cache*) {});
}

namespace
Expand Down
4 changes: 3 additions & 1 deletion test/integration/compilation/ethash_header_test.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
* Copyright 2018-2019 Pawel Bylica.
* Copyright 2018 Pawel Bylica.
* Licensed under the Apache License, Version 2.0.
*/

#include <ethash/ethash.h>

int test(void);

int test()
{
int sum = 0;
Expand Down
17 changes: 8 additions & 9 deletions test/tools/kiss99_tester.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2018-2019 Pawel Bylica.
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#include <ethash/kiss99.hpp>
Expand All @@ -17,20 +17,19 @@ int main()

constexpr double expected = double(1) / mod;

for (uint64_t i = 0; i <= uint64_t(-1); ++i)
for (uint64_t i = 0; i < uint64_t(-1); ++i)
{
auto x = rng() % mod;
++histogram[x];

if (i == output_point)
{
std::cout << std::right << std::setw(4) << (i / output_interval)
<< "G:" << std::fixed;
std::cout << std::right << std::setw(4) << (i / output_interval) << "G:" << std::fixed;

// // Probabilities:
// for (auto h : histogram)
// std::cout << ' ' << std::setw(9) << (double(h) / double(i));
// std::cout << '\n';
// Probabilities:
// for (auto h : histogram)
// std::cout << ' ' << std::setw(9) << (double(h) / double(i));
// std::cout << '\n';

// Errors:
for (auto h : histogram)
Expand All @@ -43,4 +42,4 @@ int main()
}

return 0;
}
}
5 changes: 3 additions & 2 deletions test/unittests/test_cases.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2019 Pawel Bylica.
// Ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

/// @file
Expand Down Expand Up @@ -70,4 +71,4 @@ hash_test_case hash_test_cases[] = {
"00000000000003f1554d8071ff0903268fcb70f30f4af3bf7ec7dc69cdf509f3",
},
};
} // namespace
} // namespace
6 changes: 3 additions & 3 deletions test/unittests/test_ethash.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2018-2019 Pawel Bylica.
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#pragma GCC diagnostic ignored "-Wpedantic"
Expand Down Expand Up @@ -705,7 +705,7 @@ TEST(ethash, small_dataset)
EXPECT_EQ(solution.nonce, 0);
}

#if !__APPLE__
#ifndef __APPLE__

// The Out-Of-Memory tests try to allocate huge memory buffers. This fails on
// Linux and Windows, but not on macOS. Because the macOS tries too hard
Expand All @@ -714,7 +714,7 @@ TEST(ethash, small_dataset)
// filter) because we don't want developers using macOS to be hit by this
// behavior.

#if __linux__
#ifdef __linux__
#include <sys/resource.h>

namespace
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/test_keccak.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2018-2019 Pawel Bylica.
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#include <ethash/keccak.hpp>
Expand Down Expand Up @@ -307,4 +307,4 @@ TEST(helpers, to_hash256_empty)
std::string hex;
hash256 h = to_hash256(hex);
EXPECT_EQ(h, hash256{});
}
}
4 changes: 2 additions & 2 deletions test/unittests/test_kiss.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2018-2019 Pawel Bylica.
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#include <ethash/bit_manipulation.h>
Expand Down Expand Up @@ -46,4 +46,4 @@ TEST(kiss99, compare_with_reference)

for (int i = 0; i < 100000; ++i)
EXPECT_EQ(rng(), kiss_reference());
}
}
4 changes: 2 additions & 2 deletions test/unittests/test_progpow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
// Copyright 2018-2019 Pawel Bylica.
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0.

#include "helpers.hpp"
Expand Down Expand Up @@ -135,7 +135,7 @@ TEST(progpow, search)
EXPECT_EQ(sr.mix_hash, r.mix_hash);
}

#if ETHASH_TEST_GENERATION
#ifdef ETHASH_TEST_GENERATION
TEST(progpow, generate_hash_test_cases)
{
constexpr auto num_epochs = 2;
Expand Down