diff --git a/.clang-tidy b/.clang-tidy index f3cc68f..209ab7c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -40,7 +40,9 @@ misc-throw-by-value-catch-by-reference, google-global-names-in-headers, llvm-header-guard, misc-definitions-in-headers, -readability-container-size-empty' +readability-container-size-empty +clang-analyzer-core.NonNullParamChecker +' WarningsAsErrors: '*' AnalyzeTemporaryDtors: false diff --git a/include/fls/common/assert.hpp b/include/fls/common/assert.hpp index 142d996..802edba 100644 --- a/include/fls/common/assert.hpp +++ b/include/fls/common/assert.hpp @@ -4,8 +4,10 @@ #ifdef NDEBUG #define FLS_ASSERT(...) ; #define DETAILED_FLS_ASSERT(...) ; +#define FLS_ASSERT_POINTER(...) ; #else +#define FLS_ASSERT_POINTER(p) fastlanes::Assert::NotNullPointer(p) #define FLS_ASSERT(Expr, Val, Msg) fastlanes::FlsAssert(#Expr, Val, Expr, __FILE__, __LINE__, Msg) #define DETAILED_FLS_ASSERT(Expr, Val, Msg) fastlanes::DetailedFlsAssert(#Expr, Val, Expr, __FILE__, __LINE__, Msg) #endif @@ -13,19 +15,19 @@ #define FLS_ASSERT_EXPR(Expr) DETAILED_FLS_ASSERT(Expr, " ", #Expr); #define FLS_ASSERT_TRUE(Expr) FLS_ASSERT(Expr, " ", #Expr); #define FLS_ASSERT_FALSE(EXPR) FLS_ASSERT(!(EXPR), " ", #EXPR); -#define FLS_ASSERT_NOT_NULL_POINTER(Expr) FLS_ASSERT(Expr != nullptr, " ", fastlanes::assert::NULL_POINTER); +#define FLS_ASSERT_NOT_NULL_POINTER(pointer) FLS_ASSERT_POINTER(pointer); #define FLS_ASSERT_NULL_POINTER(Expr) FLS_ASSERT(Expr == nullptr, " ", ""); -#define FLS_ASSERT_CORRECT_MIN_MAX(Min, Max) FLS_ASSERT(Max >= Min, " ", fastlanes::assert::NULL_POINTER); -#define FLS_ASSERT_CORRECT_RANGE(Range) FLS_ASSERT(Range >= 0, " ", fastlanes::assert::CORRECT_BW); -#define FLS_ASSERT_CORRECT_BW(Bw) DETAILED_FLS_ASSERT(Bw >= 0 && Bw <= 64, #Bw, fastlanes::assert::NULL_POINTER); -#define FLS_ASSERT_NOT_ZERO(Expr) FLS_ASSERT(Expr != 0, " ", fastlanes::assert::ZERO); -#define FLS_ASSERT_ZERO(Expr) FLS_ASSERT(Expr == 0, " ", fastlanes::assert::NOT_ZERO); -#define FLS_ASSERT_CORRECT_SZ(Expr) FLS_ASSERT(Expr >= 0, " ", fastlanes::assert::NEGATIVE_SZ); -#define FLS_ASSERT_CORRECT_BSZ(Expr) FLS_ASSERT(Expr >= 0, " ", fastlanes::assert::NEGATIVE_SZ); -#define FLS_ASSERT_CORRECT_EXP_T(EXP_T) FLS_ASSERT(EXP_T != 0, #EXP_T, fastlanes::assert::CORRECT_EXP_T_MSG); -#define FLS_ASSERT_CORRECT_N(Expr) FLS_ASSERT(Expr >= 0, " ", fastlanes::assert::NEGATIVE_INDEX); -#define FLS_ASSERT_CORRECT_LMTED_C(C, LMT) FLS_ASSERT(C >= 0 && C = < LMT, " ", fastlanes::assert::NEGATIVE_INDEX); -#define FLS_ASSERT_CORRECT_POS(POS) FLS_ASSERT(POS >= 0 && POS <= 1023, " ", fastlanes::assert::NEGATIVE_INDEX); +#define FLS_ASSERT_CORRECT_MIN_MAX(Min, Max) FLS_ASSERT(Max >= Min, " ", fastlanes::Assert::NULL_POINTER); +#define FLS_ASSERT_CORRECT_RANGE(Range) FLS_ASSERT(Range >= 0, " ", fastlanes::Assert::CORRECT_BW); +#define FLS_ASSERT_CORRECT_BW(Bw) DETAILED_FLS_ASSERT(Bw >= 0 && Bw <= 64, #Bw, fastlanes::Assert::NULL_POINTER); +#define FLS_ASSERT_NOT_ZERO(Expr) FLS_ASSERT(Expr != 0, " ", fastlanes::Assert::ZERO); +#define FLS_ASSERT_ZERO(Expr) FLS_ASSERT(Expr == 0, " ", fastlanes::Assert::NOT_ZERO); +#define FLS_ASSERT_CORRECT_SZ(Expr) FLS_ASSERT(Expr >= 0, " ", fastlanes::Assert::NEGATIVE_SZ); +#define FLS_ASSERT_CORRECT_BSZ(Expr) FLS_ASSERT(Expr >= 0, " ", fastlanes::Assert::NEGATIVE_SZ); +#define FLS_ASSERT_CORRECT_EXP_T(EXP_T) FLS_ASSERT(EXP_T != 0, #EXP_T, fastlanes::Assert::CORRECT_EXP_T_MSG); +#define FLS_ASSERT_CORRECT_N(Expr) FLS_ASSERT(Expr >= 0, " ", fastlanes::Assert::NEGATIVE_INDEX); +#define FLS_ASSERT_CORRECT_LMTED_C(C, LMT) FLS_ASSERT(C >= 0 && C = < LMT, " ", fastlanes::Assert::NEGATIVE_INDEX); +#define FLS_ASSERT_CORRECT_POS(POS) FLS_ASSERT(POS >= 0 && POS <= 1023, " ", fastlanes::Assert::NEGATIVE_INDEX); #define FLS_ASSERT_CORRECT_SEGMENT_SIZE(Expr) FLS_ASSERT(Expr >= 8, " ", ""); #define FLS_ASSERT_EQUALITY(L_Expr, R_Expr) FLS_ASSERT(L_Expr == R_Expr, " ", " "); #define FLS_ASSERT_LESS(L_Expr, R_Expr) FLS_ASSERT(L_Expr <= R_Expr, " ", " "); @@ -34,22 +36,26 @@ #define FLS_ASSERT_L(L_VAL, R_VAL) FLS_ASSERT(L_VAL < R_VAL, " ", " "); #define FLS_ASSERT_LE(L_VAL, R_VAL) FLS_ASSERT(L_VAL <= R_VAL, " ", " "); #define FLS_ASSERT_CORRECT_NUM(NUM, C) FLS_ASSERT(NUM <= C, " ", " "); -#define FLS_ABORT(MSG) FLS_ASSERT(false, MSG, fastlanes::assert::ABORT); -#define FLS_ASSERT_CORRECT_BASE_UB(BASE, UB) FLS_ASSERT(BASE <= UB, " ", fastlanes::assert::BASE_UB); -#define FLS_ASSERT_CORRECT_BASE_LB(BASE, LB) FLS_ASSERT(BASE >= LB, " ", fastlanes::assert::BASE_LB); -#define FLS_ASSERT_CORRECT_OFFSET(Offset) FLS_ASSERT(Offset >= 0, " ", fastlanes::assert::OFFSET); -#define FLS_ASSERT_CORRECT_SMART_OFFSET(OFFSET) FLS_ASSERT(OFFSET >= 0, " ", fastlanes::assert::SMART_OFFSET); -#define FLS_ASSERT_CORRECT_EXC_C(C) FLS_ASSERT(C <= 1024 && C >= 0, " ", fastlanes::assert::ZERO); +#define FLS_ABORT(MSG) FLS_ASSERT(false, MSG, fastlanes::Assert::ABORT); +#define FLS_ASSERT_CORRECT_BASE_UB(BASE, UB) FLS_ASSERT(BASE <= UB, " ", fastlanes::Assert::BASE_UB); +#define FLS_ASSERT_CORRECT_BASE_LB(BASE, LB) FLS_ASSERT(BASE >= LB, " ", fastlanes::Assert::BASE_LB); +#define FLS_ASSERT_CORRECT_OFFSET(Offset) FLS_ASSERT(Offset >= 0, " ", fastlanes::Assert::OFFSET); +#define FLS_ASSERT_CORRECT_SMART_OFFSET(OFFSET) FLS_ASSERT(OFFSET >= 0, " ", fastlanes::Assert::SMART_OFFSET); +#define FLS_ASSERT_CORRECT_EXC_C(C) FLS_ASSERT(C <= 1024 && C >= 0, " ", fastlanes::Assert::ZERO); #define FLS_ASSERT_NOT_EMPTY_STR(STR) FLS_ASSERT(STR.size() > 0, " ", " "); #define FLS_ASSERT_E(L_VAL, R_VAL) FLS_ASSERT(L_VAL == R_VAL, " ", " "); -#define FLS_ASSERT_CORRECT_IDX(Expr) FLS_ASSERT(Expr >= 0, " ", fastlanes::assert::IDX); -#define FLS_ASSERT_NOT_EMPTY_VEC(VEC) FLS_ASSERT(!VEC.empty(), " ", fastlanes::assert::EMPTY_VECTOR); +#define FLS_ASSERT_CORRECT_IDX(Expr) FLS_ASSERT(Expr >= 0, " ", fastlanes::Assert::IDX); +#define FLS_ASSERT_NOT_EMPTY_VEC(VEC) FLS_ASSERT(!VEC.empty(), " ", fastlanes::Assert::EMPTY_VECTOR); +#include "alias.hpp" namespace fastlanes { void FlsAssert(const char* expr_str, const char* str, bool expr, const char* file, int line, const char* msg); void DetailedFlsAssert(const char* expr_str, const char* str, bool expr, const char* file, int line, const char* msg); -class assert { +class Assert { +public: + static void NotNullPointer(const void* p); + public: static constexpr auto CORRECT_EXP_T_MSG = "Exp is invalid."; static constexpr auto ABORT = "ABORTED."; diff --git a/include/fls/encoder/assert_eq.hpp b/include/fls/encoder/assert_eq.hpp index 41fb951..1dd9fba 100644 --- a/include/fls/encoder/assert_eq.hpp +++ b/include/fls/encoder/assert_eq.hpp @@ -168,7 +168,7 @@ void assert_eq(Vec* vec, const PT* data_p, idx_t start_idx, ExpT exp) { auto* str_p = vec->buf_arr[vec->arr_c + 0].mutable_data(); auto* off_arr = vec->buf_arr[vec->arr_c + 1].mutable_data(); - FLS_ASSERT_NOT_NULL_POINTER(vec->fsst_decoder_up) + FLS_ASSERT_NOT_NULL_POINTER(vec->fsst_decoder_up.get()) uint32_t untransposed[1024] = {0}; untranspose_i(off_arr, untransposed); @@ -213,7 +213,7 @@ void assert_eq(Vec* vec, const PT* data_p, idx_t start_idx, ExpT exp) { auto* str_p = vec->buf_arr[vec->arr_c + 0].mutable_data(); auto* off_arr = vec->buf_arr[vec->arr_c + 1].mutable_data(); - FLS_ASSERT_NOT_NULL_POINTER(vec->fsst12_decoder_up) + FLS_ASSERT_NOT_NULL_POINTER(vec->fsst12_decoder_up.get()) uint32_t untransposed[1024] = {0}; untranspose_i(off_arr, untransposed); diff --git a/src/common/assert.cpp b/src/common/assert.cpp index 0528c97..386ad02 100644 --- a/src/common/assert.cpp +++ b/src/common/assert.cpp @@ -1,4 +1,5 @@ #include "fls/common/assert.hpp" +#include #include // for abort #include // for operator<<, char_traits, basic_ostream, cerr @@ -11,7 +12,6 @@ void FlsAssert(const char* expr_str, const char* str, bool expr, const char* fil << "Values:\t\t" << str << "\n" << file << ":" << line << "\n"; abort(); - throw std::runtime_error("aborted"); } void DetailedFlsAssert(const char* expr_str, const char* str, bool expr, const char* file, int line, const char* msg) { @@ -23,4 +23,6 @@ void DetailedFlsAssert(const char* expr_str, const char* str, bool expr, const c << file << ":" << line << "\n"; abort(); } + +void Assert::NotNullPointer(const void* p) { assert(p != nullptr && "Pointer must not be null"); } } // namespace fastlanes diff --git a/src/cor/eng/engine.cpp b/src/cor/eng/engine.cpp index 064a7d0..dbdfb04 100644 --- a/src/cor/eng/engine.cpp +++ b/src/cor/eng/engine.cpp @@ -27,14 +27,14 @@ void Engine::Compress(Vec& src_vec, EngineState& eng_state) { template void Engine::Decompress(Vec& des) { - FLS_ASSERT_NOT_NULL_POINTER(m_decompressor_up) + FLS_ASSERT_NOT_NULL_POINTER(m_decompressor_up.get()) m_decompressor_up->Decompress(des); } template Vec* Engine::Decompress(DecompressState& stt) { - FLS_ASSERT_NOT_NULL_POINTER(m_decompressor_up) + FLS_ASSERT_NOT_NULL_POINTER(m_decompressor_up.get()) return m_decompressor_up->Decompress(stt); } diff --git a/src/cor/eng/executor.cpp b/src/cor/eng/executor.cpp index a680ecc..48fbd64 100644 --- a/src/cor/eng/executor.cpp +++ b/src/cor/eng/executor.cpp @@ -12,7 +12,7 @@ void Exe::Execute(Vec& src_vec, Vec& des_vec, CompressState& compress_state) compress_state.cur_des_buff = 0; for (size_t i = 0; i < rpn_p->prm_c; ++i) { - FLS_ASSERT_NOT_NULL_POINTER(cmpr_fun_arr[i]) + // FLS_ASSERT_NOT_NULL_POINTER(cmpr_fun_arr[i]) //fixme cmpr_fun_arr[i](src_vec, des_vec, compress_state); } @@ -26,7 +26,7 @@ void Exe::ResCmpr(sp> exp) { for (size_t i = 0; i < rpn_p->prm_c; ++i) { cmpr_fun_arr[i] = resolver::resolve_cmpr(rpn_p->prm_arr[i], rpn_p->typ_arr[i], exp); - FLS_ASSERT_NOT_NULL_POINTER(cmpr_fun_arr[i]) + // FLS_ASSERT_NOT_NULL_POINTER(cmpr_fun_arr[i]) //fixme } } @@ -36,7 +36,7 @@ void Exe::ResDecmpr(sp> exp) { for (size_t i = 0; i < rpn_p->prm_c; ++i) { de_cmpr_fun_arr[i] = resolver::resolve_de_cmpr(rpn_p->prm_arr[i], rpn_p->typ_arr[i], exp); - FLS_ASSERT_NOT_NULL_POINTER(de_cmpr_fun_arr[i]) + // FLS_ASSERT_NOT_NULL_POINTER(de_cmpr_fun_arr[i]) } } @@ -46,7 +46,7 @@ void Exe::Execute(PageParam pg_params, VecParam vec_params, DecompressState& stt.cur_des_arr = rpn_p->des_buf_c - 1; for (size_t i = rpn_p->prm_c; i > 0; --i) { - FLS_ASSERT_NOT_NULL_POINTER(de_cmpr_fun_arr[i - 1]) + // FLS_ASSERT_NOT_NULL_POINTER(de_cmpr_fun_arr[i - 1]) de_cmpr_fun_arr[i - 1](pg_params, vec_params, stt); } diff --git a/src/cor/exp/hdr.cpp b/src/cor/exp/hdr.cpp index 676c16b..36529bb 100644 --- a/src/cor/exp/hdr.cpp +++ b/src/cor/exp/hdr.cpp @@ -1,8 +1,8 @@ #include "fls/cor/exp/hdr.hpp" #include "fls/common/assert.hpp" // for FLS_ASSERT -#include // for byte -#include // for string -#include // for basic_string +#include +#include // for byte +#include // for basic_string namespace fastlanes::exp { std::string Hdr::ToString() const { @@ -16,12 +16,11 @@ std::string& Hdr::operator<<(std::string& lhs) { } Hdr Hdr::Load(std::byte* p) { - FLS_ASSERT(p != nullptr, "", ""); - + FLS_ASSERT_NOT_NULL_POINTER(p); return *(reinterpret_cast(p)); } Hdr Hdr::Load(uint8_t* p) { - FLS_ASSERT(p != nullptr, " ", " "); + FLS_ASSERT_NOT_NULL_POINTER(p); return *(reinterpret_cast(p)); }