Skip to content

Commit

Permalink
Upgrade to NDK r26c with its new clang-tidy build.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurik committed Feb 27, 2024
1 parent 7c6c27c commit 0694dd3
Show file tree
Hide file tree
Showing 48 changed files with 190 additions and 133 deletions.
2 changes: 2 additions & 0 deletions app-linux/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ source += $(wildcard $(pwd)/source/*.cpp)
cflags/$(pwd)/source/main.cpp += -Wno-unused-function
checks/$(pwd)/source/main.cpp += -clang-diagnostic-unused-function
checks/$(pwd)/source/main.cpp += -cppcoreguidelines-pro-type-cstyle-cast
checks/$(pwd)/source/main.cpp += -misc-use-anonymous-namespace
checks/$(pwd)/source/main.cpp += -misc-const-correctness

$(call include,shared/target-lnx.mk)

Expand Down
4 changes: 2 additions & 2 deletions app-windows/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE hPrevInstance,
project.set_dart_entrypoint_arguments(GetCommandLineArguments());

FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(360, 640);
const Win32Window::Point origin(10, 10);
const Win32Window::Size size(360, 640);
if (!window.Create(L"orchid", origin, size))
return EXIT_FAILURE;
window.SetQuitOnClose(true);
Expand Down
1 change: 1 addition & 0 deletions env/checks.mk
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ checks += fuchsia-virtual-inheritance
checks += google-build-*

checks += misc-*
checks += -misc-misplaced-const
checks += -misc-no-recursion
# this check doesn't allow for any protected members :/
checks += -misc-non-private-member-variables-in-classes
Expand Down
2 changes: 1 addition & 1 deletion env/setup-ndk.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -e
set -o pipefail
echo y | "${ANDROID_HOME}"/cmdline-tools/latest/bin/sdkmanager "build-tools;29.0.2" "ndk;25.2.9519653" "platforms;android-33" >/dev/null
echo y | "${ANDROID_HOME}"/cmdline-tools/latest/bin/sdkmanager "build-tools;29.0.2" "ndk;26.2.11394342" "platforms;android-33" >/dev/null
5 changes: 2 additions & 3 deletions env/target-and.mk
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ more = --sysroot=$(llvm)/sysroot
more += -fno-addrsig
include $(pwd)/kit-android.mk

cxx += -stdlib=libc++
lflags += -static-libstdc++

define _
temp := $(subst -,$(space),$(host/$(1)))
arch := $$(word 1,$$(temp))
Expand All @@ -86,6 +83,8 @@ $(each)

endif

include $(pwd)/target-cxx.mk

lflags += -lm -llog

wflags += -L$(CURDIR)/env/android
2 changes: 1 addition & 1 deletion env/target-elf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


include $(pwd)/target-lld.mk
lflags += -Wl,-error-limit=0
#lflags += -Wl,-error-limit=0
lflags += -Wl,--build-id=none
lflags += -Wl,-z,relro
lflags += -Wl,--no-undefined
Expand Down
7 changes: 5 additions & 2 deletions eth-sender/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ all: $(output)/$(machine)/cj$(exe)
test: $(output)/$(machine)/cj$(exe)
$< $(args)

source += $(wildcard source/*.cpp)
cflags += -Isource
source += $(wildcard $(pwd)/source/*.cpp)
cflags += -I$(pwd)/source

# XXX: this literally crashes clang-tidy and I haven't filed the bug
checks/$(pwd)/source/main.cpp += -bugprone-unchecked-optional-access

$(call include,p2p/target.mk)
include env/output.mk
Expand Down
2 changes: 1 addition & 1 deletion eth-sender/source/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool Similar(const Address &address, const Nibbles &nibbles) {
template <size_t Size_, typename Code_, typename Each_>
task<void> Scan(const Brick<32> &root, Code_ &&code, Each_ &&each) {
std::set<Nibbles> todo;
todo.emplace(Nibbles());
todo.emplace();

std::set<Nibbles> done;

Expand Down
14 changes: 13 additions & 1 deletion min-v8/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ v8src := $(filter-out \

# XXX: this is a mess that I need to clean up

vflags :=

ifeq ($(machine),x86_64)
vflags += -DV8_TARGET_ARCH_X64
v8src += $(foreach sub,$(v8sub),$(wildcard $(pwd)/v8/src/$(sub)/x64/*.cc))
Expand Down Expand Up @@ -153,6 +155,11 @@ vflags += -I$(output)/$(pwd/v8)

source += $(v8src)

cflags += $(vflags)
# XXX: they almost certainly already fixed this
# (this fixes the build in CI with local clang)
vflags += -include cstdint


# XXX: this now needs to be per target (due to -m$(bits))

Expand Down Expand Up @@ -229,7 +236,6 @@ source += $(filter %.cc,$(tqsrc))
header += $(filter %.h %.inc,$(tqsrc))


cflags += $(vflags)
cflags += -I$(pwd/v8)/src
cflags += -I$(pwd/v8)/include
cflags += -I$(pwd)/extra
Expand All @@ -246,7 +252,13 @@ cflags += -DU_SHOW_INTERNAL_API
#chacks/$(pwd/v8)/src/./profiler/heap-snapshot-generator.cc += s/V8_CC_MSVC/1/
cflags += -mno-ms-bitfields

# this might have to become global if that bitfield is exported
cflags/$(pwd/v8)/ += -Wno-enum-constexpr-conversion

# https://bugs.chromium.org/p/chromium/issues/detail?id=1016945
cflags/$(pwd/v8)/ += -Wno-builtin-assume-aligned-alignment

# XXX: they might have already changed many of these cases
cflags/$(pwd/v8)/ += -Wno-unused-but-set-variable

archive += $(pwd/v8)/
3 changes: 3 additions & 0 deletions min-wireshark/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ cflags/$(pwd/wireshark)/ += -Wno-pointer-sign
# XXX: fwrite used without check; submit patch
cflags/$(pwd/wireshark)/ += -Wno-unused-result

# XXX: this is only used if you have libgnutls and I don't know what I think about that :/
cflags/$(pwd/wireshark)/epan/dissectors/packet-tls-utils.c += -Wno-unused-but-set-variable

cflags/$(pwd/wireshark)/ += -I$(pwd/wireshark)/epan
cflags/$(pwd/wireshark)/ += -I$(pwd/wireshark)/epan/dfilter
cflags/$(pwd/wireshark)/ += -I$(pwd/wireshark)/epan/dissectors
Expand Down
2 changes: 1 addition & 1 deletion min-zlib/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

source += $(wildcard $(pwd)/libz/*.c)
archive += $(pwd)/libz/
cflags/$(pwd)/libz/ += -Wno-deprecated-non-prototype
cflags/$(pwd)/libz/ += -Wno-unused-function
cflags/$(pwd)/libz/ += -Wno-unused-variable
qflags += -DCHROMIUM_ZLIB_NO_CHROMECONF
cflags += -I$(pwd)/libz
cflags += -I$(pwd)/extra
Expand Down
2 changes: 1 addition & 1 deletion p2p/boost
Submodule boost updated 136 files
2 changes: 1 addition & 1 deletion p2p/c-ares
Submodule c-ares updated 403 files
6 changes: 4 additions & 2 deletions p2p/source/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,13 +817,15 @@ class Flat final :
Flat(const Buffer &buffer) :
data_(nullptr)
{
if ((copy_ = !buffer.each([&](const uint8_t *data, size_t size) {
copy_ = !buffer.each([&](const uint8_t *data, size_t size) {
if (data_ != nullptr)
return false;
size_ = size;
data_ = data;
return true;
}))) {
});

if (copy_) {
size_ = buffer.size();
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
const auto data(new uint8_t[size_]);
Expand Down
2 changes: 1 addition & 1 deletion p2p/source/cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Cache {
}

Type_ &operator ()(const Args_ &args) {
std::unique_lock<std::mutex> lock(mutex_);
const std::unique_lock<std::mutex> lock(mutex_);
const auto &cache(cache_.find(args));
if (cache != cache_.end())
return cache->second;
Expand Down
16 changes: 9 additions & 7 deletions p2p/source/category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@

namespace orc {

// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
static std::mutex mutex_;
static std::map<int, std::exception_ptr> errors_;
static int index_(0);
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
namespace {
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
std::mutex mutex_;
std::map<int, std::exception_ptr> errors_;
int index_(0);
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
}

std::string Category::message(int index) const {
try {
Expand All @@ -43,14 +45,14 @@ std::string Category::message(int index) const {
}

std::exception_ptr Category::Convert(int index) noexcept {
std::unique_lock<std::mutex> lock(mutex_);
const std::unique_lock<std::mutex> lock(mutex_);
if (const auto error = errors_.extract(index))
return error.mapped();
orc_insist(false);
}

boost::system::error_code Category::Convert(const std::exception_ptr &error) noexcept {
std::unique_lock<std::mutex> lock(mutex_);
const std::unique_lock<std::mutex> lock(mutex_);
// XXX: clang-tidy might need fixing, as this just bans ?:
// NOLINTNEXTLINE(readability-implicit-bool-conversion)
while (!errors_.try_emplace(++index_ ?: ++index_, error).second);
Expand Down
17 changes: 10 additions & 7 deletions p2p/source/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@

namespace orc {

static std::optional<Address> MaybeAddress(const Json::Value &address) {
namespace {
std::optional<Address> MaybeAddress(const Json::Value &address) {
if (address.isNull())
return std::nullopt;
return address.asString();
}
} }

static Nested Verify(const Json::Value &proofs, Brick<32> hash, const Region &path) {
namespace {
Nested Verify(const Json::Value &proofs, Brick<32> hash, const Region &path) {
size_t offset(0);
orc_assert(!proofs.isNull());
for (auto e(proofs.size()), i(decltype(e)(0)); i != e; ++i) {
Expand Down Expand Up @@ -73,7 +75,7 @@ static Nested Verify(const Json::Value &proofs, Brick<32> hash, const Region &pa

orc_assert(hash == EmptyVector);
return nullptr;
}
} }

Receipt::Receipt(Json::Value &&value) :
height_(To<uint64_t>(value["blockNumber"].asString())),
Expand Down Expand Up @@ -171,7 +173,7 @@ Record::Record(const uint256_t &chain, const Json::Value &value) :
std::vector<Bytes32> keys;
for (const auto &key : entry["storageKeys"])
keys.emplace_back(Bless(key.asString()));
access.emplace_back(decltype(access_)::value_type(entry["address"].asString(), std::move(keys)));
access.emplace_back(entry["address"].asString(), std::move(keys));
}
return access;
}(),
Expand Down Expand Up @@ -339,14 +341,15 @@ uint256_t Chain::Get(Json::Value::ArrayIndex index, const Json::Value &storages,
return value;
}

static Brick<32> Name(const std::string &name) {
namespace {
Brick<32> Name(const std::string &name) {
if (name.empty())
return Zero<32>();
const auto period(name.find('.'));
if (period == std::string::npos)
return HashK(Tie(Zero<32>(), HashK(name)));
return HashK(Tie(Name(name.substr(period + 1)), HashK(name.substr(0, period))));
}
} }

task<S<Chain>> Chain::New(Endpoint endpoint, Flags flags, uint256_t chain) {
co_return Break<Chain>(std::move(endpoint), std::move(flags), std::move(chain));
Expand Down
4 changes: 2 additions & 2 deletions p2p/source/cipher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Encipher {
Beam operator ()() const;

static Beam All(const EVP_CIPHER *algorithm, const Region &key, const Region &iv, const Buffer &data) {
Encipher cipher(algorithm, key, iv);
const Encipher cipher(algorithm, key, iv);
const auto lhs(cipher(data));
const auto rhs(cipher());
return Beam(Tie(lhs, rhs));
Expand All @@ -74,7 +74,7 @@ class Decipher {
Beam operator ()() const;

static Beam All(const EVP_CIPHER *algorithm, const Region &key, const Region &iv, const Buffer &data) {
Decipher cipher(algorithm, key, iv);
const Decipher cipher(algorithm, key, iv);
const auto lhs(cipher(data));
const auto rhs(cipher());
return Beam(Tie(lhs, rhs));
Expand Down
7 changes: 4 additions & 3 deletions p2p/source/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,12 @@ Signature::Signature(const Brick<65> &data) {
}


static const secp256k1_context *Curve() {
namespace {
const secp256k1_context *Curve() {
// NOLINTNEXTLINE(misc-redundant-expression)
static std::unique_ptr<secp256k1_context, decltype(&secp256k1_context_destroy)> context_{secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY), &secp256k1_context_destroy};
static const std::unique_ptr<secp256k1_context, decltype(&secp256k1_context_destroy)> context_{secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY), &secp256k1_context_destroy};
return context_.get();
}
} }

bool operator ==(const Key &lhs, const Key &rhs) {
const auto context(Curve());
Expand Down
4 changes: 2 additions & 2 deletions p2p/source/datagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ bool Datagram(const Buffer &data, const std::function<bool (const Socket &, cons
const auto udp(window.Take<openvpn::UDPHeader>());
orc_assert(window.size() == boost::endian::big_to_native(udp.len) - sizeof(udp));

Socket source(boost::endian::big_to_native(ip4.saddr), boost::endian::big_to_native(udp.source));
Socket destination(boost::endian::big_to_native(ip4.daddr), boost::endian::big_to_native(udp.dest));
const Socket source(boost::endian::big_to_native(ip4.saddr), boost::endian::big_to_native(udp.source));
const Socket destination(boost::endian::big_to_native(ip4.daddr), boost::endian::big_to_native(udp.dest));

return code(source, destination, std::move(window));
}, "parsing packet: " << data); }
Expand Down
4 changes: 2 additions & 2 deletions p2p/source/encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std::string utf(const std::u16string &value) {
if (value.empty())
return data;
data.resize(value.size() * 5);
int writ(WideCharToMultiByte(CP_UTF8, 0, w16(value.data()), Fit(value.size()), &data[0], Fit(data.size() * sizeof(data[0])), nullptr, nullptr))
const int writ(WideCharToMultiByte(CP_UTF8, 0, w16(value.data()), Fit(value.size()), &data[0], Fit(data.size() * sizeof(data[0])), nullptr, nullptr))
;
orc_assert(writ != 0);
data.resize(writ / sizeof(data[0]));
Expand All @@ -48,7 +48,7 @@ std::u16string utf(const std::string &value) {
if (value.empty())
return data;
data.resize(value.size());
int writ(MultiByteToWideChar(CP_UTF8, 0, value.data(), Fit(value.size() * sizeof(value[0])), w16(&data[0]), Fit(data.size())));
const int writ(MultiByteToWideChar(CP_UTF8, 0, value.data(), Fit(value.size() * sizeof(value[0])), w16(&data[0]), Fit(data.size())));
orc_assert(writ != 0);
data.resize(writ);
return data;
Expand Down
4 changes: 4 additions & 0 deletions p2p/source/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Error final :

template <typename Type_>
Error operator <<(const Type_ &value) && {
// NOLINTNEXTLINE(misc-const-correctness)
std::ostringstream data;
data << value;
what_ += data.str();
Expand Down Expand Up @@ -89,10 +90,13 @@ class Error final :
orc_log(orc_Log(), "handled error: " << error.what() << std::endl); \
code } catch (...) { code }

// XXX: clang-tidy fails to consider statement expressions
// NOLINTBEGIN(bugprone-assignment-in-if-condition)
#define orc_ignore(code) \
({ bool _failed(false); try code \
orc_catch({ _failed = true; }) \
_failed; })
// NOLINTEND(bugprone-assignment-in-if-condition)

#define orc_except(code) \
try code catch (...) { \
Expand Down
Loading

0 comments on commit 0694dd3

Please sign in to comment.