diff --git a/.bazelrc b/.bazelrc index b5b20e0..16418e5 100644 --- a/.bazelrc +++ b/.bazelrc @@ -7,3 +7,6 @@ build --experimental_cc_shared_library # Remove error output limit build --experimental_ui_max_stdouterr_bytes=-1 + +# Do not strip symbols +build --strip=never diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 06e0c7a..35ed6e5 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -103,7 +103,7 @@ }, "@@ewdk_cc_toolchain~//:ewdk_extension.bzl%toolchains": { "general": { - "bzlTransitiveDigest": "o8jWc/DKL6u/xdGVR7ZVOsdvrJWHczkHwS5vnpdr1b8=", + "bzlTransitiveDigest": "9JDci1UBSQRcNgV8CaGaG7lk1+ZmfO4FF//420jL10w=", "usagesDigest": "KWfyUyVJ/UQYtoURvUEdG5qx0XigX4CN/NfpTe9J3Ns=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, diff --git a/default_copts.bzl b/default_copts.bzl index ac9760d..b1b2525 100644 --- a/default_copts.bzl +++ b/default_copts.bzl @@ -18,7 +18,18 @@ RAD_CPP20 = select({ "//:clang": ["-std=c++20"], }) -RAD_GCC_OPTS = [ +RAD_ASAN_COPTS = [ + "-fsanitize=address", + "-DADDRESS_SANITIZER", + "-g", + "-fno-omit-frame-pointer", +] + +RAD_ASAN_LINKOPTS = [ + "-fsanitize=address", +] + +RAD_GCC_COPTS = [ "-Wall", "-Wextra", "-Wcast-qual", @@ -37,6 +48,8 @@ RAD_GCC_OPTS = [ "-Wpedantic", ] +RAD_GCC_LINKOPTS = [] + RAD_DEFAULT_COPTS = select({ "//:msvc": [ "/W4", @@ -44,6 +57,12 @@ RAD_DEFAULT_COPTS = select({ "/DNOMINMAX", "/Zc:__cplusplus", ], - "//:gcc": RAD_GCC_OPTS, - "//:clang": RAD_GCC_OPTS, + "//:gcc": RAD_GCC_COPTS + RAD_ASAN_COPTS, + "//:clang": RAD_GCC_COPTS, +}) + +RAD_DEFAULT_LINKOPTS = select({ + "//:msvc": [], + "//:gcc": RAD_GCC_LINKOPTS + RAD_ASAN_LINKOPTS, + "//:clang": RAD_GCC_LINKOPTS, }) diff --git a/radiant/Result.h b/radiant/Result.h index 5bf59ee..5e9fdb9 100644 --- a/radiant/Result.h +++ b/radiant/Result.h @@ -23,6 +23,15 @@ #include #endif +// +// Result is effectively a type-safe union and GCC gets confused about the union +// being "maybe" uninitialized. +// +#if !RAD_DBG && defined(RAD_GCC_VERSION) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + namespace rad { @@ -82,10 +91,6 @@ struct ResultStorage constexpr ResultStorage() noexcept : m_state(ResultState::Empty) -#if !RAD_CPP17 - , - m_default(false) -#endif { } @@ -150,7 +155,6 @@ struct ResultStorage { OkWrap m_ok; ErrWrap m_err; - bool m_default; }; }; @@ -174,10 +178,6 @@ struct ResultStorage constexpr ResultStorage() noexcept : m_state(ResultState::Empty) -#if !RAD_CPP17 - , - m_default(false) -#endif { } @@ -255,7 +255,6 @@ struct ResultStorage { OkWrap m_ok; ErrWrap m_err; - bool m_default; }; }; @@ -1262,3 +1261,7 @@ constexpr inline EnIf, Decay>, bool> operator!=( } } // namespace rad + +#if !RAD_DBG && defined(RAD_GCC_VERSION) +#pragma GCC diagnostic pop +#endif diff --git a/radiant/detail/VectorOperations.h b/radiant/detail/VectorOperations.h index d5285f3..f86f83a 100644 --- a/radiant/detail/VectorOperations.h +++ b/radiant/detail/VectorOperations.h @@ -32,6 +32,8 @@ namespace detail template struct VectorAlloc { +public: + ~VectorAlloc() { if (buffer) @@ -42,10 +44,10 @@ struct VectorAlloc } explicit VectorAlloc(TAllocator& alloc) noexcept - : allocator(alloc), - buffer(nullptr), + : buffer(nullptr), size(0), - capacity(0) + capacity(0), + allocator(alloc) { } @@ -53,6 +55,8 @@ struct VectorAlloc bool Alloc(uint32_t count) { + RAD_ASSERT(buffer == nullptr); + buffer = allocator.Alloc(count); if (!buffer) { @@ -73,10 +77,13 @@ struct VectorAlloc return tmp; } - TAllocator& allocator; T* buffer; uint32_t size; uint32_t capacity; + +private: + + TAllocator& allocator; }; template @@ -401,8 +408,7 @@ struct VectorStorage } VectorAlloc vec(alloc); - vec.buffer = vec.allocator.Alloc(m_size); - if (!vec.buffer) + if (!vec.Alloc(m_size)) { return Error::NoMemory; } @@ -523,8 +529,7 @@ struct VectorStorage else { VectorAlloc vec(alloc); - vec.buffer = vec.allocator.Alloc(m_size); - if (!vec.buffer) + if (!vec.Alloc(m_size)) { return Error::NoMemory; } @@ -866,6 +871,8 @@ struct VectorOperations : public VectorStorage } else { + Free(alloc); + m_data = vec.Release(); m_capacity = count; } @@ -895,8 +902,7 @@ struct VectorOperations : public VectorStorage else { VectorAlloc vec(alloc); - vec.buffer = vec.allocator.Alloc(count); - if (!vec.buffer) + if (!vec.Alloc(count)) { return Error::NoMemory; } @@ -904,6 +910,8 @@ struct VectorOperations : public VectorStorage ManipType().CopyCtor(vec.buffer, count, value); ManipType().DtorRange(Data(), Data() + m_size); + Free(alloc); + m_data = vec.Release(); m_capacity = count; } @@ -942,6 +950,8 @@ struct VectorOperations : public VectorStorage } else { + Free(alloc); + m_data = vec.Release(); m_capacity = span.Size(); } diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 30d924e..4d6c39e 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -1,4 +1,4 @@ -load("//:default_copts.bzl", "RAD_CPP14", "RAD_CPP17", "RAD_CPP20", "RAD_DEFAULT_COPTS") +load("//:default_copts.bzl", "RAD_CPP14", "RAD_CPP17", "RAD_CPP20", "RAD_DEFAULT_COPTS", "RAD_DEFAULT_LINKOPTS") filegroup( name = "test_srcs", @@ -22,6 +22,7 @@ cc_test( size = TEST_SIZE, srcs = TEST_SRCS, copts = RAD_CPP14 + RAD_DEFAULT_COPTS, + linkopts = RAD_DEFAULT_LINKOPTS, deps = TEST_DEPS, ) @@ -30,6 +31,7 @@ cc_test( size = TEST_SIZE, srcs = TEST_SRCS, copts = RAD_CPP17 + RAD_DEFAULT_COPTS, + linkopts = RAD_DEFAULT_LINKOPTS, deps = TEST_DEPS, ) @@ -38,5 +40,6 @@ cc_test( size = TEST_SIZE, srcs = TEST_SRCS, copts = RAD_CPP20 + RAD_DEFAULT_COPTS, + linkopts = RAD_DEFAULT_LINKOPTS, deps = TEST_DEPS, ) diff --git a/test/test_Result.cpp b/test/test_Result.cpp index 6774a69..d4cc201 100644 --- a/test/test_Result.cpp +++ b/test/test_Result.cpp @@ -29,6 +29,11 @@ #include #include +#if !RAD_DBG && defined(RAD_GCC_VERSION) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + namespace testnoexcept { @@ -3188,3 +3193,7 @@ TEST(ResultTests, CompareRes) EXPECT_FALSE(value != rad::ResultErr(MYSTATUS_UNSUCCESSFUL)); EXPECT_FALSE(rad::ResultErr(MYSTATUS_UNSUCCESSFUL) != value); } + +#if !RAD_DBG && defined(RAD_GCC_VERSION) +#pragma GCC diagnostic pop +#endif