diff --git a/deps/oblib/src/lib/container/ob_id_map.h b/deps/oblib/src/lib/container/ob_id_map.h index edaf8de13692f9bb45098821d13db12ef4c1ee5f..07bcf10c5a0c7bb8bbf1bb27f7623302bb4e1d38 100644 --- a/deps/oblib/src/lib/container/ob_id_map.h +++ b/deps/oblib/src/lib/container/ob_id_map.h @@ -79,11 +79,13 @@ private: inline int calc_clz(const uint32_t s) { + OB_ASSERT(0 != s); return __builtin_clz(s); } inline int calc_clz(const uint64_t s) { + OB_ASSERT(0ULL != s); return __builtin_clzl(s); } diff --git a/deps/oblib/src/lib/hash/ob_dchash.h b/deps/oblib/src/lib/hash/ob_dchash.h index ed8a338871decb332c4717883815556354967a56..8abecdc6ec948b0ca1ed8871438723c4d762d76e 100644 --- a/deps/oblib/src/lib/hash/ob_dchash.h +++ b/deps/oblib/src/lib/hash/ob_dchash.h @@ -138,6 +138,7 @@ public: private: static uint64_t calc_shift(uint64_t capacity) { + OB_ASSERT(0ULL != capacity); return __builtin_clzll(capacity) + 1; } HashNode* locate(uint64_t hash) diff --git a/deps/oblib/src/lib/queue/ob_lighty_queue.h b/deps/oblib/src/lib/queue/ob_lighty_queue.h index 540160ae6edfc9efbc37f5a2db78912417bc9892..2bb646c2693f5668d91fc92aecd4d92044c9175b 100644 --- a/deps/oblib/src/lib/queue/ob_lighty_queue.h +++ b/deps/oblib/src/lib/queue/ob_lighty_queue.h @@ -163,6 +163,7 @@ public: private: static uint64_t calc_n_cond(uint64_t capacity) { + OB_ASSERT(0ULL != capacity); return std::min(1024ULL, 1ULL << (63 - __builtin_clzll(capacity))); } uint64_t push_bounded(void* p, uint64_t limit) diff --git a/deps/oblib/src/lib/utility/utility.h b/deps/oblib/src/lib/utility/utility.h index 77a7033484f0ee8a0f3edb9d599ce2d89b9a9e66..0ecacaa90f84513e6057fcf88679373df8e701f8 100644 --- a/deps/oblib/src/lib/utility/utility.h +++ b/deps/oblib/src/lib/utility/utility.h @@ -71,7 +71,7 @@ int32_t parse_string_to_int_array(const char* line, const char del, int32_t* arr bool is2n(int64_t input); constexpr int64_t next_pow2(const int64_t x) { - return x ? (1ULL << (8 * sizeof(int64_t) - __builtin_clzll(x - 1))) : 1; + return x > 1LL ? (1ULL << (8 * sizeof(int64_t) - __builtin_clzll(x - 1))) : 1LL; } bool all_zero(const char* buffer, const int64_t size); diff --git a/src/sql/engine/expr/ob_expr_estimate_ndv.cpp b/src/sql/engine/expr/ob_expr_estimate_ndv.cpp index f2469028fa6b38f0fc7079f804eef9d9fee07efa..dd63b2e8ceb0b73fd6b00b1a5b2c86259ad9592a 100644 --- a/src/sql/engine/expr/ob_expr_estimate_ndv.cpp +++ b/src/sql/engine/expr/ob_expr_estimate_ndv.cpp @@ -80,6 +80,7 @@ void ObExprEstimateNdv::llc_estimate_ndv(int64_t& result, const ObString& bitmap } uint64_t ObExprEstimateNdv::llc_leading_zeros(uint64_t value, uint64_t bit_width) { + OB_ASSERT(0ULL != value); return std::min(bit_width, static_cast(__builtin_clzll(value))); } diff --git a/src/sql/engine/expr/ob_expr_res_type_map.h b/src/sql/engine/expr/ob_expr_res_type_map.h index 3b855996278b23b6a4b57e348d8da75d77951503..5530b5940268bb3331344e63ab3d15e21c9864df 100644 --- a/src/sql/engine/expr/ob_expr_res_type_map.h +++ b/src/sql/engine/expr/ob_expr_res_type_map.h @@ -126,8 +126,9 @@ public: typedef bool (*is_type_func)(common::ObObjType type); - static constexpr int flag2bit(uint64_t flag) + static int flag2bit(uint64_t flag) { + OB_ASSERT(0ULL != flag); return static_cast(__builtin_ctzll(flag)); } diff --git a/src/sql/engine/join/ob_hash_join_op.cpp b/src/sql/engine/join/ob_hash_join_op.cpp index 28af3f0522457189b8db3dc6c2041bb7afbb9029..d0b5d6683bba40f34c7ac1ce98a389a7a6533446 100644 --- a/src/sql/engine/join/ob_hash_join_op.cpp +++ b/src/sql/engine/join/ob_hash_join_op.cpp @@ -1561,12 +1561,14 @@ void ObHashJoinOp::calc_cache_aware_partition_count() int64_t tmp_partition_cnt_per_level = max_partition_count_per_level_; if (total_partition_cnt > tmp_partition_cnt_per_level) { level1_part_count_ = part_count_; + OB_ASSERT(0 != level1_part_count_); level1_bit_ = __builtin_ctz(level1_part_count_); level2_part_count_ = total_partition_cnt / level1_part_count_; level2_part_count_ = level2_part_count_ > tmp_partition_cnt_per_level ? tmp_partition_cnt_per_level : level2_part_count_; } else { level1_part_count_ = total_partition_cnt > part_count_ ? total_partition_cnt : part_count_; + OB_ASSERT(0 != level1_part_count_); level1_bit_ = __builtin_ctz(level1_part_count_); } LOG_TRACE("partition count", @@ -2755,6 +2757,7 @@ int ObHashJoinOp::get_next_probe_partition() } } else { // two level + OB_ASSERT(0 != level2_part_count_); int64_t level1_part_idx = (cur_full_right_partition_ >> (__builtin_ctz(level2_part_count_))); if (level1_part_idx < dump_part_count) { cur_left_hist_ = &part_histograms_[cur_full_right_partition_]; diff --git a/src/sql/engine/join/ob_hash_join_op.h b/src/sql/engine/join/ob_hash_join_op.h index e4ae5fa5865d8233e2c8a686e3beb6f1791dfe46..8566fbb17ae554c6b4463c899a8d7ed21745bdbb 100644 --- a/src/sql/engine/join/ob_hash_join_op.h +++ b/src/sql/engine/join/ob_hash_join_op.h @@ -307,6 +307,8 @@ private: void set_part_count(int64_t part_shift, int64_t level1_part_count, int64_t level2_part_count) { + OB_ASSERT(0 != level1_part_count); + OB_ASSERT(0 != level2_part_count); part_shift_ = part_shift; level_one_part_count_ = level1_part_count; level_two_part_count_ = level2_part_count; diff --git a/src/storage/ob_handle_cache.h b/src/storage/ob_handle_cache.h index f461f14c3cf41546a9c8af61058a208ef5c97c6d..09f8858a171b79e5e5f173d07de99cd968d89748 100644 --- a/src/storage/ob_handle_cache.h +++ b/src/storage/ob_handle_cache.h @@ -19,11 +19,6 @@ namespace oceanbase { namespace storage { -constexpr int64_t next_pow2(const int64_t x) -{ - return x ? (1ULL << (8 * sizeof(int64_t) - __builtin_clzll(x - 1))) : 1; -} - template class ObHandleCacheNode : public common::ObDLinkBase> { public: @@ -125,7 +120,7 @@ public: } private: - static const uint64_t BUCKET_SIZE = next_pow2(N * 2); + static const uint64_t BUCKET_SIZE = common::next_pow2(N * 2); static const uint64_t MASK = BUCKET_SIZE - 1; CacheNode nodes_[N]; int16_t buckets_[BUCKET_SIZE];