From 55165582ebfb55f2d24546d592340e46ddfd2005 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 14:59:38 +0100 Subject: [PATCH 01/19] Bring configuration for `clang-tidy` up-to-date. This patch brings our clang-tidy setup up to date. Much of this was built with `./ci/run-ci` `in mind with extra suppressions hardcoded e.g., in `.clang-tidy.ignore`. With this patch we instead configure `.clang-tidy` files so they can suppress diagnostics from certain directories. We also set up 3rdparty code to work with CMake's `clang-tidy` integration[1]. We also globally suppress some diagnostics which we have no intention of addressing. [^1]: https://cmake.org/cmake/help/latest/prop_tgt/LANG_CLANG_TIDY.html#prop_tgt:%3CLANG%3E_CLANG_TIDY --- .clang-tidy | 1 + 3rdparty/.clang-tidy | 10 ++++++++++ 3rdparty/CMakeLists.txt | 8 +++++++- hilti/runtime/include/3rdparty/.clang-tidy | 1 + hilti/runtime/src/tests/.clang-tidy | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 3rdparty/.clang-tidy create mode 120000 hilti/runtime/include/3rdparty/.clang-tidy diff --git a/.clang-tidy b/.clang-tidy index 333bbc877..39720cb7d 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,6 +4,7 @@ Checks: ' bugprone-*, -bugprone-easily-swappable-parameters, + -bugprone-exception-escape, -bugprone-reserved-identifier, -bugprone-branch-clone, -bugprone-macro-parentheses, diff --git a/3rdparty/.clang-tidy b/3rdparty/.clang-tidy new file mode 100644 index 000000000..60692b177 --- /dev/null +++ b/3rdparty/.clang-tidy @@ -0,0 +1,10 @@ +# Copyright (c) 2020-2023 by the Zeek Project. See LICENSE for details. + +--- +# We want to disable clang-tidy checks for all files under this directory, but +# clang-tidy cannot run with all checks disabled. Instead enable an inexpensive +# check and configure it so it matches nothing, see +# https://stackoverflow.com/a/58379342/176922. +Checks: '-*,misc-definitions-in-headers' +CheckOptions: + - { key: HeaderFileExtensions, value: "x" } diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 68655ce65..59ce1d1a1 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -1,3 +1,10 @@ +# If we run clang-tidy as part of CMake we never want to check files in this +# directory. We specify this in addition to the local `.clang-tidy` in this +# directory since it is only valid in subdirectories which do not provided +# their on `.clang-tidy` config. +set(CMAKE_C_CLANG_TIDY "") +set(CMAKE_CXX_CLANG_TIDY "") + # Note that most of the subdirectories here don't need to be known # to CMake because we directly pick out the pieces where we need # them. @@ -7,7 +14,6 @@ add_subdirectory(doctest) add_subdirectory(justrx) - # Use the configured C compiler as ASM compiler as well. This prevents that we # e.g., use a Clang as C compiler, but e.g., GCC as assembler which leads to # incompatible flags like `-Weverything` being passed to GCC from e.g., diff --git a/hilti/runtime/include/3rdparty/.clang-tidy b/hilti/runtime/include/3rdparty/.clang-tidy new file mode 120000 index 000000000..245ba124b --- /dev/null +++ b/hilti/runtime/include/3rdparty/.clang-tidy @@ -0,0 +1 @@ +../../../../3rdparty/.clang-tidy \ No newline at end of file diff --git a/hilti/runtime/src/tests/.clang-tidy b/hilti/runtime/src/tests/.clang-tidy index fc05f23f6..3e44c0401 100644 --- a/hilti/runtime/src/tests/.clang-tidy +++ b/hilti/runtime/src/tests/.clang-tidy @@ -2,5 +2,6 @@ --- Checks: ' + -clang-analyzer-optin.core.EnumCastOutOfRange, -modernize-type-traits, ' From dc7931fe19029df0ed9c6cdfae919098e91936bf Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 13:52:41 +0100 Subject: [PATCH 02/19] Fix APIs where we assumed a string_view was null-terminated. This either switches to using `const char*` to signify guaranteed null termination, or locally suppress clang-tidy warnings about assuming null-terminated string_views. --- hilti/runtime/include/fmt.h | 14 ++++++++++++-- hilti/runtime/include/library.h | 3 +-- hilti/runtime/src/library.cc | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/hilti/runtime/include/fmt.h b/hilti/runtime/include/fmt.h index eba44b35f..4e6c46a95 100644 --- a/hilti/runtime/include/fmt.h +++ b/hilti/runtime/include/fmt.h @@ -17,7 +17,17 @@ std::string fmt(const char* fmt, const Args&... args) { /** sprintf-style string formatting. */ template std::string fmt(std::string_view s, const Args&... args) { - // In generated code `s` is always null-terminated. - return fmt(s.data(), args...); + // In principal we do not know whether the passed `string_view` is + // null-terminated, so `s.data()` could end up accessing out of bounds + // data. In generated code `s` is always null-terminated though. + // + // NOTE: If we ever wanted to make this safe for views not null-terminated, + // a fix would be to expand `s` into a true, null-terminated `const char*`, + // e.g., + // + // char buf[1024]; + // snprintf(buf, sizeof(buf), "%.*s", static_cast(s.length()), s.data()); + // return fmt(buf, args...); + return fmt(s.data(), args...); // NOLINT(bugprone-suspicious-stringview-data-usage) } } // namespace hilti::rt diff --git a/hilti/runtime/include/library.h b/hilti/runtime/include/library.h index cbfe07f2d..728bb9033 100644 --- a/hilti/runtime/include/library.h +++ b/hilti/runtime/include/library.h @@ -3,7 +3,6 @@ #pragma once #include -#include #include #include @@ -93,7 +92,7 @@ class Library { // // @param name name of the symbol // @return a valid pointer to the symbol or an error - hilti::rt::Result symbol(std::string_view name) const; + hilti::rt::Result symbol(const char* name) const; /* * Remove the file corresponding to this library without unloading it. diff --git a/hilti/runtime/src/library.cc b/hilti/runtime/src/library.cc index 3cde27958..f24b83771 100644 --- a/hilti/runtime/src/library.cc +++ b/hilti/runtime/src/library.cc @@ -85,14 +85,14 @@ hilti::rt::Result hilti::rt::Library::open() const return version; } -hilti::rt::Result hilti::rt::Library::symbol(std::string_view name) const { +hilti::rt::Result hilti::rt::Library::symbol(const char* name) const { if ( ! _handle ) return result::Error(fmt("library %s has not been opened", _path)); // Clear any library errors. ::dlerror(); - auto* symbol = ::dlsym(_handle, name.data()); + auto* symbol = ::dlsym(_handle, name); if ( ::dlerror() ) return result::Error(fmt("symbol '%s' not found", name)); From 3c7983254b121f3afaca1670c1b3f8fcc8533f7b Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:01:43 +0100 Subject: [PATCH 03/19] Prefer `std::max` over ad hoc implementations. --- hilti/runtime/src/fiber.cc | 2 ++ hilti/toolchain/include/base/util.h | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hilti/runtime/src/fiber.cc b/hilti/runtime/src/fiber.cc index 4d5a68294..6a6b8f296 100644 --- a/hilti/runtime/src/fiber.cc +++ b/hilti/runtime/src/fiber.cc @@ -219,6 +219,7 @@ detail::Fiber::Fiber(Type type) : _type(type), _fiber(std::make_unique<::Fiber>( ++_total_fibers; ++_current_fibers; + // NOLINTNEXTLINE(readability-use-std-min-max) if ( _current_fibers > _max_fibers ) _max_fibers = _current_fibers; } @@ -652,6 +653,7 @@ void detail::trackStack() { return; if ( fiber->type() == Fiber::Type::IndividualStack || fiber->type() == Fiber::Type::SharedStack ) { + // NOLINTNEXTLINE(readability-use-std-min-max) if ( auto size = fiber->stackBuffer().activeSize(); size > detail::Fiber::_max_stack_size ) detail::Fiber::_max_stack_size = size; } diff --git a/hilti/toolchain/include/base/util.h b/hilti/toolchain/include/base/util.h index 3d79a0f19..140eaeafe 100644 --- a/hilti/toolchain/include/base/util.h +++ b/hilti/toolchain/include/base/util.h @@ -176,11 +176,9 @@ std::vector slice(const std::vector& v, int begin, int end = -1) { if ( end < 0 ) end = v.size() + end + 1; - if ( begin < 0 ) - begin = 0; + begin = std::max(begin, 0); - if ( end < 0 ) - end = 0; + end = std::max(end, 0); if ( static_cast(end) > v.size() ) end = v.size(); From d3f2b8d6d0417c84b151134fc18240b4cd09ae61 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:20:46 +0100 Subject: [PATCH 04/19] Locally suppress `clang-tidy` diagnostic. This suppresses a `clang-tidy` lint suggesting to mark our default `main` function as not exported. This function is shipped as part of libhilti and intended to be available as a weak symbol. --- hilti/runtime/src/main.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/hilti/runtime/src/main.cc b/hilti/runtime/src/main.cc index c66a0669e..539a0fa4c 100644 --- a/hilti/runtime/src/main.cc +++ b/hilti/runtime/src/main.cc @@ -19,6 +19,7 @@ static void usage(const char* prog) { } namespace hilti { +// NOLINTNEXTLINE(misc-use-internal-linkage) int main(int argc, char** argv); } // namespace hilti From 537babae2bd094ef3aa181a08d3780bf49589038 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:03:16 +0100 Subject: [PATCH 05/19] Consistently mark functions and values not exposed `static`. --- hilti/runtime/src/context.cc | 2 +- hilti/runtime/src/profiler.cc | 2 +- hilti/runtime/src/safe-math.cc | 2 +- hilti/runtime/src/types/address.cc | 2 +- hilti/runtime/src/types/real.cc | 2 +- hilti/toolchain/bin/hilti-config.cc | 4 ++-- hilti/toolchain/src/ast/ast-context.cc | 7 ++++--- hilti/toolchain/src/compiler/coercer.cc | 2 +- hilti/toolchain/src/compiler/cxx/elements.cc | 5 +++-- hilti/toolchain/src/compiler/optimizer.cc | 6 +++--- hilti/toolchain/tests/id-base.cc | 2 +- spicy/toolchain/bin/spicy-batch-extract.cc | 4 ++-- spicy/toolchain/bin/spicy-config.cc | 4 ++-- spicy/toolchain/src/config.cc.in | 2 +- spicy/toolchain/tests/grammar.cc | 2 +- 15 files changed, 25 insertions(+), 23 deletions(-) diff --git a/hilti/runtime/src/context.cc b/hilti/runtime/src/context.cc index 0d1b73e8c..91239599e 100644 --- a/hilti/runtime/src/context.cc +++ b/hilti/runtime/src/context.cc @@ -14,7 +14,7 @@ using namespace hilti::rt::detail; namespace hilti::rt::context::detail { // Not part of global state, it's per thread. -HILTI_THREAD_LOCAL Context* __current = nullptr; +static HILTI_THREAD_LOCAL Context* __current = nullptr; Context*& current() { return __current; } diff --git a/hilti/runtime/src/profiler.cc b/hilti/runtime/src/profiler.cc index fc3f6de94..06c9de196 100644 --- a/hilti/runtime/src/profiler.cc +++ b/hilti/runtime/src/profiler.cc @@ -12,7 +12,7 @@ using namespace hilti::rt; using namespace hilti::rt::profiler; // Helper to get a platform-specific, monotonic high-resolution clock. -inline uint64_t _getClock() { +inline static uint64_t _getClock() { #if defined(__APPLE__) return clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW); #else diff --git a/hilti/runtime/src/safe-math.cc b/hilti/runtime/src/safe-math.cc index 7729f6719..188245aed 100644 --- a/hilti/runtime/src/safe-math.cc +++ b/hilti/runtime/src/safe-math.cc @@ -5,7 +5,7 @@ using namespace hilti::rt; -[[noreturn]] inline void safe_math_fail(const char* msg) { throw OutOfRange("integer value out of range"); } +[[noreturn]] inline static void safe_math_fail(const char* msg) { throw OutOfRange("integer value out of range"); } #define SAFE_MATH_FAIL_DEFINED extern "C" { diff --git a/hilti/runtime/src/types/address.cc b/hilti/runtime/src/types/address.cc index 8c57b6ebd..c820ed1a8 100644 --- a/hilti/runtime/src/types/address.cc +++ b/hilti/runtime/src/types/address.cc @@ -148,7 +148,7 @@ Bytes Address::pack(ByteOrder fmt) const { } template -Result> _unpack(const T& data, AddressFamily family, ByteOrder fmt) { +static Result> _unpack(const T& data, AddressFamily family, ByteOrder fmt) { switch ( family.value() ) { case AddressFamily::IPv4: { if ( data.size() < 4 ) diff --git a/hilti/runtime/src/types/real.cc b/hilti/runtime/src/types/real.cc index a67c494a6..b05064428 100644 --- a/hilti/runtime/src/types/real.cc +++ b/hilti/runtime/src/types/real.cc @@ -27,7 +27,7 @@ Bytes real::pack(double d, real::Type type, ByteOrder fmt) { } template -Result> _unpack(const T& data, real::Type type, ByteOrder fmt) { +static Result> _unpack(const T& data, real::Type type, ByteOrder fmt) { switch ( type.value() ) { case real::Type::IEEE754_Single: { if ( data.size() < 4 ) diff --git a/hilti/toolchain/bin/hilti-config.cc b/hilti/toolchain/bin/hilti-config.cc index 42bd2d064..83d941474 100644 --- a/hilti/toolchain/bin/hilti-config.cc +++ b/hilti/toolchain/bin/hilti-config.cc @@ -12,7 +12,7 @@ using namespace std; -void usage() { +static void usage() { std::cerr << R"( Usage: hilti-config [options] @@ -45,7 +45,7 @@ Available options: } template -void join(std::vector& a, const std::vector& b) { +static void join(std::vector& a, const std::vector& b) { a.insert(a.end(), b.begin(), b.end()); } diff --git a/hilti/toolchain/src/ast/ast-context.cc b/hilti/toolchain/src/ast/ast-context.cc index f1528582e..1c2cf3a99 100644 --- a/hilti/toolchain/src/ast/ast-context.cc +++ b/hilti/toolchain/src/ast/ast-context.cc @@ -532,7 +532,8 @@ declaration::module::UID ASTContext::_addModuleToAST(declaration::Module* module } template -Result _runHook(const Plugin& plugin, PluginMember hook, const std::string& description, const Args&... args) { +static Result _runHook(const Plugin& plugin, PluginMember hook, const std::string& description, + const Args&... args) { if ( ! (plugin.*hook) ) return Nothing(); @@ -548,8 +549,8 @@ Result _runHook(const Plugin& plugin, PluginMember hook, const std::str } template -Result _runHook(bool* modified, const Plugin& plugin, PluginMember hook, const std::string& description, - const Args&... args) { +static Result _runHook(bool* modified, const Plugin& plugin, PluginMember hook, const std::string& description, + const Args&... args) { if ( ! (plugin.*hook) ) return Nothing(); diff --git a/hilti/toolchain/src/compiler/coercer.cc b/hilti/toolchain/src/compiler/coercer.cc index 5a4ebd37a..f92e209fa 100644 --- a/hilti/toolchain/src/compiler/coercer.cc +++ b/hilti/toolchain/src/compiler/coercer.cc @@ -927,7 +927,7 @@ Result> hilti::coerceOperands(Builder* builder, ope // If an expression is a reference, dereference it; otherwise return the // expression itself. -Expression* skipReferenceValue(Builder* builder, Expression* op) { +static Expression* skipReferenceValue(Builder* builder, Expression* op) { static auto value_reference_deref = operator_::get("value_reference::Deref"); static auto strong_reference_deref = operator_::get("strong_reference::Deref"); static auto weak_reference_deref = operator_::get("weak_reference::Deref"); diff --git a/hilti/toolchain/src/compiler/cxx/elements.cc b/hilti/toolchain/src/compiler/cxx/elements.cc index 8ce957996..5d517ec1b 100644 --- a/hilti/toolchain/src/compiler/cxx/elements.cc +++ b/hilti/toolchain/src/compiler/cxx/elements.cc @@ -211,8 +211,9 @@ void cxx::Block::addComment(const std::string& stmt, bool sep_before, bool sep_a _stmts.emplace_back(fmt("// %s", stmt), Block(), f); } -inline std::string fmtDeclaration(const cxx::ID& id, const cxx::Type& type, const std::vector& args, - std::string linkage = "", std::optional init = {}) { +inline static std::string fmtDeclaration(const cxx::ID& id, const cxx::Type& type, + const std::vector& args, std::string linkage = "", + std::optional init = {}) { std::string sinit; if ( init ) diff --git a/hilti/toolchain/src/compiler/optimizer.cc b/hilti/toolchain/src/compiler/optimizer.cc index 829e514ad..5cf31d9da 100644 --- a/hilti/toolchain/src/compiler/optimizer.cc +++ b/hilti/toolchain/src/compiler/optimizer.cc @@ -45,7 +45,7 @@ inline const DebugStream OptimizerCollect("optimizer-collect"); } // namespace logging::debug // Helper function to extract innermost type, removing any wrapping in reference or container types. -QualifiedType* innermostType(QualifiedType* type) { +static QualifiedType* innermostType(QualifiedType* type) { if ( type->type()->isReferenceType() ) return innermostType(type->type()->dereferencedType()); @@ -55,10 +55,10 @@ QualifiedType* innermostType(QualifiedType* type) { return type; } -bool isFeatureFlag(const ID& id) { return util::startsWith(id.local(), "__feat%"); } +static bool isFeatureFlag(const ID& id) { return util::startsWith(id.local(), "__feat%"); } // Helper to extract `(ID, feature)` from a feature constant. -auto idFeatureFromConstant(const ID& featureConstant) -> std::optional> { +static auto idFeatureFromConstant(const ID& featureConstant) -> std::optional> { const auto& id = featureConstant.local(); if ( ! isFeatureFlag(id) ) diff --git a/hilti/toolchain/tests/id-base.cc b/hilti/toolchain/tests/id-base.cc index eb12393dd..f724b3fbd 100644 --- a/hilti/toolchain/tests/id-base.cc +++ b/hilti/toolchain/tests/id-base.cc @@ -9,7 +9,7 @@ using namespace hilti; -std::optional normalizeID(std::string_view id) { +static std::optional normalizeID(std::string_view id) { if ( id.substr(0, 1) == "%" ) return std::string("XXX_") + std::string(id.substr(1)); diff --git a/spicy/toolchain/bin/spicy-batch-extract.cc b/spicy/toolchain/bin/spicy-batch-extract.cc index 70b9a5e54..c7d8543d6 100644 --- a/spicy/toolchain/bin/spicy-batch-extract.cc +++ b/spicy/toolchain/bin/spicy-batch-extract.cc @@ -7,12 +7,12 @@ #include -void error(const std::string& msg) { +static void error(const std::string& msg) { std::cerr << "error: " << msg << '\n'; exit(1); } -void processPreBatchedInput(std::string needle, std::istream& in, std::ostream& out) { +static void processPreBatchedInput(std::string needle, std::istream& in, std::ostream& out) { std::string magic; std::getline(in, magic); diff --git a/spicy/toolchain/bin/spicy-config.cc b/spicy/toolchain/bin/spicy-config.cc index d3117c549..244326ed5 100644 --- a/spicy/toolchain/bin/spicy-config.cc +++ b/spicy/toolchain/bin/spicy-config.cc @@ -14,7 +14,7 @@ using namespace std; -void usage() { +static void usage() { std::cerr << R"( Usage: spicy-config [options] @@ -49,7 +49,7 @@ Available options: } template -void join(std::vector& a, const std::vector& b) { +static void join(std::vector& a, const std::vector& b) { a.insert(a.end(), b.begin(), b.end()); } diff --git a/spicy/toolchain/src/config.cc.in b/spicy/toolchain/src/config.cc.in index c947f5149..9ae62b017 100644 --- a/spicy/toolchain/src/config.cc.in +++ b/spicy/toolchain/src/config.cc.in @@ -50,7 +50,7 @@ void set_precompiled_header(const hilti::Configuration& config, bool debug, std: } // namespace template -inline auto join(const std::vector& v1, const std::vector& v2) { +inline static auto join(const std::vector& v1, const std::vector& v2) { std::vector n; n.reserve(v1.size() + v2.size()); diff --git a/spicy/toolchain/tests/grammar.cc b/spicy/toolchain/tests/grammar.cc index cce45609e..310b8554e 100644 --- a/spicy/toolchain/tests/grammar.cc +++ b/spicy/toolchain/tests/grammar.cc @@ -16,7 +16,7 @@ using Ps = std::vector>; template -auto make_prods(Args... args) { +static auto make_prods(Args... args) { std::vector> rv; (rv.emplace_back(std::move(args)), ...); return rv; From 149ed47c15476609bb67ba07bf14857a2981f372 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:04:21 +0100 Subject: [PATCH 06/19] Fix APIs taking `std::string_view` assuming them to be null-terminated. In general `std::string_view` values do not need to be null-terminated, e.g., if they reference subranges in a bigger null-terminated string. We were previously passing `std::string_view` in a few places where we assumed them to be null-terminated, e.g., for passing them on to C APIs expecting null-terminated `const char*`. These worked well enough for us for now, but these APIs were generally unsafe. This patch switches to instead passing either `const char*` signalling proper, null-terminated strings, or by passing in a `const std::string&` where it should already be present in the caller. --- hilti/toolchain/include/base/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hilti/toolchain/include/base/util.h b/hilti/toolchain/include/base/util.h index 140eaeafe..5aa4bc4d5 100644 --- a/hilti/toolchain/include/base/util.h +++ b/hilti/toolchain/include/base/util.h @@ -587,7 +587,7 @@ constexpr auto from_string(std::string_view name, const Value (&values)[Si if ( v.name == name ) return v.value; - throw std::out_of_range(name.data()); + throw std::out_of_range(std::string(name.begin(), name.size())); }; /** From 7469376f3067b54bba46f092f9bd78d14394b51c Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:05:03 +0100 Subject: [PATCH 07/19] Remove unneeded copies. --- hilti/runtime/src/types/regexp.cc | 2 +- hilti/toolchain/include/compiler/printer.h | 2 +- hilti/toolchain/src/base/util.cc | 2 +- hilti/toolchain/src/compiler/optimizer.cc | 2 +- hilti/toolchain/src/config.cc.in | 10 +++++----- spicy/runtime/src/sink.cc | 2 +- spicy/toolchain/src/config.cc.in | 15 +++++++++------ 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/hilti/runtime/src/types/regexp.cc b/hilti/runtime/src/types/regexp.cc index 43237d718..c58f6c906 100644 --- a/hilti/runtime/src/types/regexp.cc +++ b/hilti/runtime/src/types/regexp.cc @@ -435,7 +435,7 @@ std::string hilti::rt::detail::adl::to_string(const RegExp& x, adl::tag /*unused if ( x.patterns().empty() ) return ""; - auto p = join(transform(x.patterns(), [&](auto s) { return fmt("/%s/", s); }), " | "); + auto p = join(transform(x.patterns(), [&](const auto& s) { return fmt("/%s/", s); }), " | "); auto f = std::vector(); diff --git a/hilti/toolchain/include/compiler/printer.h b/hilti/toolchain/include/compiler/printer.h index ceed57b0e..929df7593 100644 --- a/hilti/toolchain/include/compiler/printer.h +++ b/hilti/toolchain/include/compiler/printer.h @@ -123,7 +123,7 @@ class Stream { // Output lists. template - Stream& operator<<(std::pair p) { + Stream& operator<<(const std::pair& p) { bool first = true; for ( const auto& i : p.first ) { _flush_pending(); diff --git a/hilti/toolchain/src/base/util.cc b/hilti/toolchain/src/base/util.cc index 8a8f3fe99..c42c68bd1 100644 --- a/hilti/toolchain/src/base/util.cc +++ b/hilti/toolchain/src/base/util.cc @@ -275,7 +275,7 @@ std::string util::prefixParts(const std::string& in, const std::string& prefix, return x; }); - return join(filter(x, [](auto s) -> bool { return s.size(); }), " "); + return join(filter(x, [](const auto& s) -> bool { return s.size(); }), " "); } std::vector util::flattenParts(const std::vector& in) { diff --git a/hilti/toolchain/src/compiler/optimizer.cc b/hilti/toolchain/src/compiler/optimizer.cc index 5cf31d9da..454b615e7 100644 --- a/hilti/toolchain/src/compiler/optimizer.cc +++ b/hilti/toolchain/src/compiler/optimizer.cc @@ -1530,7 +1530,7 @@ struct MemberVisitor : OptimizerVisitor { assert(tokens.size() == 3); auto type_id = ID(tokens[1]); - auto feature = tokens[2]; + const auto& feature = tokens[2]; auto is_active = n->value()->as()->ctor()->as()->value(); type_id = ID(util::replace(type_id, "@@", "::")); diff --git a/hilti/toolchain/src/config.cc.in b/hilti/toolchain/src/config.cc.in index f36bdd614..b1d4fdbb0 100644 --- a/hilti/toolchain/src/config.cc.in +++ b/hilti/toolchain/src/config.cc.in @@ -105,23 +105,23 @@ void Configuration::init(bool use_build_directory) { library_paths = flatten({".", prefix("${HILTI_CONFIG_LIBRARY_DIRS}", "", installation_tag)}); } - hilti_library_paths = util::transform(library_paths, [](auto s) { return hilti::rt::filesystem::path(s); }); + hilti_library_paths = util::transform(library_paths, [](const auto& s) { return hilti::rt::filesystem::path(s); }); runtime_cxx_include_paths = util::transform(hilti::util::split(prefix("${HILTI_CONFIG_RUNTIME_CXX_INCLUDE_DIRS}", "", installation_tag)), - [](auto s) { return hilti::rt::filesystem::path(s); }); + [](const auto& s) { return hilti::rt::filesystem::path(s); }); runtime_cxx_library_paths = util::transform(hilti::util::split(prefix("${HILTI_CONFIG_RUNTIME_CXX_LIBRARY_DIRS}", "", installation_tag)), - [](auto s) { return hilti::rt::filesystem::path(s); }); + [](const auto& s) { return hilti::rt::filesystem::path(s); }); toolchain_cxx_include_paths = util::transform(hilti::util::split(prefix("${HILTI_CONFIG_TOOLCHAIN_CXX_INCLUDE_DIRS}", "", installation_tag)), - [](auto s) { return hilti::rt::filesystem::path(s); }); + [](const auto& s) { return hilti::rt::filesystem::path(s); }); toolchain_cxx_library_paths = util::transform(hilti::util::split(prefix("${HILTI_CONFIG_TOOLCHAIN_CXX_LIBRARY_DIRS}", "", installation_tag)), - [](auto s) { return hilti::rt::filesystem::path(s); }); + [](const auto& s) { return hilti::rt::filesystem::path(s); }); // We hardcode the main compiler flags here instead of injecting them from // CMake to make it clear that they are really independent on what CMake diff --git a/spicy/runtime/src/sink.cc b/spicy/runtime/src/sink.cc index 3b02f0e0b..c462bc8d3 100644 --- a/spicy/runtime/src/sink.cc +++ b/spicy/runtime/src/sink.cc @@ -380,7 +380,7 @@ void Sink::_debugReassemblerBuffer(std::string_view msg) const { } void Sink::connect_mime_type(const MIMEType& mt, std::string_view scope) { - auto connect_matching = [&](auto mt) { + auto connect_matching = [&](const auto& mt) { if ( const auto& x = detail::globalState()->parsers_by_mime_type.find(mt.asKey()); x != detail::globalState()->parsers_by_mime_type.end() ) { for ( const auto& p : x->second ) { diff --git a/spicy/toolchain/src/config.cc.in b/spicy/toolchain/src/config.cc.in index 9ae62b017..de9f59121 100644 --- a/spicy/toolchain/src/config.cc.in +++ b/spicy/toolchain/src/config.cc.in @@ -1,6 +1,7 @@ // Copyright (c) 2020-2023 by the Zeek Project. See LICENSE for details. #include +#include #include @@ -99,33 +100,35 @@ void Configuration::init(bool use_build_directory) { std::vector library_paths; if ( auto path = std::getenv("SPICY_PATH") ) { - library_paths = hilti::util::transform(hilti::util::split(path, ":"), [](auto s) { return std::string(s); }); + library_paths = + hilti::util::transform(hilti::util::split(path, ":"), [](auto s) { return std::string(std::move(s)); }); } else { library_paths = flatten({".", prefix("${SPICY_CONFIG_LIBRARY_DIRS}", "", installation_tag)}); } - spicy_library_paths = hilti::util::transform(library_paths, [](auto s) { return hilti::rt::filesystem::path(s); }); + spicy_library_paths = + hilti::util::transform(library_paths, [](const auto& s) { return hilti::rt::filesystem::path(s); }); runtime_cxx_include_paths = hilti::util::transform(hilti::util::split( prefix("${SPICY_CONFIG_RUNTIME_CXX_INCLUDE_DIRS}", "", installation_tag)), - [](auto s) { return hilti::rt::filesystem::path(s); }); + [](const auto& s) { return hilti::rt::filesystem::path(s); }); runtime_cxx_library_paths = hilti::util::transform(hilti::util::split( prefix("${SPICY_CONFIG_RUNTIME_CXX_LIBRARY_DIRS}", "", installation_tag)), - [](auto s) { return hilti::rt::filesystem::path(s); }); + [](const auto& s) { return hilti::rt::filesystem::path(s); }); toolchain_cxx_include_paths = hilti::util::transform(hilti::util::split( prefix("${SPICY_CONFIG_TOOLCHAIN_CXX_INCLUDE_DIRS}", "", installation_tag)), - [](auto s) { return hilti::rt::filesystem::path(s); }); + [](const auto& s) { return hilti::rt::filesystem::path(s); }); toolchain_cxx_library_paths = hilti::util::transform(hilti::util::split( prefix("${SPICY_CONFIG_TOOLCHAIN_CXX_LIBRARY_DIRS}", "", installation_tag)), - [](auto s) { return hilti::rt::filesystem::path(s); }); + [](const auto& s) { return hilti::rt::filesystem::path(s); }); runtime_cxx_flags_debug = flatten({prefix("${SPICY_CONFIG_RUNTIME_CXX_INCLUDE_DIRS}", "-I", installation_tag), prefix("${SPICY_CONFIG_RUNTIME_CXX_FLAGS_DEBUG}", "", installation_tag)}); From e2d7090abc4732fb6042f42ef386aa967edfe36e Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:05:25 +0100 Subject: [PATCH 08/19] Consistently pass `std::string_view` by value. `std::string_view` is a type which is designed to be (very) cheap to copy. --- hilti/toolchain/include/ast/declaration.h | 2 +- hilti/toolchain/include/ast/declarations/parameter.h | 2 +- hilti/toolchain/include/ast/expressions/keyword.h | 2 +- hilti/toolchain/include/ast/function.h | 2 +- hilti/toolchain/include/ast/types/function.h | 2 +- hilti/toolchain/include/base/logger.h | 2 +- hilti/toolchain/tests/util.cc | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hilti/toolchain/include/ast/declaration.h b/hilti/toolchain/include/ast/declaration.h index 458951252..e256f2293 100644 --- a/hilti/toolchain/include/ast/declaration.h +++ b/hilti/toolchain/include/ast/declaration.h @@ -39,7 +39,7 @@ namespace linkage { * * @exception `std::out_of_range` if the string does not map to a linkage */ -constexpr auto from_string(const std::string_view& s) { return util::enum_::from_string(s, detail::Linkages); } +constexpr auto from_string(std::string_view s) { return util::enum_::from_string(s, detail::Linkages); } } // namespace linkage } // namespace declaration diff --git a/hilti/toolchain/include/ast/declarations/parameter.h b/hilti/toolchain/include/ast/declarations/parameter.h index 8715d049b..b1830e216 100644 --- a/hilti/toolchain/include/ast/declarations/parameter.h +++ b/hilti/toolchain/include/ast/declarations/parameter.h @@ -37,7 +37,7 @@ constexpr util::enum_::Value Kinds[] = { constexpr auto to_string(Kind k) { return util::enum_::to_string(k, detail::Kinds); } namespace kind { -constexpr auto from_string(const std::string_view& s) { return util::enum_::from_string(s, detail::Kinds); } +constexpr auto from_string(std::string_view s) { return util::enum_::from_string(s, detail::Kinds); } } // namespace kind } // namespace hilti::parameter diff --git a/hilti/toolchain/include/ast/expressions/keyword.h b/hilti/toolchain/include/ast/expressions/keyword.h index 00af282c5..f2a367978 100644 --- a/hilti/toolchain/include/ast/expressions/keyword.h +++ b/hilti/toolchain/include/ast/expressions/keyword.h @@ -30,7 +30,7 @@ constexpr util::enum_::Value Kinds[] = {{Kind::Self, "self"}, } // namespace detail namespace kind { -constexpr auto from_string(const std::string_view& s) { return util::enum_::from_string(s, detail::Kinds); } +constexpr auto from_string(std::string_view s) { return util::enum_::from_string(s, detail::Kinds); } } // namespace kind constexpr auto to_string(Kind m) { return util::enum_::to_string(m, detail::Kinds); } diff --git a/hilti/toolchain/include/ast/function.h b/hilti/toolchain/include/ast/function.h index a50a9b255..4cc84025a 100644 --- a/hilti/toolchain/include/ast/function.h +++ b/hilti/toolchain/include/ast/function.h @@ -34,7 +34,7 @@ constexpr util::enum_::Value Conventions[] = { constexpr auto to_string(CallingConvention cc) { return util::enum_::to_string(cc, detail::Conventions); } namespace calling_convention { -constexpr auto from_string(const std::string_view& s) { +constexpr auto from_string(std::string_view s) { return util::enum_::from_string(s, detail::Conventions); } } // namespace calling_convention diff --git a/hilti/toolchain/include/ast/types/function.h b/hilti/toolchain/include/ast/types/function.h index 5382680c4..f05986bad 100644 --- a/hilti/toolchain/include/ast/types/function.h +++ b/hilti/toolchain/include/ast/types/function.h @@ -40,7 +40,7 @@ constexpr util::enum_::Value Flavors[] = { constexpr auto to_string(Flavor f) { return util::enum_::to_string(f, detail::Flavors); } namespace flavor { -constexpr auto from_string(const std::string_view& s) { return util::enum_::from_string(s, detail::Flavors); } +constexpr auto from_string(std::string_view s) { return util::enum_::from_string(s, detail::Flavors); } } // namespace flavor } // namespace function diff --git a/hilti/toolchain/include/base/logger.h b/hilti/toolchain/include/base/logger.h index 1c4807b84..aafd963e1 100644 --- a/hilti/toolchain/include/base/logger.h +++ b/hilti/toolchain/include/base/logger.h @@ -65,7 +65,7 @@ constexpr util::enum_::Value Levels[] = { constexpr auto to_string(Level m) { return util::enum_::to_string(m, detail::Levels); } namespace level { -constexpr auto from_string(const std::string_view& s) { return util::enum_::from_string(s, detail::Levels); } +constexpr auto from_string(std::string_view s) { return util::enum_::from_string(s, detail::Levels); } } // namespace level /** Ostream-variant that forwards output to the central logger. */ diff --git a/hilti/toolchain/tests/util.cc b/hilti/toolchain/tests/util.cc index be3721888..41a4a42ad 100644 --- a/hilti/toolchain/tests/util.cc +++ b/hilti/toolchain/tests/util.cc @@ -24,7 +24,7 @@ constexpr hilti::util::enum_::Value values[] = { {Foo::CCC, "ccc"}, }; -constexpr static auto from_string(const std::string_view& s) { return hilti::util::enum_::from_string(s, values); } +constexpr static auto from_string(std::string_view s) { return hilti::util::enum_::from_string(s, values); } TEST_SUITE_BEGIN("util"); From 8db158a57398f297de4460585bd35ead49b360d9 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:06:41 +0100 Subject: [PATCH 09/19] Parenthesize expression when arithmetic mixes difference precedences. `clang-tidy` suggests adding extra parentheses when mixing e.g., addition and multiplication. Apply these suggestions (automatically). --- hilti/runtime/src/profiler.cc | 2 +- hilti/runtime/src/types/time.cc | 2 +- hilti/runtime/src/util.cc | 2 +- hilti/toolchain/src/base/util.cc | 4 ++-- hilti/toolchain/src/compiler/cxx/elements.cc | 2 +- spicy/toolchain/src/compiler/validator.cc | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hilti/runtime/src/profiler.cc b/hilti/runtime/src/profiler.cc index 06c9de196..6ef9fe4bc 100644 --- a/hilti/runtime/src/profiler.cc +++ b/hilti/runtime/src/profiler.cc @@ -24,7 +24,7 @@ inline static uint64_t _getClock() { #else clock_gettime(CLOCK_MONOTONIC, &t); // POSIX #endif - return static_cast(1000000000) * t.tv_sec + t.tv_nsec; + return (static_cast(1000000000) * t.tv_sec) + t.tv_nsec; #endif } diff --git a/hilti/runtime/src/types/time.cc b/hilti/runtime/src/types/time.cc index fe17f4cb0..822341c16 100644 --- a/hilti/runtime/src/types/time.cc +++ b/hilti/runtime/src/types/time.cc @@ -14,7 +14,7 @@ Time time::current_time() { if ( gettimeofday(&tv, nullptr) < 0 ) throw RuntimeError("gettimeofday failed in current_time()"); - double t = static_cast(tv.tv_sec) + static_cast(tv.tv_usec) / 1e6; + double t = static_cast(tv.tv_sec) + (static_cast(tv.tv_usec) / 1e6); return Time(t, Time::SecondTag()); } diff --git a/hilti/runtime/src/util.cc b/hilti/runtime/src/util.cc index 946cffd8f..6355b4ccb 100644 --- a/hilti/runtime/src/util.cc +++ b/hilti/runtime/src/util.cc @@ -50,7 +50,7 @@ hilti::rt::ResourceUsage hilti::rt::resource_usage() { auto fibers = detail::Fiber::statistics(); const auto to_seconds = [](const timeval& t) { - return static_cast(t.tv_sec) + static_cast(t.tv_usec) / 1e6; + return static_cast(t.tv_sec) + (static_cast(t.tv_usec) / 1e6); }; stats.user_time = to_seconds(r.ru_utime) - detail::globalState()->resource_usage_init.user_time; diff --git a/hilti/toolchain/src/base/util.cc b/hilti/toolchain/src/base/util.cc index c42c68bd1..f1e8fdabe 100644 --- a/hilti/toolchain/src/base/util.cc +++ b/hilti/toolchain/src/base/util.cc @@ -200,7 +200,7 @@ void util::abortWithBacktrace() { double util::currentTime() { struct timeval tv{}; gettimeofday(&tv, nullptr); - return static_cast(tv.tv_sec) + static_cast(tv.tv_usec) / 1e6; + return static_cast(tv.tv_sec) + (static_cast(tv.tv_usec) / 1e6); } std::string util::toIdentifier(std::string s) { @@ -211,7 +211,7 @@ std::string util::toIdentifier(std::string s) { // Fast-path: no special-characters, no leading digits. return s; - auto buffer_size = s.size() * 3 + 1; + auto buffer_size = (s.size() * 3) + 1; char* buffer = reinterpret_cast(alloca(buffer_size)); // max possible size of modified string char* p = buffer; diff --git a/hilti/toolchain/src/compiler/cxx/elements.cc b/hilti/toolchain/src/compiler/cxx/elements.cc index 5d517ec1b..698e4a09c 100644 --- a/hilti/toolchain/src/compiler/cxx/elements.cc +++ b/hilti/toolchain/src/compiler/cxx/elements.cc @@ -146,7 +146,7 @@ std::optional cxx::normalizeID(std::string_view id) { // Fast-path: no special-characters, no leading digits. return std::nullopt; - auto buffer_size = id.size() * 6 + 1; + auto buffer_size = (id.size() * 6) + 1; char* buffer = reinterpret_cast(alloca(buffer_size)); // max possible size of modified string char* p = buffer; diff --git a/spicy/toolchain/src/compiler/validator.cc b/spicy/toolchain/src/compiler/validator.cc index d91070caa..0370fe39c 100644 --- a/spicy/toolchain/src/compiler/validator.cc +++ b/spicy/toolchain/src/compiler/validator.cc @@ -373,7 +373,7 @@ struct VisitorPost : visitor::PreOrder, hilti::validator::VisitorMixIn { patch = parse_number(v[2]); // This must match the computation in the toplevel `CMakeLists.txt` file. - auto version = major * 10000 + minor * 100 + patch; + auto version = (major * 10000) + (minor * 100) + patch; if ( hilti::configuration().version_number < version ) error(fmt("module %s requires at least Spicy version %s (have %s)", n->id(), s->value(), hilti::configuration().version_string), From 654d86fdc8f82bb7bc4f685d98f104db7035e035 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:18:01 +0100 Subject: [PATCH 10/19] Remove some unneeded includes. --- 3rdparty/any | 2 +- hilti/runtime/src/tests/library.cc | 1 - hilti/runtime/src/tests/logging.cc | 2 -- hilti/toolchain/bin/hilti-config.cc | 1 - hilti/toolchain/include/ast/builder/builder.h | 1 - hilti/toolchain/include/ast/ctors/default.h | 1 - hilti/toolchain/include/ast/ctors/list.h | 1 - hilti/toolchain/include/ast/ctors/map.h | 2 -- hilti/toolchain/include/ast/ctors/set.h | 1 - hilti/toolchain/include/ast/ctors/struct.h | 3 --- hilti/toolchain/include/ast/ctors/vector.h | 1 - hilti/toolchain/include/ast/declarations/module.h | 1 - hilti/toolchain/include/ast/declarations/parameter.h | 3 +-- hilti/toolchain/include/ast/expressions/keyword.h | 1 - hilti/toolchain/include/ast/forward.h | 1 - hilti/toolchain/include/ast/function.h | 1 + hilti/toolchain/include/ast/statements/block.h | 1 - hilti/toolchain/include/ast/statements/switch.h | 2 -- hilti/toolchain/include/ast/types/bitfield.h | 2 -- hilti/toolchain/include/ast/types/function.h | 2 +- hilti/toolchain/include/ast/types/struct.h | 1 - hilti/toolchain/include/ast/types/tuple.h | 2 -- hilti/toolchain/include/ast/types/union.h | 1 - spicy/toolchain/bin/spicy-config.cc | 1 - spicy/toolchain/include/ast/builder/builder.h | 1 - spicy/toolchain/include/ast/ctors/unit.h | 1 - spicy/toolchain/include/ast/statements/print.h | 1 - spicy/toolchain/include/ast/types/unit-items/block.h | 1 - spicy/toolchain/include/ast/types/unit.h | 1 - 29 files changed, 4 insertions(+), 36 deletions(-) diff --git a/3rdparty/any b/3rdparty/any index a05d5ad91..7c76129ad 160000 --- a/3rdparty/any +++ b/3rdparty/any @@ -1 +1 @@ -Subproject commit a05d5ad91cfbca0153adb7d7b3e6456fffc7b812 +Subproject commit 7c76129ad519b2214800dec9038bb3baad09882f diff --git a/hilti/runtime/src/tests/library.cc b/hilti/runtime/src/tests/library.cc index f2f5d8f71..4806e1ff8 100644 --- a/hilti/runtime/src/tests/library.cc +++ b/hilti/runtime/src/tests/library.cc @@ -4,7 +4,6 @@ #include #include -#include #include #include #include diff --git a/hilti/runtime/src/tests/logging.cc b/hilti/runtime/src/tests/logging.cc index 05f009f68..ad270ff5f 100644 --- a/hilti/runtime/src/tests/logging.cc +++ b/hilti/runtime/src/tests/logging.cc @@ -1,8 +1,6 @@ // Copyright (c) 2020-2023 by the Zeek Project. See LICENSE for details. -#include #include -#include #include #include diff --git a/hilti/toolchain/bin/hilti-config.cc b/hilti/toolchain/bin/hilti-config.cc index 83d941474..c8f631dd0 100644 --- a/hilti/toolchain/bin/hilti-config.cc +++ b/hilti/toolchain/bin/hilti-config.cc @@ -4,7 +4,6 @@ #include #include -#include #include #include diff --git a/hilti/toolchain/include/ast/builder/builder.h b/hilti/toolchain/include/ast/builder/builder.h index 1c61b7bea..990083bba 100644 --- a/hilti/toolchain/include/ast/builder/builder.h +++ b/hilti/toolchain/include/ast/builder/builder.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include #include diff --git a/hilti/toolchain/include/ast/ctors/default.h b/hilti/toolchain/include/ast/ctors/default.h index b0a1d9517..530d29074 100644 --- a/hilti/toolchain/include/ast/ctors/default.h +++ b/hilti/toolchain/include/ast/ctors/default.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include diff --git a/hilti/toolchain/include/ast/ctors/list.h b/hilti/toolchain/include/ast/ctors/list.h index 790f28fe2..c5eb7b9e5 100644 --- a/hilti/toolchain/include/ast/ctors/list.h +++ b/hilti/toolchain/include/ast/ctors/list.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include diff --git a/hilti/toolchain/include/ast/ctors/map.h b/hilti/toolchain/include/ast/ctors/map.h index f9a9eef67..371d362d9 100644 --- a/hilti/toolchain/include/ast/ctors/map.h +++ b/hilti/toolchain/include/ast/ctors/map.h @@ -2,10 +2,8 @@ #pragma once -#include #include #include -#include #include #include diff --git a/hilti/toolchain/include/ast/ctors/set.h b/hilti/toolchain/include/ast/ctors/set.h index 1d2e5915f..4ffc4c6de 100644 --- a/hilti/toolchain/include/ast/ctors/set.h +++ b/hilti/toolchain/include/ast/ctors/set.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include diff --git a/hilti/toolchain/include/ast/ctors/struct.h b/hilti/toolchain/include/ast/ctors/struct.h index 33b39eccc..f0d5aaeb7 100644 --- a/hilti/toolchain/include/ast/ctors/struct.h +++ b/hilti/toolchain/include/ast/ctors/struct.h @@ -2,10 +2,7 @@ #pragma once -#include -#include #include -#include #include #include diff --git a/hilti/toolchain/include/ast/ctors/vector.h b/hilti/toolchain/include/ast/ctors/vector.h index 18c8c3991..7e51a04c6 100644 --- a/hilti/toolchain/include/ast/ctors/vector.h +++ b/hilti/toolchain/include/ast/ctors/vector.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include diff --git a/hilti/toolchain/include/ast/declarations/module.h b/hilti/toolchain/include/ast/declarations/module.h index f89ea3374..7ec9052bd 100644 --- a/hilti/toolchain/include/ast/declarations/module.h +++ b/hilti/toolchain/include/ast/declarations/module.h @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/hilti/toolchain/include/ast/declarations/parameter.h b/hilti/toolchain/include/ast/declarations/parameter.h index b1830e216..e4c31c195 100644 --- a/hilti/toolchain/include/ast/declarations/parameter.h +++ b/hilti/toolchain/include/ast/declarations/parameter.h @@ -2,10 +2,9 @@ #pragma once -#include #include +#include #include -#include #include #include diff --git a/hilti/toolchain/include/ast/expressions/keyword.h b/hilti/toolchain/include/ast/expressions/keyword.h index f2a367978..cf132d54e 100644 --- a/hilti/toolchain/include/ast/expressions/keyword.h +++ b/hilti/toolchain/include/ast/expressions/keyword.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include diff --git a/hilti/toolchain/include/ast/forward.h b/hilti/toolchain/include/ast/forward.h index e58c0667b..6ca75257b 100644 --- a/hilti/toolchain/include/ast/forward.h +++ b/hilti/toolchain/include/ast/forward.h @@ -3,7 +3,6 @@ #pragma once #include -#include #include namespace hilti { diff --git a/hilti/toolchain/include/ast/function.h b/hilti/toolchain/include/ast/function.h index 4cc84025a..84927dec2 100644 --- a/hilti/toolchain/include/ast/function.h +++ b/hilti/toolchain/include/ast/function.h @@ -3,6 +3,7 @@ #pragma once #include +#include #include #include diff --git a/hilti/toolchain/include/ast/statements/block.h b/hilti/toolchain/include/ast/statements/block.h index 9b39d9c2d..7f48cbc61 100644 --- a/hilti/toolchain/include/ast/statements/block.h +++ b/hilti/toolchain/include/ast/statements/block.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include diff --git a/hilti/toolchain/include/ast/statements/switch.h b/hilti/toolchain/include/ast/statements/switch.h index 2ae4e75b4..f2c8b3152 100644 --- a/hilti/toolchain/include/ast/statements/switch.h +++ b/hilti/toolchain/include/ast/statements/switch.h @@ -2,10 +2,8 @@ #pragma once -#include #include #include -#include #include #include diff --git a/hilti/toolchain/include/ast/types/bitfield.h b/hilti/toolchain/include/ast/types/bitfield.h index b8b8b06e8..f421c7bf3 100644 --- a/hilti/toolchain/include/ast/types/bitfield.h +++ b/hilti/toolchain/include/ast/types/bitfield.h @@ -2,10 +2,8 @@ #pragma once -#include #include #include -#include #include #include diff --git a/hilti/toolchain/include/ast/types/function.h b/hilti/toolchain/include/ast/types/function.h index f05986bad..ddcf92c26 100644 --- a/hilti/toolchain/include/ast/types/function.h +++ b/hilti/toolchain/include/ast/types/function.h @@ -2,7 +2,7 @@ #pragma once -#include +#include #include #include diff --git a/hilti/toolchain/include/ast/types/struct.h b/hilti/toolchain/include/ast/types/struct.h index a7b6b126e..884f77903 100644 --- a/hilti/toolchain/include/ast/types/struct.h +++ b/hilti/toolchain/include/ast/types/struct.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include diff --git a/hilti/toolchain/include/ast/types/tuple.h b/hilti/toolchain/include/ast/types/tuple.h index bcf60d25f..04cb53420 100644 --- a/hilti/toolchain/include/ast/types/tuple.h +++ b/hilti/toolchain/include/ast/types/tuple.h @@ -3,10 +3,8 @@ #pragma once #include -#include #include #include -#include #include #include diff --git a/hilti/toolchain/include/ast/types/union.h b/hilti/toolchain/include/ast/types/union.h index d685ecfb2..4c09e5f48 100644 --- a/hilti/toolchain/include/ast/types/union.h +++ b/hilti/toolchain/include/ast/types/union.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include diff --git a/spicy/toolchain/bin/spicy-config.cc b/spicy/toolchain/bin/spicy-config.cc index 244326ed5..8635e5512 100644 --- a/spicy/toolchain/bin/spicy-config.cc +++ b/spicy/toolchain/bin/spicy-config.cc @@ -4,7 +4,6 @@ #include #include -#include #include #include diff --git a/spicy/toolchain/include/ast/builder/builder.h b/spicy/toolchain/include/ast/builder/builder.h index b4ccb5e81..2d86aa0f1 100644 --- a/spicy/toolchain/include/ast/builder/builder.h +++ b/spicy/toolchain/include/ast/builder/builder.h @@ -4,7 +4,6 @@ #include #include -#include #include diff --git a/spicy/toolchain/include/ast/ctors/unit.h b/spicy/toolchain/include/ast/ctors/unit.h index 2cdd66989..c6c4812ff 100644 --- a/spicy/toolchain/include/ast/ctors/unit.h +++ b/spicy/toolchain/include/ast/ctors/unit.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include diff --git a/spicy/toolchain/include/ast/statements/print.h b/spicy/toolchain/include/ast/statements/print.h index 57d78fd59..c26e315d0 100644 --- a/spicy/toolchain/include/ast/statements/print.h +++ b/spicy/toolchain/include/ast/statements/print.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include diff --git a/spicy/toolchain/include/ast/types/unit-items/block.h b/spicy/toolchain/include/ast/types/unit-items/block.h index ceb8dc9ad..a9a2ac6d2 100644 --- a/spicy/toolchain/include/ast/types/unit-items/block.h +++ b/spicy/toolchain/include/ast/types/unit-items/block.h @@ -3,7 +3,6 @@ #pragma once #include -#include #include #include diff --git a/spicy/toolchain/include/ast/types/unit.h b/spicy/toolchain/include/ast/types/unit.h index 370012b54..dd6f03d76 100644 --- a/spicy/toolchain/include/ast/types/unit.h +++ b/spicy/toolchain/include/ast/types/unit.h @@ -2,7 +2,6 @@ #pragma once -#include #include #include From c1741b817f3df8f765328d8dca69a369b19cd369 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:27:07 +0100 Subject: [PATCH 11/19] Reformat code not recognized as C++ by pre-commit hook. --- hilti/toolchain/src/config.cc.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hilti/toolchain/src/config.cc.in b/hilti/toolchain/src/config.cc.in index b1d4fdbb0..996426f12 100644 --- a/hilti/toolchain/src/config.cc.in +++ b/hilti/toolchain/src/config.cc.in @@ -140,9 +140,10 @@ void Configuration::init(bool use_build_directory) { // // (3) it helps the optimizer to know that symbols won't be accessed // externally. - runtime_cxx_flags_debug = flatten({"-fPIC", "-std=c++17", "-g", "-O0", "-fvisibility=hidden", "-Wno-invalid-offsetof", - prefix("${HILTI_CONFIG_RUNTIME_CXX_INCLUDE_DIRS}", "-I", installation_tag), - prefix("${HILTI_CONFIG_RUNTIME_CXX_FLAGS_DEBUG}", "", installation_tag)}); + runtime_cxx_flags_debug = + flatten({"-fPIC", "-std=c++17", "-g", "-O0", "-fvisibility=hidden", "-Wno-invalid-offsetof", + prefix("${HILTI_CONFIG_RUNTIME_CXX_INCLUDE_DIRS}", "-I", installation_tag), + prefix("${HILTI_CONFIG_RUNTIME_CXX_FLAGS_DEBUG}", "", installation_tag)}); runtime_cxx_flags_release = flatten({"-fPIC", "-std=c++17", "-g", "-O3", "-DNDEBUG", "-fvisibility=hidden", "-Wno-invalid-offsetof", From 6adea361ca5493d1a0db63b737b0b7e57afe51eb Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Mon, 9 Dec 2024 23:25:42 +0100 Subject: [PATCH 12/19] Disable clang-tidy on generated lexer/parser files. --- hilti/toolchain/CMakeLists.txt | 3 +++ spicy/toolchain/CMakeLists.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/hilti/toolchain/CMakeLists.txt b/hilti/toolchain/CMakeLists.txt index 08cf10ca8..2270d0afd 100644 --- a/hilti/toolchain/CMakeLists.txt +++ b/hilti/toolchain/CMakeLists.txt @@ -12,6 +12,9 @@ flex_target(scanner_hilti src/compiler/parser/scanner.ll ${AUTOGEN_CC}/__scanner bison_target_pp(parser_hilti src/compiler/parser/parser.yy ${AUTOGEN_CC}/__parser.cc DEFINES_FILE ${AUTOGEN_CC}/__parser.h) +set_source_files_properties(${FLEX_scanner_hilti_OUTPUTS} PROPERTIES SKIP_LINTING ON) +set_source_files_properties(${BISON_parser_hilti_OUTPUTS} PROPERTIES SKIP_LINTING ON) + bison_source(src/compiler/plugin.cc ${AUTOGEN_CC}) bison_source(src/compiler/parser/driver.cc ${AUTOGEN_CC}) bison_source(${AUTOGEN_CC}/__scanner.cc ${AUTOGEN_CC}) diff --git a/spicy/toolchain/CMakeLists.txt b/spicy/toolchain/CMakeLists.txt index f3607dafd..a88696a1e 100644 --- a/spicy/toolchain/CMakeLists.txt +++ b/spicy/toolchain/CMakeLists.txt @@ -14,6 +14,9 @@ flex_target(scanner_spicy src/compiler/parser/scanner.ll ${AUTOGEN_CC}/__scanner bison_target_pp(parser_spicy src/compiler/parser/parser.yy ${AUTOGEN_CC}/__parser.cc DEFINES_FILE ${AUTOGEN_CC}/__parser.h) +set_source_files_properties(${FLEX_scanner_spicy_OUTPUTS} PROPERTIES SKIP_LINTING ON) +set_source_files_properties(${BISON_parser_spicy_OUTPUTS} PROPERTIES SKIP_LINTING ON) + bison_source(src/compiler/plugin.cc ${AUTOGEN_CC}) bison_source(src/compiler/parser/driver.cc ${AUTOGEN_CC}) bison_source(${AUTOGEN_CC}/__scanner.cc ${AUTOGEN_CC}) From dd3949642879b20d4bb402c966f93f3c8c5bb7e2 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:35:47 +0100 Subject: [PATCH 13/19] Fix up container helpers to ensure moving. It is not immediately clear to me when the previous implementation could move their values over. `clang-tidy` ended up flagging many of these as not moving and forcing copies. This patch rewrites the loops in these helpers to enforce iteration with move. --- 3rdparty/any | 2 +- hilti/toolchain/include/ast/forward.h | 5 +++-- hilti/toolchain/include/ast/node.h | 7 ++++--- hilti/toolchain/include/base/util.h | 11 ++++++----- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/3rdparty/any b/3rdparty/any index 7c76129ad..a05d5ad91 160000 --- a/3rdparty/any +++ b/3rdparty/any @@ -1 +1 @@ -Subproject commit 7c76129ad519b2214800dec9038bb3baad09882f +Subproject commit a05d5ad91cfbca0153adb7d7b3e6456fffc7b812 diff --git a/hilti/toolchain/include/ast/forward.h b/hilti/toolchain/include/ast/forward.h index 6ca75257b..39668814a 100644 --- a/hilti/toolchain/include/ast/forward.h +++ b/hilti/toolchain/include/ast/forward.h @@ -2,6 +2,7 @@ #pragma once +#include #include #include @@ -761,8 +762,8 @@ class Nodes : public NodeVector { template Nodes(NodeVector m) { reserve(m.size()); - for ( auto* x : m ) - emplace_back(x); + for ( auto it = std::make_move_iterator(m.begin()); it != std::make_move_iterator(m.end()); ++it ) + emplace_back(*it); } Nodes() = default; diff --git a/hilti/toolchain/include/ast/node.h b/hilti/toolchain/include/ast/node.h index 7f9f56906..ed773f788 100644 --- a/hilti/toolchain/include/ast/node.h +++ b/hilti/toolchain/include/ast/node.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -1117,8 +1118,8 @@ template Nodes flatten(std::vector t) { Nodes v; v.reserve(t.size()); - for ( const auto& i : t ) - v.emplace_back(std::move(i)); + for ( auto it = std::make_move_iterator(t.begin()); it != std::make_move_iterator(t.end()); ++it ) + v.emplace_back(*it); return v; } @@ -1164,7 +1165,7 @@ inline Nodes flatten() { return Nodes(); } */ template* = nullptr> Nodes flatten(T t, Ts... ts) { - return util::concat(std::move(flatten(t)), flatten(std::move(ts)...)); + return util::concat(std::move(flatten(std::move(t))), flatten(std::move(ts)...)); } /** diff --git a/hilti/toolchain/include/base/util.h b/hilti/toolchain/include/base/util.h index 5aa4bc4d5..ff65f88be 100644 --- a/hilti/toolchain/include/base/util.h +++ b/hilti/toolchain/include/base/util.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -515,18 +516,18 @@ std::vector& append(std::vector& v1, const std::vector& v2) { return v1; } -/** Remov duplicates from a vector without changing order. */ +/** Remove duplicates from a vector without changing order. */ template std::vector removeDuplicates(std::vector v) { std::set seen; std::vector out; - for ( auto&& i : v ) { - if ( seen.find(i) != seen.end() ) + for ( auto it = std::make_move_iterator(v.begin()); it != std::make_move_iterator(v.end()); ++it ) { + if ( seen.find(*it) != seen.end() ) continue; - seen.insert(i); - out.emplace_back(std::move(i)); + seen.insert(*it); + out.emplace_back(*it); } return out; From c91c2908267d991b4cba3953293e44bbc494e4d9 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 17 Dec 2024 15:33:45 +0100 Subject: [PATCH 14/19] Fix up APIs in AST API which were not actually moving. Many functions in the AST API were moving arguments only for them to ultimately be copied; `clang-tidy` diagnosed most of these. This patch cleans up the flagged useless passes by value and `std::move` without effect. --- hilti/toolchain/include/ast/attribute.h | 4 ++-- hilti/toolchain/include/ast/builder/builder.h | 8 ++++---- hilti/toolchain/include/ast/ctors/default.h | 9 ++++----- hilti/toolchain/include/ast/ctors/list.h | 12 ++++++------ hilti/toolchain/include/ast/ctors/map.h | 12 ++++++------ hilti/toolchain/include/ast/ctors/set.h | 12 ++++++------ hilti/toolchain/include/ast/ctors/struct.h | 8 ++++---- hilti/toolchain/include/ast/ctors/vector.h | 12 ++++++------ hilti/toolchain/include/ast/declarations/module.h | 4 ++-- hilti/toolchain/include/ast/statements/block.h | 4 ++-- hilti/toolchain/include/ast/statements/switch.h | 2 +- hilti/toolchain/include/ast/types/bitfield.h | 4 ++-- hilti/toolchain/include/ast/types/struct.h | 9 +++++---- hilti/toolchain/include/ast/types/tuple.h | 4 ++-- hilti/toolchain/include/ast/types/union.h | 9 +++++---- hilti/toolchain/include/ast/visitor.h | 2 +- hilti/toolchain/src/compiler/resolver.cc | 4 ++-- spicy/toolchain/include/ast/ctors/unit.h | 8 ++++---- spicy/toolchain/include/ast/statements/print.h | 4 ++-- spicy/toolchain/include/ast/types/unit-items/block.h | 4 ++-- spicy/toolchain/include/ast/types/unit.h | 9 ++++----- 21 files changed, 72 insertions(+), 72 deletions(-) diff --git a/hilti/toolchain/include/ast/attribute.h b/hilti/toolchain/include/ast/attribute.h index c8f328f6c..19daff51c 100644 --- a/hilti/toolchain/include/ast/attribute.h +++ b/hilti/toolchain/include/ast/attribute.h @@ -248,8 +248,8 @@ class AttributeSet : public Node { /** Returns true if the set has at least one element. */ operator bool() const { return ! attributes().empty(); } - static auto create(ASTContext* ctx, Attributes attrs = {}, Meta m = Meta()) { - return ctx->make(ctx, std::move(attrs), std::move(m)); + static auto create(ASTContext* ctx, const Attributes& attrs = {}, Meta m = Meta()) { + return ctx->make(ctx, attrs, std::move(m)); } protected: diff --git a/hilti/toolchain/include/ast/builder/builder.h b/hilti/toolchain/include/ast/builder/builder.h index 990083bba..3487452f1 100644 --- a/hilti/toolchain/include/ast/builder/builder.h +++ b/hilti/toolchain/include/ast/builder/builder.h @@ -662,13 +662,13 @@ class ExtendedBuilderTemplate : public Builder { return std::make_pair(_newBuilder(true_), _newBuilder(false_)); } - auto newBlock(Meta m = Meta()) { - auto body = Builder::statementBlock(std::move(m)); + auto newBlock(const Meta& m = Meta()) { + auto body = Builder::statementBlock(m); return _newBuilder(body); } - auto addBlock(Meta m = Meta()) { - auto body = Builder::statementBlock(std::move(m)); + auto addBlock(const Meta& m = Meta()) { + auto body = Builder::statementBlock(m); Builder::block()->_add(Builder::context(), body); return _newBuilder(body); } diff --git a/hilti/toolchain/include/ast/ctors/default.h b/hilti/toolchain/include/ast/ctors/default.h index 530d29074..dc1573011 100644 --- a/hilti/toolchain/include/ast/ctors/default.h +++ b/hilti/toolchain/include/ast/ctors/default.h @@ -17,9 +17,9 @@ class Default : public Ctor { QualifiedType* type() const final { return child(0); } - void setTypeArguments(ASTContext* ctx, Expressions exprs) { + void setTypeArguments(ASTContext* ctx, const Expressions& exprs) { removeChildren(1, {}); - addChildren(ctx, std::move(exprs)); + addChildren(ctx, exprs); } /** Constructs a default value of a given type. */ @@ -31,10 +31,9 @@ class Default : public Ctor { * Constructs a default value of a given type, passing specified arguments to * types with parameters. */ - static auto create(ASTContext* ctx, UnqualifiedType* type, Expressions type_args, const Meta& meta = {}) { + static auto create(ASTContext* ctx, UnqualifiedType* type, const Expressions& type_args, const Meta& meta = {}) { return ctx->make(ctx, - node::flatten(QualifiedType::create(ctx, type, Constness::Const, meta), - std::move(type_args)), + node::flatten(QualifiedType::create(ctx, type, Constness::Const, meta), type_args), meta); } diff --git a/hilti/toolchain/include/ast/ctors/list.h b/hilti/toolchain/include/ast/ctors/list.h index c5eb7b9e5..143e9601a 100644 --- a/hilti/toolchain/include/ast/ctors/list.h +++ b/hilti/toolchain/include/ast/ctors/list.h @@ -19,24 +19,24 @@ class List : public Ctor { QualifiedType* type() const final { return child(0); } - void setValue(ASTContext* ctx, Expressions exprs) { + void setValue(ASTContext* ctx, const Expressions& exprs) { removeChildren(0, {}); addChild(ctx, QualifiedType::createAuto(ctx, meta())); - addChildren(ctx, std::move(exprs)); + addChildren(ctx, exprs); } void setType(ASTContext* ctx, QualifiedType* t) { setChild(ctx, 0, t); } - static auto create(ASTContext* ctx, QualifiedType* etype, Expressions exprs, Meta meta = {}) { + static auto create(ASTContext* ctx, QualifiedType* etype, const Expressions& exprs, Meta meta = {}) { auto stype = QualifiedType::create(ctx, type::List::create(ctx, etype, meta), Constness::Const, meta); - return ctx->make(ctx, node::flatten(stype, std::move(exprs)), std::move(meta)); + return ctx->make(ctx, node::flatten(stype, exprs), std::move(meta)); } - static auto create(ASTContext* ctx, Expressions exprs, Meta meta = {}) { + static auto create(ASTContext* ctx, const Expressions& exprs, Meta meta = {}) { // Bool is just an arbitrary place-holder type for empty values. auto etype = exprs.empty() ? QualifiedType::create(ctx, type::Bool::create(ctx, meta), Constness::Const, meta) : QualifiedType::createAuto(ctx, meta); - return create(ctx, etype, std::move(exprs), std::move(meta)); + return create(ctx, etype, exprs, std::move(meta)); } protected: diff --git a/hilti/toolchain/include/ast/ctors/map.h b/hilti/toolchain/include/ast/ctors/map.h index 371d362d9..6d9fdf505 100644 --- a/hilti/toolchain/include/ast/ctors/map.h +++ b/hilti/toolchain/include/ast/ctors/map.h @@ -63,23 +63,23 @@ class Map : public Ctor { void setType(ASTContext* ctx, QualifiedType* type) { setChild(ctx, 0, type); } - void setValue(ASTContext* ctx, map::Elements exprs) { + void setValue(ASTContext* ctx, const map::Elements& exprs) { removeChildren(1, {}); - addChildren(ctx, std::move(exprs)); + addChildren(ctx, exprs); } - static auto create(ASTContext* ctx, QualifiedType* key, QualifiedType* value, map::Elements elements, + static auto create(ASTContext* ctx, QualifiedType* key, QualifiedType* value, const map::Elements& elements, Meta meta = {}) { auto mtype = QualifiedType::create(ctx, type::Map::create(ctx, key, value, meta), Constness::Mutable, meta); - return ctx->make(ctx, node::flatten(mtype, std::move(elements)), std::move(meta)); + return ctx->make(ctx, node::flatten(mtype, elements), std::move(meta)); } - static auto create(ASTContext* ctx, map::Elements elements, Meta meta = {}) { + static auto create(ASTContext* ctx, const map::Elements& elements, Meta meta = {}) { // bool is just an arbitrary place-holder type for empty values. auto mtype = elements.empty() ? QualifiedType::create(ctx, type::Bool::create(ctx, meta), Constness::Mutable, meta) : QualifiedType::createAuto(ctx, meta); - return ctx->make(ctx, node::flatten(mtype, std::move(elements)), std::move(meta)); + return ctx->make(ctx, node::flatten(mtype, elements), std::move(meta)); } protected: diff --git a/hilti/toolchain/include/ast/ctors/set.h b/hilti/toolchain/include/ast/ctors/set.h index 4ffc4c6de..7a7817ca1 100644 --- a/hilti/toolchain/include/ast/ctors/set.h +++ b/hilti/toolchain/include/ast/ctors/set.h @@ -21,22 +21,22 @@ class Set : public Ctor { void setType(ASTContext* ctx, QualifiedType* t) { setChild(ctx, 0, t); } - void setValue(ASTContext* ctx, Expressions exprs) { + void setValue(ASTContext* ctx, const Expressions& exprs) { removeChildren(1, {}); - addChildren(ctx, std::move(exprs)); + addChildren(ctx, exprs); } - static auto create(ASTContext* ctx, QualifiedType* etype, Expressions exprs, Meta meta = {}) { + static auto create(ASTContext* ctx, QualifiedType* etype, const Expressions& exprs, Meta meta = {}) { auto stype = QualifiedType::create(ctx, type::Set::create(ctx, etype, meta), Constness::Mutable, meta); - return ctx->make(ctx, node::flatten(stype, std::move(exprs)), std::move(meta)); + return ctx->make(ctx, node::flatten(stype, exprs), std::move(meta)); } - static auto create(ASTContext* ctx, Expressions exprs, Meta meta = {}) { + static auto create(ASTContext* ctx, const Expressions& exprs, Meta meta = {}) { // bool is just an arbitrary place-holder type for empty values. auto etype = exprs.empty() ? QualifiedType::create(ctx, type::Bool::create(ctx, meta), Constness::Mutable, meta) : QualifiedType::createAuto(ctx, meta); - return create(ctx, etype, std::move(exprs), std::move(meta)); + return create(ctx, etype, exprs, std::move(meta)); } protected: diff --git a/hilti/toolchain/include/ast/ctors/struct.h b/hilti/toolchain/include/ast/ctors/struct.h index f0d5aaeb7..f008f5537 100644 --- a/hilti/toolchain/include/ast/ctors/struct.h +++ b/hilti/toolchain/include/ast/ctors/struct.h @@ -69,12 +69,12 @@ class Struct : public Ctor, public node::WithUniqueID { return Ctor::properties() + node::WithUniqueID::properties() + p; } - static auto create(ASTContext* ctx, struct_::Fields fields, QualifiedType* t, Meta meta = {}) { - return ctx->make(ctx, node::flatten(t, std::move(fields)), std::move(meta)); + static auto create(ASTContext* ctx, const struct_::Fields& fields, QualifiedType* t, Meta meta = {}) { + return ctx->make(ctx, node::flatten(t, fields), std::move(meta)); } - static auto create(ASTContext* ctx, struct_::Fields fields, const Meta& meta = {}) { - return ctx->make(ctx, node::flatten(QualifiedType::createAuto(ctx, meta), std::move(fields)), meta); + static auto create(ASTContext* ctx, const struct_::Fields& fields, const Meta& meta = {}) { + return ctx->make(ctx, node::flatten(QualifiedType::createAuto(ctx, meta), fields), meta); } protected: diff --git a/hilti/toolchain/include/ast/ctors/vector.h b/hilti/toolchain/include/ast/ctors/vector.h index 7e51a04c6..e11553bc3 100644 --- a/hilti/toolchain/include/ast/ctors/vector.h +++ b/hilti/toolchain/include/ast/ctors/vector.h @@ -21,22 +21,22 @@ class Vector : public Ctor { void setType(ASTContext* ctx, QualifiedType* t) { setChild(ctx, 0, t); } - void setValue(ASTContext* ctx, Expressions exprs) { + void setValue(ASTContext* ctx, const Expressions& exprs) { removeChildren(1, {}); - addChildren(ctx, std::move(exprs)); + addChildren(ctx, exprs); } - static auto create(ASTContext* ctx, QualifiedType* etype, Expressions exprs, Meta meta = {}) { + static auto create(ASTContext* ctx, QualifiedType* etype, const Expressions& exprs, Meta meta = {}) { auto stype = QualifiedType::create(ctx, type::Vector::create(ctx, etype, meta), Constness::Mutable, meta); - return ctx->make(ctx, node::flatten(stype, std::move(exprs)), std::move(meta)); + return ctx->make(ctx, node::flatten(stype, exprs), std::move(meta)); } - static auto create(ASTContext* ctx, Expressions exprs, Meta meta = {}) { + static auto create(ASTContext* ctx, const Expressions& exprs, Meta meta = {}) { // bool is just an arbitrary place-holder type for empty values. auto etype = exprs.empty() ? QualifiedType::create(ctx, type::Bool::create(ctx, meta), Constness::Mutable, meta) : QualifiedType::createAuto(ctx, meta); - return create(ctx, etype, std::move(exprs), std::move(meta)); + return create(ctx, etype, exprs, std::move(meta)); } protected: diff --git a/hilti/toolchain/include/ast/declarations/module.h b/hilti/toolchain/include/ast/declarations/module.h index 7ec9052bd..eee82e11e 100644 --- a/hilti/toolchain/include/ast/declarations/module.h +++ b/hilti/toolchain/include/ast/declarations/module.h @@ -106,8 +106,8 @@ class Module : public Declaration { std::string_view branchTag() const final { return _uid.process_extension.native(); } static auto create(ASTContext* ctx, const declaration::module::UID& uid, const ID& scope, const Declarations& decls, - Statements stmts, Meta meta = {}) { - Nodes nodes = {statement::Block::create(ctx, std::move(stmts), meta)}; + const Statements& stmts, Meta meta = {}) { + Nodes nodes = {statement::Block::create(ctx, stmts, meta)}; for ( auto d : decls ) nodes.push_back(d); diff --git a/hilti/toolchain/include/ast/statements/block.h b/hilti/toolchain/include/ast/statements/block.h index 7f48cbc61..343f40255 100644 --- a/hilti/toolchain/include/ast/statements/block.h +++ b/hilti/toolchain/include/ast/statements/block.h @@ -21,8 +21,8 @@ class Block : public Statement { /** Internal method for use by builder API only. */ auto _lastStatement() { return children().back()->as(); } - static auto create(ASTContext* ctx, Statements stmts, Meta meta = {}) { - return ctx->make(ctx, std::move(stmts), std::move(meta)); + static auto create(ASTContext* ctx, const Statements& stmts, Meta meta = {}) { + return ctx->make(ctx, stmts, std::move(meta)); } static auto create(ASTContext* ctx, const Meta& meta = {}) { return create(ctx, {}, meta); } diff --git a/hilti/toolchain/include/ast/statements/switch.h b/hilti/toolchain/include/ast/statements/switch.h index f2c8b3152..d6a873a49 100644 --- a/hilti/toolchain/include/ast/statements/switch.h +++ b/hilti/toolchain/include/ast/statements/switch.h @@ -71,7 +71,7 @@ class Case final : public Node { } removeChildren(_end_exprs, {}); - addChildren(ctx, std::move(exprs)); + addChildren(ctx, exprs); } std::string _dump() const final; diff --git a/hilti/toolchain/include/ast/types/bitfield.h b/hilti/toolchain/include/ast/types/bitfield.h index f421c7bf3..be60ab4dd 100644 --- a/hilti/toolchain/include/ast/types/bitfield.h +++ b/hilti/toolchain/include/ast/types/bitfield.h @@ -131,13 +131,13 @@ class Bitfield : public UnqualifiedType, public node::WithUniqueID { return UnqualifiedType::properties() + node::WithUniqueID::properties() + p; } - static auto create(ASTContext* ctx, unsigned int width, type::bitfield::BitRanges bits, AttributeSet* attrs, + static auto create(ASTContext* ctx, unsigned int width, const type::bitfield::BitRanges& bits, AttributeSet* attrs, const Meta& m = Meta()) { if ( ! attrs ) attrs = AttributeSet::create(ctx); auto value = bitfield::BitRange::create(ctx, ID("__value__"), 0, width - 1, width, {}, m); - return ctx->make(ctx, node::flatten(attrs, std::move(bits), value), width, m); + return ctx->make(ctx, node::flatten(attrs, bits, value), width, m); } static auto create(ASTContext* ctx, Wildcard _, const Meta& m = Meta()) { diff --git a/hilti/toolchain/include/ast/types/struct.h b/hilti/toolchain/include/ast/types/struct.h index 884f77903..9d7345524 100644 --- a/hilti/toolchain/include/ast/types/struct.h +++ b/hilti/toolchain/include/ast/types/struct.h @@ -64,11 +64,12 @@ class Struct : public UnqualifiedType { bool isNameType() const final { return true; } bool isResolved(node::CycleDetector* cd) const final; - static auto create(ASTContext* ctx, const declaration::Parameters& params, Declarations fields, Meta meta = {}) { + static auto create(ASTContext* ctx, const declaration::Parameters& params, const Declarations& fields, + Meta meta = {}) { for ( auto&& p : params ) p->setIsTypeParameter(); - auto t = ctx->make(ctx, node::flatten(nullptr, params, std::move(fields)), std::move(meta)); + auto t = ctx->make(ctx, node::flatten(nullptr, params, fields), std::move(meta)); t->_setSelf(ctx); return t; } @@ -80,8 +81,8 @@ class Struct : public UnqualifiedType { } struct AnonymousStruct {}; - static auto create(ASTContext* ctx, AnonymousStruct _, Declarations fields, Meta meta = {}) { - auto t = ctx->make(ctx, node::flatten(nullptr, std::move(fields)), std::move(meta)); + static auto create(ASTContext* ctx, AnonymousStruct _, const Declarations& fields, Meta meta = {}) { + auto t = ctx->make(ctx, node::flatten(nullptr, fields), std::move(meta)); t->_setSelf(ctx); return t; } diff --git a/hilti/toolchain/include/ast/types/tuple.h b/hilti/toolchain/include/ast/types/tuple.h index 04cb53420..f9918fcd2 100644 --- a/hilti/toolchain/include/ast/types/tuple.h +++ b/hilti/toolchain/include/ast/types/tuple.h @@ -61,8 +61,8 @@ class Tuple : public UnqualifiedType { bool isResolved(node::CycleDetector* cd) const final; bool isSortable() const final { return true; } - static auto create(ASTContext* ctx, type::tuple::Elements elements, Meta meta = {}) { - return ctx->make(ctx, std::move(elements), std::move(meta)); + static auto create(ASTContext* ctx, const type::tuple::Elements& elements, Meta meta = {}) { + return ctx->make(ctx, elements, std::move(meta)); } static auto create(ASTContext* ctx, const QualifiedTypes& types, Meta meta = {}) { diff --git a/hilti/toolchain/include/ast/types/union.h b/hilti/toolchain/include/ast/types/union.h index 4c09e5f48..53be1f8b8 100644 --- a/hilti/toolchain/include/ast/types/union.h +++ b/hilti/toolchain/include/ast/types/union.h @@ -63,11 +63,12 @@ class Union : public UnqualifiedType { bool isNameType() const final { return true; } bool isResolved(node::CycleDetector* cd) const final; - static auto create(ASTContext* ctx, const declaration::Parameters& params, Declarations fields, Meta meta = {}) { + static auto create(ASTContext* ctx, const declaration::Parameters& params, const Declarations& fields, + Meta meta = {}) { for ( auto&& p : params ) p->setIsTypeParameter(); - return ctx->make(ctx, node::flatten(params, std::move(fields)), -1, std::move(meta)); + return ctx->make(ctx, node::flatten(params, fields), -1, std::move(meta)); } static auto create(ASTContext* ctx, const Declarations& fields, Meta meta = {}) { @@ -75,8 +76,8 @@ class Union : public UnqualifiedType { } union AnonymousUnion {}; - static auto create(ASTContext* ctx, AnonymousUnion _, Declarations fields, Meta meta = {}) { - return ctx->make(ctx, std::move(fields), ++anon_union_counter, std::move(meta)); + static auto create(ASTContext* ctx, AnonymousUnion _, const Declarations& fields, Meta meta = {}) { + return ctx->make(ctx, fields, ++anon_union_counter, std::move(meta)); } static auto create(ASTContext* ctx, Wildcard _, Meta meta = {}) { diff --git a/hilti/toolchain/include/ast/visitor.h b/hilti/toolchain/include/ast/visitor.h index ce49360b7..2171037a8 100644 --- a/hilti/toolchain/include/ast/visitor.h +++ b/hilti/toolchain/include/ast/visitor.h @@ -273,7 +273,7 @@ class MutatingVisitor : public Visitor, public MutatingVisito * @param builder builder to use for modifications * @param dbg debug stream to log modifications to */ - MutatingVisitor(Builder* builder, logging::DebugStream dbg) + MutatingVisitor(Builder* builder, const logging::DebugStream& dbg) : MutatingVisitorBase(contextFromBuilder(builder), dbg), _builder(builder) {} using visitor::MutatingVisitorBase::MutatingVisitorBase; diff --git a/hilti/toolchain/src/compiler/resolver.cc b/hilti/toolchain/src/compiler/resolver.cc index c8d32cee7..9b94452ed 100644 --- a/hilti/toolchain/src/compiler/resolver.cc +++ b/hilti/toolchain/src/compiler/resolver.cc @@ -291,7 +291,7 @@ struct VisitorPass2 : visitor::MutatingPostOrder { // expressions or the type aren't fully resolved yet. Returns an error if a // coercion failed with a hard error. template - Result> coerceCallArguments(Container1 exprs, Container2 params) { + Result> coerceCallArguments(Container1 exprs, const Container2& params) { // Build a tuple to coerce expression according to an OperandList. for ( const auto& e : exprs ) { if ( ! e->isResolved() ) @@ -554,7 +554,7 @@ struct VisitorPass2 : visitor::MutatingPostOrder { if ( auto x = n->typeArguments(); x.size() ) { if ( auto coerced = coerceCallArguments(x, t->type()->parameters()); coerced && *coerced ) { recordChange(n, builder()->ctorTuple(**coerced), "call arguments"); - n->setTypeArguments(context(), std::move(**coerced)); + n->setTypeArguments(context(), **coerced); } } } diff --git a/spicy/toolchain/include/ast/ctors/unit.h b/spicy/toolchain/include/ast/ctors/unit.h index c6c4812ff..bfbf0cc93 100644 --- a/spicy/toolchain/include/ast/ctors/unit.h +++ b/spicy/toolchain/include/ast/ctors/unit.h @@ -45,13 +45,13 @@ class Unit : public Ctor { void setType(ASTContext* ctx, QualifiedType* t) { setChild(ctx, 0, t); } - static auto create(ASTContext* ctx, ctor::unit::Fields fields, Meta meta = {}) { + static auto create(ASTContext* ctx, const ctor::unit::Fields& fields, Meta meta = {}) { auto auto_ = QualifiedType::create(ctx, hilti::type::Auto::create(ctx), hilti::Constness::Const, meta); - return ctx->make(ctx, node::flatten(auto_, std::move(fields)), std::move(meta)); + return ctx->make(ctx, node::flatten(auto_, fields), std::move(meta)); } - static auto create(ASTContext* ctx, ctor::unit::Fields fields, QualifiedType* t, Meta meta = {}) { - return ctx->make(ctx, node::flatten(t, std::move(fields)), std::move(meta)); + static auto create(ASTContext* ctx, const ctor::unit::Fields& fields, QualifiedType* t, Meta meta = {}) { + return ctx->make(ctx, node::flatten(t, fields), std::move(meta)); } protected: diff --git a/spicy/toolchain/include/ast/statements/print.h b/spicy/toolchain/include/ast/statements/print.h index c26e315d0..0fd942494 100644 --- a/spicy/toolchain/include/ast/statements/print.h +++ b/spicy/toolchain/include/ast/statements/print.h @@ -16,8 +16,8 @@ class Print : public Statement { public: auto expressions() const { return children(0, {}); } - static auto create(ASTContext* ctx, Expressions expressions, Meta meta = {}) { - return ctx->make(ctx, std::move(expressions), std::move(meta)); + static auto create(ASTContext* ctx, const Expressions& expressions, Meta meta = {}) { + return ctx->make(ctx, expressions, std::move(meta)); } protected: diff --git a/spicy/toolchain/include/ast/types/unit-items/block.h b/spicy/toolchain/include/ast/types/unit-items/block.h index a9a2ac6d2..fb9e31408 100644 --- a/spicy/toolchain/include/ast/types/unit-items/block.h +++ b/spicy/toolchain/include/ast/types/unit-items/block.h @@ -48,10 +48,10 @@ class Block : public unit::Item { } protected: - Block(ASTContext* ctx, int else_start, Nodes children, Meta meta) + Block(ASTContext* ctx, int else_start, const Nodes& children, Meta meta) : unit::Item(ctx, NodeTags, node::flatten(QualifiedType::create(ctx, hilti::type::Void::create(ctx), hilti::Constness::Const), - std::move(children)), + children), ID(), std::move(meta)), _else_start(else_start) {} diff --git a/spicy/toolchain/include/ast/types/unit.h b/spicy/toolchain/include/ast/types/unit.h index dd6f03d76..596db8be1 100644 --- a/spicy/toolchain/include/ast/types/unit.h +++ b/spicy/toolchain/include/ast/types/unit.h @@ -105,8 +105,8 @@ class Unit : public UnqualifiedType { } /** Adds a number of new items to the unit. */ - void addItems(ASTContext* ctx, unit::Items items) { - addChildren(ctx, std::move(items)); + void addItems(ASTContext* ctx, const unit::Items& items) { + addChildren(ctx, items); _assignItemIndices(); } @@ -133,7 +133,7 @@ class Unit : public UnqualifiedType { return hilti::UnqualifiedType::properties() + p; } - static auto create(ASTContext* ctx, const hilti::declaration::Parameters& params, type::unit::Items items, + static auto create(ASTContext* ctx, const hilti::declaration::Parameters& params, const type::unit::Items& items, AttributeSet* attrs, Meta meta = {}) { if ( ! attrs ) attrs = hilti::AttributeSet::create(ctx); @@ -141,8 +141,7 @@ class Unit : public UnqualifiedType { for ( auto&& p : params ) p->setIsTypeParameter(); - auto t = - ctx->make(ctx, node::flatten(nullptr, attrs, nullptr, params, std::move(items)), std::move(meta)); + auto t = ctx->make(ctx, node::flatten(nullptr, attrs, nullptr, params, items), std::move(meta)); t->_setSelf(ctx); return t; From 27969acd114ebc2c70bb2cf93897564dd2ed9329 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Wed, 18 Dec 2024 13:59:51 +0100 Subject: [PATCH 15/19] Bump LLVM toolchain used in CI. --- .cirrus.yml | 18 +++++++++--------- ci/Dockerfile | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 1e5e35fab..a9fd46972 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -37,12 +37,12 @@ lint_task: env: CCACHE_DIR: /tmp/ccache - LD_LIBRARY_PATH: /usr/lib/llvm-18/lib/clang/18/lib/linux/ + LD_LIBRARY_PATH: /usr/lib/llvm-19/lib/clang/19/lib/linux/ update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-18 --clang-format `which clang-format-18` --clang-tidy `which clang-tidy-18` + configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-19 --clang-format `which clang-format-19` --clang-tidy `which clang-tidy-19` --run-clang-tidy `which run-clang-tidy-19` build_script: ./ci/run-ci -b build build test_code_script: ./ci/run-ci -b build test-code @@ -56,7 +56,7 @@ lint_task: clang_artifacts: path: build/ci -clang18_ubuntu_debug_task: +clang19_ubuntu_debug_task: container: dockerfile: ci/Dockerfile cpu: 4 @@ -72,12 +72,12 @@ clang18_ubuntu_debug_task: env: CCACHE_DIR: /tmp/ccache - LD_LIBRARY_PATH: /usr/lib/llvm-18/lib/clang/18/lib/linux/ + LD_LIBRARY_PATH: /usr/lib/llvm-19/lib/clang/19/lib/linux/ update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-18 --clang-format `which clang-format-18` --clang-tidy `which clang-tidy-18` + configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-19 --clang-format `which clang-format-19` --clang-tidy `which clang-tidy-19` build_script: ./ci/run-ci -b build build test_build_script: ./ci/run-ci -b build test-build install_script: ./ci/run-ci -b build install @@ -98,7 +98,7 @@ clang18_ubuntu_debug_task: clang_artifacts: path: build/ci -clang18_lts_ubuntu_release_task: +clang19_lts_ubuntu_release_task: container: dockerfile: ci/Dockerfile cpu: 4 @@ -118,7 +118,7 @@ clang18_lts_ubuntu_release_task: update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-18 --clang-format `which clang-format-18` --clang-tidy `which clang-tidy-18` + configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-19 --clang-format `which clang-format-19` --clang-tidy `which clang-tidy-19` build_script: ./ci/run-ci -b build build test_build_script: ./ci/run-ci -b build test-build install_script: ./ci/run-ci -b build install @@ -139,7 +139,7 @@ clang18_lts_ubuntu_release_task: type: text/xml format: junit -clang18_lts_ubuntu_release_static_task: +clang19_lts_ubuntu_release_static_task: container: dockerfile: ci/Dockerfile cpu: 4 @@ -159,7 +159,7 @@ clang18_lts_ubuntu_release_static_task: update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-18 --clang-format `which clang-format-18` --clang-tidy `which clang-tidy-18` --build-static-libs + configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-19 --clang-format `which clang-format-19` --clang-tidy `which clang-tidy-19` --build-static-libs build_script: ./ci/run-ci -b build build install_script: ./ci/run-ci -b build install cleanup_script: ./ci/run-ci -b build cleanup diff --git a/ci/Dockerfile b/ci/Dockerfile index a08d0b4e5..f5f737e1e 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -40,10 +40,10 @@ RUN apt-get update \ # GCC. && apt-get install -y --no-install-recommends g++ gcc \ # LLVM toolchain. - && echo 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main' >> /etc/apt/sources.list.d/llvm18.list \ - && echo 'deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main' >> /etc/apt/sources.list.d/llvm18.list \ + && echo 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main' >> /etc/apt/sources.list.d/llvm19.list \ + && echo 'deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main' >> /etc/apt/sources.list.d/llvm19.list \ && curl https://apt.llvm.org/llvm-snapshot.gpg.key -o /etc/apt/trusted.gpg.d/llvm.asc \ && apt-get update \ - && apt-get install -y --no-install-recommends llvm-18-dev clang-18 libclang-18-dev clang-format-18 clang-tidy-18 libclang-rt-18-dev \ + && apt-get install -y --no-install-recommends llvm-19-dev clang-19 libclang-19-dev clang-format-19 clang-tidy-19 libclang-rt-19-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* From 4114a23980be811fe7cc7d6dd8bab9f482313123 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Wed, 18 Dec 2024 16:23:35 +0100 Subject: [PATCH 16/19] Update CMake version in CI for clang-tidy. --- ci/Dockerfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ci/Dockerfile b/ci/Dockerfile index f5f737e1e..f44d409a3 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -14,7 +14,6 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends \ bison \ ccache \ - cmake \ doxygen \ flex \ g++ \ @@ -45,5 +44,11 @@ RUN apt-get update \ && curl https://apt.llvm.org/llvm-snapshot.gpg.key -o /etc/apt/trusted.gpg.d/llvm.asc \ && apt-get update \ && apt-get install -y --no-install-recommends llvm-19-dev clang-19 libclang-19-dev clang-format-19 clang-tidy-19 libclang-rt-19-dev \ + # Install a recent CMake for `SKIP_LINTING` support. + && test -f /usr/share/doc/kitware-archive-keyring/copyright || \ + curl https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null \ + && echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | tee /etc/apt/sources.list.d/kitware.list >/dev/null \ + && apt-get update \ + && apt-get install -y --no-install-recommends kitware-archive-keyring cmake \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* From eab2a5fb8e9ab2dc204cff4d81bed8a92d0cdf15 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Wed, 18 Dec 2024 13:55:54 +0100 Subject: [PATCH 17/19] Move `./ci/run-ci`'s clang-tidy check to CMake. Instead of implementing this ourself instea use CMake with `CMAKE_CXX_CLANG_TIDY`/`CMAKE_C_CLANG_TIDY`. --- .cirrus.yml | 8 +-- .clang-tidy.ignore | 13 ---- Makefile | 27 -------- ci/run-ci | 33 ++-------- scripts/run-clang-tidy | 138 ----------------------------------------- 5 files changed, 10 insertions(+), 209 deletions(-) delete mode 100644 .clang-tidy.ignore delete mode 100644 Makefile delete mode 100755 scripts/run-clang-tidy diff --git a/.cirrus.yml b/.cirrus.yml index a9fd46972..c9e2e76f6 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -42,7 +42,7 @@ lint_task: update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-19 --clang-format `which clang-format-19` --clang-tidy `which clang-tidy-19` --run-clang-tidy `which run-clang-tidy-19` + configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-19 --clang-format `which clang-format-19` --clang-tidy `which clang-tidy-19` build_script: ./ci/run-ci -b build build test_code_script: ./ci/run-ci -b build test-code @@ -77,7 +77,7 @@ clang19_ubuntu_debug_task: update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-19 --clang-format `which clang-format-19` --clang-tidy `which clang-tidy-19` + configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-19 --clang-format `which clang-format-19` build_script: ./ci/run-ci -b build build test_build_script: ./ci/run-ci -b build test-build install_script: ./ci/run-ci -b build install @@ -118,7 +118,7 @@ clang19_lts_ubuntu_release_task: update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-19 --clang-format `which clang-format-19` --clang-tidy `which clang-tidy-19` + configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-19 --clang-format `which clang-format-19` build_script: ./ci/run-ci -b build build test_build_script: ./ci/run-ci -b build test-build install_script: ./ci/run-ci -b build install @@ -159,7 +159,7 @@ clang19_lts_ubuntu_release_static_task: update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-19 --clang-format `which clang-format-19` --clang-tidy `which clang-tidy-19` --build-static-libs + configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-19 --clang-format `which clang-format-19` build_script: ./ci/run-ci -b build build install_script: ./ci/run-ci -b build install cleanup_script: ./ci/run-ci -b build cleanup diff --git a/.clang-tidy.ignore b/.clang-tidy.ignore deleted file mode 100644 index c9123896e..000000000 --- a/.clang-tidy.ignore +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2020-2023 by the Zeek Project. See LICENSE for details. -# -# Paths to source files to ignore when running clang-tidy. This is -# evaluated by scripts/run-clang-tidy. -# -# Note that this doesn't catch header files to ignore. We use a -# combination of HeaderFilterRegex and file names starting with "__" to -# select which headers to skip. - -.*3rdparty/ -hilti/src/rt/types/regexp.cc # Too many warnings due to usage of jrx C API. -spicy/toolchain/tests/grammar.cc # odd identifier naming -tests/ diff --git a/Makefile b/Makefile deleted file mode 100644 index 01eecae3a..000000000 --- a/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (c) 2020-2023 by the Zeek Project. See LICENSE for details. - -all: build - -.PHONY: build doc - -build: - @if [ -e build/Makefile ]; then $(MAKE) -C build; else true; fi - @if [ -e build/build.ninja ]; then ninja -C build; else true; fi - -install: - @if [ -e build/Makefile ]; then $(MAKE) -C build install; else true; fi - @if [ -e build/build.ninja ]; then ninja -C build install; else true; fi - -doc: - $(MAKE) -C doc - -test: - $(MAKE) -C tests test - -tidy: - ./scripts/run-clang-tidy -j 10 build - -tidy-fixit: - ./scripts/run-clang-tidy -j 10 --fixit build - -check: test format tidy diff --git a/ci/run-ci b/ci/run-ci index 381f03cf4..55fd7805a 100755 --- a/ci/run-ci +++ b/ci/run-ci @@ -166,6 +166,12 @@ function run_configure { echo "${clang_format}" >${build}/.clang_format echo "${clang_tidy}" >${build}/.clang_tidy + + if [ -x "${clang_tidy}" ]; then + pushd "${build}" >/dev/null || exit 1 + cmake -DCMAKE_CXX_CLANG_TIDY="${clang_tidy}" -DCMAKE_C_CLANG_TIDY="${clang_tidy}" .. + popd >/dev/null || exit 1 + fi } function run_build { @@ -233,38 +239,11 @@ function run_test_btest { execute_btest "Spicy" "tests" "${alternative}" } -function run_test_clang_tidy { - clang_tidy=$(cat ${build}/.clang_tidy 2>/dev/null) - - if [ ! -x ${clang_tidy} ]; then - log_warning "clang-tidy not available, skipping" - return 0 - fi - - log_stage "Running clang-tidy ..." - - export CLANG_TIDY=${clang_tidy} - - if ${root}/scripts/run-clang-tidy --fixit -j 3 ${build}; then - echo "clang-tidy run passed" - return 0 - else - git diff | tee ${artifacts}/clang-tidy.diff - log_diag "Patch to what can be fixed automatically in 'clang-tidy.diff'" - log_error "clang-tidy has failed" - return 1 - fi -} - function run_test_code { rc=0 pre-commit run -a --show-diff-on-failure || rc=1 - pushd $(pwd) >/dev/null - run_test_clang_tidy || rc=1 - popd >/dev/null - return ${rc} } diff --git a/scripts/run-clang-tidy b/scripts/run-clang-tidy deleted file mode 100755 index 5e36edb84..000000000 --- a/scripts/run-clang-tidy +++ /dev/null @@ -1,138 +0,0 @@ -#! /bin/sh -# -# Copyright (c) 2020-2023 by the Zeek Project. See LICENSE for details. - -usage() { - echo "Usage: $(basename $0) [--fixit] [-j ] [--clang-tidy-path ] [--clang-tidy-arg ] []" - exit 1 -} - -error() { - echo "$@" >&2 -} - -abspath() { - printf "%s/%s\n" "$(cd $(dirname $1) && pwd)" "$(basename $1)" -} - -cleanup() { - rm -rf "${tmpdir} ${error}" -} - -fix="" -clang_tidy_args="" -files="" -parallel=1 - -if [ -n "${CLANG_TIDY}" ]; then - clang_tidy_path=${CLANG_TIDY} -else - clang_tidy_path=$(which clang-tidy 2>/dev/null) -fi - -while true; do - case "$1" in - --fixit) fix=1; shift;; - --clang-tidy-path) clang_tidy_path="$2"; shift; shift;; - --clang-tidy-arg) clang_tidy_args="${clang_tidy_args} $2"; shift; shift;; - --ignore) ignores="${ignores:+${ignores}|}$2"; shift; shift;; - -j) parallel="$2"; shift; shift;; - -h | --help) usage;; - --) shift; break;; - --*) usage;; - *) break;; - esac -done - -if [ $# -lt 1 ]; then - usage -fi - -build=$(cd $1 && pwd) -root=$(cd ${build}/.. && pwd) -shift - -for f in $@; do - files=$(printf "%s %s\n" ${files} $(abspath ${f})) -done - -cd ${build} - -cmake_cache=CMakeCache.txt -compile_json=compile_commands.json -clang_tidy_ignore=${root}/.clang-tidy.ignore - -if ! which jq >/dev/null 2>&1; then - error "Need jq in PATH, aborting." && exit 1 -fi - -for i in ${cmake_cache} ${compile_json} bin/hiltic; do - if [ ! -f ${i} ]; then - error "${i} not found, did you configure and build?" && exit 1 - fi -done - -if [ -z "${clang_tidy_path}" ]; then - clang_tidy_path=$(cat ${cmake_cache} | grep CMAKE_CXX_COMPILER:PATH | cut -d = -f 2 | sed 's/clang+\{0,2\}/clang-tidy/') -fi - -if [ ! -x "${clang_tidy_path}" ]; then - error "cannot find clang-tidy" && exit 1 -fi - -if [ "${fix}" = 1 -a -n "$(git status --porcelain | grep -E -v '^(M|\?\?) ')" ]; then - echo >&2 - echo "error: uncommitted changes in working directory, won't apply changes" >&2 - echo >&2 - git status -sb >&2 - exit 1 -fi - -clang_apply_replacements_path=$(echo ${clang_tidy_path} | sed 's/clang-tidy/clang-apply-replacements/') - -if [ ! -x "${clang_apply_replacements_path}" ]; then - error "cannot find clang-apply-replacements" && exit 1 -fi - -if [ -f "${clang_tidy_ignore}" ]; then - x=$(cat ${clang_tidy_ignore} | grep -E -v '^ *(#.*)?$' | awk '{printf "%s|", $1}' | sed 's/|$//g') - ignores="${ignores:+${ignores}|}${x}" -fi - -if [ -z "${ignores}" ]; then - ignores="__NEVER_MATCHES__" -fi - -if [ -z "${files}" ]; then - files=$(cat ${compile_json} | jq -r '.[].file' | grep -E '\.(cc|c|h)$' | grep -v autogen/__ | grep -v '\.bif\.' | grep -E -v "${root}/(${ignores})") -fi - -cmd="${clang_tidy_path} -quiet -p=${build} ${clang_tidy_args}" - -error=/tmp/$(basename $0).$$.error.tmp -tmpdir=/tmp/$(basename $0).$$.tmp -rm -rf "${tmpdir}" -mkdir -p "${tmpdir}" -trap cleanup EXIT - -base=$(cd ${build}/.. && pwd) -rm -f ${error} - -echo "${files}" | awk -v "cmd=${cmd}" -v "tmp=${tmpdir}" '{t=$1; gsub("[/]", "_", t); printf("%s -export-fixes=%s/%s.yaml %s\n", cmd, tmp, t, $1);}' \ - | tr '\n' '\0' | (xargs -0 -n 1 -P ${parallel} sh -c 2>&1 || touch ${error}) | grep -v 'warnings\? generated\.$' | sed "s#^../\(.*:\)#${base}/\1#g" - -if [ -e "${error}" ]; then - rc=1 -else - rc=0 -fi - -if [ ${rc} != 0 -a -n "${fix}" ]; then - # It looks like clang-apply-replacements can merge & unique changes from - # multiple files. In case that turns out not to work, we could borrow - # from LLVM's run-clang-tidy.py script). That has Python code to merge - # replacements ahead of time. - ${clang_apply_replacements_path} ${tmpdir} -fi - -exit ${rc} From 616a88f62d0a9ed5fc8cd95bad94b67f22ca8d00 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Fri, 20 Dec 2024 14:02:06 +0100 Subject: [PATCH 18/19] Drop unused clang-format integration in `./ci/run-ci`. This was already unused since we moved clang-format to a pre-commit hook. --- .cirrus.yml | 8 ++++---- ci/Dockerfile | 2 +- ci/run-ci | 11 ----------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index c9e2e76f6..e714a96c5 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -42,7 +42,7 @@ lint_task: update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-19 --clang-format `which clang-format-19` --clang-tidy `which clang-tidy-19` + configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-19 --clang-tidy `which clang-tidy-19` build_script: ./ci/run-ci -b build build test_code_script: ./ci/run-ci -b build test-code @@ -77,7 +77,7 @@ clang19_ubuntu_debug_task: update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-19 --clang-format `which clang-format-19` + configure_script: ./ci/run-ci -b build configure debug --cxx-compiler clang++-19 build_script: ./ci/run-ci -b build build test_build_script: ./ci/run-ci -b build test-build install_script: ./ci/run-ci -b build install @@ -118,7 +118,7 @@ clang19_lts_ubuntu_release_task: update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-19 --clang-format `which clang-format-19` + configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-19 build_script: ./ci/run-ci -b build build test_build_script: ./ci/run-ci -b build test-build install_script: ./ci/run-ci -b build install @@ -159,7 +159,7 @@ clang19_lts_ubuntu_release_static_task: update_git_script: - git submodule update --recursive --init - configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-19 --clang-format `which clang-format-19` + configure_script: ./ci/run-ci -b build configure release --cxx-compiler clang++-19 build_script: ./ci/run-ci -b build build install_script: ./ci/run-ci -b build install cleanup_script: ./ci/run-ci -b build cleanup diff --git a/ci/Dockerfile b/ci/Dockerfile index f44d409a3..ac5f51ee1 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -43,7 +43,7 @@ RUN apt-get update \ && echo 'deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main' >> /etc/apt/sources.list.d/llvm19.list \ && curl https://apt.llvm.org/llvm-snapshot.gpg.key -o /etc/apt/trusted.gpg.d/llvm.asc \ && apt-get update \ - && apt-get install -y --no-install-recommends llvm-19-dev clang-19 libclang-19-dev clang-format-19 clang-tidy-19 libclang-rt-19-dev \ + && apt-get install -y --no-install-recommends llvm-19-dev clang-19 libclang-19-dev clang-tidy-19 libclang-rt-19-dev \ # Install a recent CMake for `SKIP_LINTING` support. && test -f /usr/share/doc/kitware-archive-keyring/copyright || \ curl https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null \ diff --git a/ci/run-ci b/ci/run-ci index 55fd7805a..072d97d16 100755 --- a/ci/run-ci +++ b/ci/run-ci @@ -45,7 +45,6 @@ Global options: Configure options: --build-toolchain={yes,no} Build the Spicy compiler toolchain [default: yes] - --clang-format Path to clang-format to use (default: found in PATH) --clang-tidy Path to clang-tidy to use (default: found in PATH) --cxx-compiler Path to C++ compiler to use (default: found by cmake) --disable-precompiled-headers Disable use of precompiled headers for developer tests @@ -92,7 +91,6 @@ function run_configure { mkdir -p ${install} configure="./configure --builddir=${build} --prefix=${install} --generator=Ninja --enable-werror --enable-ccache --with-hilti-compiler-launcher=ccache" - clang_format=$(which clang-format 2>/dev/null) clang_tidy=$(which clang-tidy 2>/dev/null) if [ "${build_type}" == "release" ]; then @@ -111,13 +109,6 @@ function run_configure { shift 2; ;; - --clang-format) - test $# -gt 0 || usage - clang_format="$2" - test -x ${clang_format} || error "clang-format not found in $2" - shift 2; - ;; - --clang-tidy) test $# -gt 0 || usage clang_tidy="$2" @@ -153,7 +144,6 @@ function run_configure { error "Build directory ${build} already exists, delete first" fi - test -z "${clang_format}" && log_stage "Warning: No clang-format found, will skip any related tests" test -z "${clang_tidy}" && log_stage "Warning: No clang-tidy found, will skip any related tests" # Looks like Cirrus CI doesn't fetch tags. @@ -164,7 +154,6 @@ function run_configure { ${configure} || exit 1 mkdir -p ${artifacts} - echo "${clang_format}" >${build}/.clang_format echo "${clang_tidy}" >${build}/.clang_tidy if [ -x "${clang_tidy}" ]; then From a050c874026a4b66ffce99f503494786760813cb Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 7 Jan 2025 15:27:52 +0100 Subject: [PATCH 19/19] Bump `3rdparty/filesystem` to pick up fixes for clang-tidy-19. --- 3rdparty/filesystem | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty/filesystem b/3rdparty/filesystem index 42ea4fc61..076592ce6 160000 --- a/3rdparty/filesystem +++ b/3rdparty/filesystem @@ -1 +1 @@ -Subproject commit 42ea4fc6159d6078f08f1b0531a45d88b9e2c989 +Subproject commit 076592ce6e64568521b88a11881aa36b3d3f7048