From cf3b1218c4bd7f816279e175a061cb861186ce35 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 23 Jun 2019 00:28:48 -0600 Subject: [PATCH] ircd: Misc fixes for clang. --- include/ircd/allocator.h | 14 +++++--- include/ircd/js.h | 1 + include/ircd/net/listener_udp.h | 2 +- include/ircd/prof.h | 4 +-- include/ircd/stdinc.h | 5 ++- include/ircd/util/tuple.h | 2 +- include/ircd/util/util.h | 2 +- ircd/assert.cc | 3 ++ ircd/ctx.cc | 13 +++---- ircd/db.cc | 20 ++++++----- ircd/exception.cc | 7 +++- ircd/fs_aio.cc | 2 ++ ircd/ios.cc | 4 +++ ircd/json.cc | 8 ++--- ircd/m.cc | 62 ++++++++++++++++----------------- ircd/m_event.cc | 2 +- ircd/mods.cc | 2 +- ircd/net.cc | 8 ++--- ircd/openssl.cc | 1 + ircd/prof.cc | 31 ++++++++--------- 20 files changed, 106 insertions(+), 87 deletions(-) diff --git a/include/ircd/allocator.h b/include/ircd/allocator.h index 9bf4cb635..36320df01 100644 --- a/include/ircd/allocator.h +++ b/include/ircd/allocator.h @@ -119,7 +119,7 @@ struct ircd::allocator::scope scope(alloc_closure = {}, realloc_closure = {}, free_closure = {}); scope(const scope &) = delete; scope(scope &&) = delete; - ~scope(); + ~scope() noexcept; }; /// Internal state structure for some of these tools. This is a very small and @@ -290,8 +290,12 @@ struct ircd::allocator::fixed operator allocator(); fixed() - :state{MAX, avail.data()} - {} + { + static_cast(*this) = + { + MAX, avail.data() + }; + } }; /// The actual allocator template as used by the container. @@ -342,7 +346,7 @@ struct ircd::allocator::fixed::allocator allocate(std::nothrow_t, const size_type &n, const const_pointer &hint = nullptr) { const auto base(reinterpret_cast(s->buf.data())); - const uint hintpos(hint? uintptr_t(hint - base) : uintptr_t(-1)); + const uint hintpos(hint? uint(hint - base) : uint(-1)); const pointer ret(base + s->state::allocate(std::nothrow, n, hintpos)); return s->in_range(ret)? ret : nullptr; } @@ -352,7 +356,7 @@ struct ircd::allocator::fixed::allocator allocate(const size_type &n, const const_pointer &hint = nullptr) { const auto base(reinterpret_cast(s->buf.data())); - const uint hintpos(hint? uintptr_t(hint - base) : uintptr_t(-1)); + const uint hintpos(hint? uint(hint - base) : uint(-1)); return base + s->state::allocate(n, hintpos); } diff --git a/include/ircd/js.h b/include/ircd/js.h index d5c5cf64e..042aa6eb2 100644 --- a/include/ircd/js.h +++ b/include/ircd/js.h @@ -59,6 +59,7 @@ ircd::js::init::init() inline ircd::js::init::~init() +noexcept { } diff --git a/include/ircd/net/listener_udp.h b/include/ircd/net/listener_udp.h index 96e7a1e6e..6c722d083 100644 --- a/include/ircd/net/listener_udp.h +++ b/include/ircd/net/listener_udp.h @@ -74,7 +74,7 @@ struct ircd::net::listener_udp::datagram datagram(const mutable_buffer &buf, const enum flag &flag = (enum flag)0); - datagram() = default; + datagram() {} }; enum ircd::net::listener_udp::flag diff --git a/include/ircd/prof.h b/include/ircd/prof.h index 4cb345554..4496c7807 100644 --- a/include/ircd/prof.h +++ b/include/ircd/prof.h @@ -106,7 +106,7 @@ struct ircd::prof::instructions const uint64_t &at() const; const uint64_t &sample(); - instructions() noexcept; + instructions(); instructions(instructions &&) = delete; instructions(const instructions &) = delete; ~instructions() noexcept; @@ -207,7 +207,7 @@ struct ircd::prof::system system(sample_t) noexcept; system() - :array_type{{0}} + :array_type{{{0}}} {} }; diff --git a/include/ircd/stdinc.h b/include/ircd/stdinc.h index 2a4721945..7c73ef3ff 100644 --- a/include/ircd/stdinc.h +++ b/include/ircd/stdinc.h @@ -203,8 +203,11 @@ namespace ircd using std::chrono::high_resolution_clock; using std::chrono::time_point; - using namespace std::literals::chrono_literals; using namespace std::string_literals; + using namespace std::chrono_literals; + using namespace std::literals::chrono_literals; + using std::string_literals::operator""s; + using std::chrono_literals::operator""s; namespace ph = std::placeholders; diff --git a/include/ircd/util/tuple.h b/include/ircd/util/tuple.h index b8d4488ac..ca9cdafaf 100644 --- a/include/ircd/util/tuple.h +++ b/include/ircd/util/tuple.h @@ -409,7 +409,7 @@ template(std::addressof(std::get(t))) - reinterpret_cast(std::addressof(t)) diff --git a/include/ircd/util/util.h b/include/ircd/util/util.h index d7575c54f..5c0087d79 100644 --- a/include/ircd/util/util.h +++ b/include/ircd/util/util.h @@ -158,7 +158,7 @@ at(It &&start, { for(; start != stop; --i, std::advance(start, 1)) if(!i) - return start; + return std::move(start); throw std::out_of_range { diff --git a/ircd/assert.cc b/ircd/assert.cc index d01f3602f..59af49fbe 100644 --- a/ircd/assert.cc +++ b/ircd/assert.cc @@ -34,6 +34,8 @@ __assert_perror_fail(int __errnum, #endif #if !defined(NDEBUG) && defined(RB_ASSERT) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" void __assert_fail(const char *__assertion, const char *__file, @@ -89,6 +91,7 @@ __assert_fail(const char *__assertion, else __builtin_trap(); } +#pragma clang diagnostic pop #endif void diff --git a/ircd/ctx.cc b/ircd/ctx.cc index d97a7e4f9..c4e95fdab 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -789,7 +789,7 @@ noexcept assert(bool(*this)); #ifdef HAVE_CXXABI_H - __cxa_end_catch(); + __cxxabiv1::__cxa_end_catch(); #endif // We don't yet support more levels of exceptions; after ending this @@ -1533,7 +1533,7 @@ try { const auto func { - std::move(q.pop()) + q.pop() }; const scope_count working @@ -2146,21 +2146,16 @@ noexcept } ircd::ctx::promise_base::~promise_base() -noexcept try +noexcept { if(!valid()) return; if(refcount(state()) == 1) - throw broken_promise{}; + set_exception(make_exception_ptr()); else remove(state(), *this); } -catch(const std::exception &e) -{ - set_exception(std::current_exception()); - return; -} void ircd::ctx::promise_base::set_exception(std::exception_ptr eptr) diff --git a/ircd/db.cc b/ircd/db.cc index 50b74ec07..acd63020b 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -1243,11 +1243,11 @@ try existing.erase(descriptor.name); } - for(const auto &remain : existing) + if(!existing.empty()) throw error { "Failed to describe existing column '%s' (and %zd others...)", - remain, + *begin(existing), existing.size() - 1 }; @@ -1427,7 +1427,7 @@ catch(const error &e) log::error { "Error opening db '%s': %s", - this->name, + name, e.what() }; @@ -1438,14 +1438,14 @@ catch(const std::exception &e) log::error { "Error opening db '%s': %s", - this->name, + name, e.what() }; throw error { "Failed to open db '%s': %s", - this->name, + name, e.what() }; } @@ -1522,8 +1522,7 @@ catch(const std::exception &e) { log::error { - log, "'%s': Error closing database(%p) :%s", - name, + log, "Error closing database(%p) :%s", this, e.what() }; @@ -1534,8 +1533,7 @@ catch(...) { log::critical { - log, "'%s': Unknown error closing database(%p)", - name, + log, "Unknown error closing database(%p)", this }; @@ -2191,6 +2189,8 @@ noexcept #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsuggest-attribute=format" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wformat-nonliteral" void ircd::db::database::logger::Logv(const rocksdb::InfoLogLevel level_, const char *const fmt, @@ -2225,6 +2225,7 @@ noexcept rog(level, "'%s': %s", d->name, str); } +#pragma clang diagnostic pop #pragma GCC diagnostic pop /////////////////////////////////////////////////////////////////////////////// @@ -3955,6 +3956,7 @@ catch(const std::exception &e) }; ircd::terminate(); + __builtin_unreachable(); } rocksdb::Status diff --git a/ircd/exception.cc b/ircd/exception.cc index 2f81f9013..dc8379f1a 100644 --- a/ircd/exception.cc +++ b/ircd/exception.cc @@ -282,7 +282,12 @@ const noexcept ircd::terminate::terminate() noexcept { - terminate(std::current_exception()); + ircd::terminate + { + std::current_exception() + }; + + __builtin_unreachable(); } ircd::terminate::terminate(const string_view &str) diff --git a/ircd/fs_aio.cc b/ircd/fs_aio.cc index b825cfbde..ed4db37da 100644 --- a/ircd/fs_aio.cc +++ b/ircd/fs_aio.cc @@ -910,6 +910,8 @@ catch(const std::exception &e) qcount, e.what() }}; + + __builtin_unreachable(); } size_t diff --git a/ircd/ios.cc b/ircd/ios.cc index d173843e6..1f904ca53 100644 --- a/ircd/ios.cc +++ b/ircd/ios.cc @@ -106,7 +106,11 @@ ircd::ios::descriptor::default_deallocator(handler &handler, void *const &ptr, const size_t &size) { + #ifdef __clang__ + ::operator delete(ptr); + #else ::operator delete(ptr, size); + #endif } void * diff --git a/ircd/json.cc b/ircd/json.cc index ea90c6dd3..20e834de8 100644 --- a/ircd/json.cc +++ b/ircd/json.cc @@ -3353,14 +3353,14 @@ ircd::json::serialized(const value &v) size_t ircd::json::serialized(const bool &b) { - constexpr const size_t t + static constexpr const size_t t { - strlen("true") + _constexpr_strlen("true") }; - constexpr const size_t f + static constexpr const size_t f { - strlen("false") + _constexpr_strlen("false") }; return b? t : f; diff --git a/ircd/m.cc b/ircd/m.cc index 0047d4cee..85a68ed2c 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -690,6 +690,11 @@ ircd::m::sync::stats_info { "default", false }, }; +template<> +decltype(ircd::m::sync::item::instance_multimap::map) +ircd::m::sync::item::instance_multimap::map +{}; + bool ircd::m::sync::for_each(const item_closure_bool &closure) { @@ -875,11 +880,6 @@ noexcept // item // -template<> -decltype(ircd::m::sync::item::instance_multimap::map) -ircd::m::sync::item::instance_multimap::map -{}; - // // item::item // @@ -4598,6 +4598,32 @@ namespace ircd::m static json::strung _hook_make_feature(const json::members &); } +/// Instance list linkage for all hook sites +template<> +decltype(ircd::util::instance_list::allocator) +ircd::util::instance_list::allocator +{}; + +template<> +decltype(ircd::util::instance_list::list) +ircd::util::instance_list::list +{ + allocator +}; + +/// Instance list linkage for all hooks +template<> +decltype(ircd::util::instance_list::allocator) +ircd::util::instance_list::allocator +{}; + +template<> +decltype(ircd::util::instance_list::list) +ircd::util::instance_list::list +{ + allocator +}; + // // hook::maps // @@ -4757,19 +4783,6 @@ const // hook::base // -/// Instance list linkage for all hooks -template<> -decltype(ircd::util::instance_list::allocator) -ircd::util::instance_list::allocator -{}; - -template<> -decltype(ircd::util::instance_list::list) -ircd::util::instance_list::list -{ - allocator -}; - /// Primary hook ctor ircd::m::hook::base::base(const json::members &members) try @@ -4850,19 +4863,6 @@ catch(const std::out_of_range &e) // hook::site // -/// Instance list linkage for all hook sites -template<> -decltype(ircd::util::instance_list::allocator) -ircd::util::instance_list::allocator -{}; - -template<> -decltype(ircd::util::instance_list::list) -ircd::util::instance_list::list -{ - allocator -}; - // // hook::site::site // diff --git a/ircd/m_event.cc b/ircd/m_event.cc index 072007247..797327cb5 100644 --- a/ircd/m_event.cc +++ b/ircd/m_event.cc @@ -3170,7 +3170,7 @@ bool ircd::m::verify_hash(const event &event, const sha256::buf &hash) { - static const size_t hashb64sz + static constexpr size_t hashb64sz { size_t(hash.size() * 1.34) + 1 }; diff --git a/ircd/mods.cc b/ircd/mods.cc index 9da1bffdc..d9187ed26 100644 --- a/ircd/mods.cc +++ b/ircd/mods.cc @@ -795,7 +795,7 @@ ircd::mods::make_target_name(const string_view &name, }}; ret.shrink_to_fit(); - return ret; + return std::move(ret); } /////////////////////////////////////////////////////////////////////////////// diff --git a/ircd/net.cc b/ircd/net.cc index 2421613b1..48c4f0055 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -356,7 +356,7 @@ size_t ircd::net::discard_all(socket &socket, const size_t &len) { - static char buffer[512] alignas(16); + static char buffer[512]; size_t remain{len}; while(remain) { @@ -380,7 +380,7 @@ size_t ircd::net::discard_any(socket &socket, const size_t &len) { - static char buffer[512] alignas(16); + static char buffer[512]; size_t remain{len}; while(remain) { @@ -3047,7 +3047,7 @@ try case ready::READ: { - static char buf[1] alignas(16); + static char buf[1]; static const ilist bufs{buf}; static ios::descriptor desc { @@ -3112,7 +3112,7 @@ noexcept { assert(type == ready::ERROR); - static char buf[1] alignas(16); + static char buf[1]; static const ilist bufs{buf}; static const std::error_code eof { diff --git a/ircd/openssl.cc b/ircd/openssl.cc index d3f409661..a37872a5a 100644 --- a/ircd/openssl.cc +++ b/ircd/openssl.cc @@ -1658,6 +1658,7 @@ ircd::openssl::init::init() } ircd::openssl::init::~init() +noexcept { ec_fini(); diff --git a/ircd/prof.cc b/ircd/prof.cc index 7195ac5bc..d19742942 100644 --- a/ircd/prof.cc +++ b/ircd/prof.cc @@ -66,6 +66,18 @@ struct ircd::prof::event ~event() noexcept; }; +template<> +decltype(ircd::util::instance_list::allocator) +ircd::util::instance_list::allocator +{}; + +template<> +decltype(ircd::util::instance_list::list) +ircd::util::instance_list::list +{ + allocator +}; + decltype(ircd::prof::enable) ircd::prof::enable { @@ -105,7 +117,7 @@ catch(const std::exception &e) e.what() }; - this->~init(); + system::group.clear(); throw; } @@ -200,7 +212,7 @@ namespace ircd::prof::vg } // -// prof::vg::enable +// prof::vg::enable // ircd::prof::vg::enable::enable() @@ -216,7 +228,7 @@ noexcept } // -// prof::vg::disable +// prof::vg::disable // ircd::prof::vg::disable::disable() @@ -292,7 +304,6 @@ ircd::prof::vg::enabled() // ircd::prof::instructions::instructions() -noexcept { if(!create(this->group, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, true, false)) throw error @@ -642,18 +653,6 @@ noexcept // event // -template<> -decltype(ircd::util::instance_list::allocator) -ircd::util::instance_list::allocator -{}; - -template<> -decltype(ircd::util::instance_list::list) -ircd::util::instance_list::list -{ - allocator -}; - // // event::event //