all: assorted cleanups; introduce undocumented '--sysinfo' option

This commit is contained in:
Markus F.X.J. Oberhumer
2023-10-05 03:51:27 +02:00
parent 7f9d381c7b
commit 632c7c4826
30 changed files with 498 additions and 339 deletions
+40 -17
View File
@@ -28,6 +28,7 @@
#if WITH_XSPAN
// namespace
#if 1
#define XSPAN_NAMESPACE_NAME XSpan
#define XSPAN_NAMESPACE_BEGIN namespace XSPAN_NAMESPACE_NAME {
@@ -51,12 +52,12 @@ noinline void xspan_fail_range_range(void) may_throw;
void xspan_check_range(const void *ptr, const void *base, ptrdiff_t size_in_bytes) may_throw;
// help constructor to distinguish between number of elements and bytes
struct XSpanCount {
explicit forceinline XSpanCount(size_t n) noexcept : count(n) {}
struct XSpanCount final {
explicit forceinline constexpr XSpanCount(size_t n) noexcept : count(n) {}
size_t count; // public
};
struct XSpanSizeInBytes {
explicit forceinline XSpanSizeInBytes(size_t bytes) noexcept : size_in_bytes(bytes) {}
struct XSpanSizeInBytes final {
explicit forceinline constexpr XSpanSizeInBytes(size_t bytes) noexcept : size_in_bytes(bytes) {}
size_t size_in_bytes; // public
};
@@ -117,8 +118,8 @@ struct XSpan_is_convertible : public std::is_convertible<From *, To *> {};
#else
// manual implementation
namespace detail {
// helper for "void"
namespace XSpan_detail {
// XSpan_void_to_T - helper for "void"
template <class T, class U>
struct XSpan_void_to_T {
typedef U type;
@@ -131,19 +132,18 @@ template <class T>
struct XSpan_void_to_T<T, const void> {
typedef T type;
};
// XSpan_ptr_is_convertible
template <class From, class To>
struct XSpan_ptr_is_convertible : public std::false_type {};
template <class T>
struct XSpan_ptr_is_convertible<T, T> : public std::true_type {};
template <class T>
struct XSpan_ptr_is_convertible<T, const T> : public std::true_type {};
} // namespace detail
} // namespace XSpan_detail
template <class From, class To>
struct XSpan_is_convertible
: public detail::XSpan_ptr_is_convertible<From,
typename detail::XSpan_void_to_T<From, To>::type> {};
struct XSpan_is_convertible : public XSpan_detail::XSpan_ptr_is_convertible<
From, typename XSpan_detail::XSpan_void_to_T<From, To>::type> {};
#endif
#if DEBUG
@@ -193,15 +193,38 @@ template <class T>
struct Ptr;
// XSpanInternalDummyArg: some type that is hard to match by accident
class XSpanInternalDummyArgFake; // not implemented on purpose
// (this should result in efficient code and fully get optimized away)
#if 0
// too simple, can be matched by nullptr
class XSpanInternalDummyArgFake; // not implemented on purpose
typedef XSpanInternalDummyArgFake *XSpanInternalDummyArg;
#define XSpanInternalDummyArgInit nullptr
#else
struct XSpanInternalDummyArg {
explicit forceinline XSpanInternalDummyArg(int, XSpanInternalDummyArgFake *) noexcept {}
#elif 1
// use an enum
struct XSpanInternalDummyArg final {
enum DummyEnum {};
explicit forceinline constexpr XSpanInternalDummyArg(DummyEnum &&) noexcept {}
};
#define XSpanInternalDummyArgInit (XSPAN_NS(XSpanInternalDummyArg)(0, nullptr))
#define XSpanInternalDummyArgInit \
(XSPAN_NS(XSpanInternalDummyArg)(XSPAN_NS(XSpanInternalDummyArg)::DummyEnum{}))
#else
// use a class with a private constructor
struct XSpanInternalDummyArg final {
static forceinline constexpr XSpanInternalDummyArg make() noexcept {
return XSpanInternalDummyArg{};
}
private:
explicit forceinline constexpr XSpanInternalDummyArg() noexcept {}
#if !(ACC_CC_MSC) // MSVC wants to use the copy and move constructors; correct or compiler bug?
// @COMPILER_BUG @MSVC_BUG
XSpanInternalDummyArg(const XSpanInternalDummyArg &) = delete;
XSpanInternalDummyArg(XSpanInternalDummyArg &&) noexcept = delete;
XSpanInternalDummyArg &operator=(const XSpanInternalDummyArg &) = delete;
XSpanInternalDummyArg &operator=(XSpanInternalDummyArg &&) noexcept = delete;
#endif
};
#define XSpanInternalDummyArgInit \
(XSPAN_NS(XSpanInternalDummyArg)(XSPAN_NS(XSpanInternalDummyArg)::make()))
#endif
// poison a pointer: point to a non-null invalid address
@@ -209,7 +232,7 @@ struct XSpanInternalDummyArg {
// - this should be efficient (so no mmap() guard page etc.)
// - this should play nice with runtime checkers like ASAN, MSAN, valgrind, etc.
// - this should play nice with static analyzers like clang-tidy etc.
static forceinline void *XSPAN_GET_POISON_VOID_PTR() {
static forceinline void *XSPAN_GET_POISON_VOID_PTR() noexcept {
// return (void *) (upx_uintptr_t) 251; // NOLINT(performance-no-int-to-ptr)
return (void *) 251;
}