1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

fix some warnings

This commit is contained in:
birydrad 2024-09-13 09:54:57 +02:00
parent 1c66852842
commit 71dbb48594
18 changed files with 151 additions and 122 deletions

View file

@ -320,7 +320,7 @@ ton::ValidatorSessionConfig Config::get_consensus_config() const {
c.max_block_size = r.max_block_bytes;
c.max_collated_data_size = r.max_collated_bytes;
};
auto set_v2 = [&] (auto& r) {
auto set_v2 = [&](auto& r) {
set_v1(r);
c.new_catchain_ids = r.new_catchain_ids;
};
@ -1940,7 +1940,7 @@ td::Result<SizeLimitsConfig> Config::get_size_limits_config() const {
td::Result<SizeLimitsConfig> Config::do_get_size_limits_config(td::Ref<vm::CellSlice> cs) {
SizeLimitsConfig limits;
if (cs.is_null()) {
return limits; // default values
return limits; // default values
}
auto unpack_v1 = [&](auto& rec) {
limits.max_msg_bits = rec.max_msg_bits;
@ -2299,17 +2299,14 @@ td::Result<Ref<vm::Tuple>> ConfigInfo::get_prev_blocks_info() const {
if (shard->sgn() < 0) {
shard &= ((td::make_refint(1) << 64) - 1);
}
return vm::make_tuple_ref(
td::make_refint(block_id.id.workchain),
std::move(shard),
td::make_refint(block_id.id.seqno),
td::bits_to_refint(block_id.root_hash.bits(), 256),
td::bits_to_refint(block_id.file_hash.bits(), 256));
return vm::make_tuple_ref(td::make_refint(block_id.id.workchain), std::move(shard),
td::make_refint(block_id.id.seqno), td::bits_to_refint(block_id.root_hash.bits(), 256),
td::bits_to_refint(block_id.file_hash.bits(), 256));
};
std::vector<vm::StackEntry> last_mc_blocks;
last_mc_blocks.push_back(block_id_to_tuple(block_id));
for (ton::BlockSeqno seqno = block_id.id.seqno; seqno > 0 && last_mc_blocks.size() < 16; ) {
for (ton::BlockSeqno seqno = block_id.id.seqno; seqno > 0 && last_mc_blocks.size() < 16;) {
--seqno;
ton::BlockIdExt block_id;
if (!get_old_mc_block_id(seqno, block_id)) {
@ -2323,9 +2320,8 @@ td::Result<Ref<vm::Tuple>> ConfigInfo::get_prev_blocks_info() const {
if (!get_last_key_block(last_key_block, last_key_block_lt)) {
return td::Status::Error("cannot fetch last key block");
}
return vm::make_tuple_ref(
td::make_cnt_ref<std::vector<vm::StackEntry>>(std::move(last_mc_blocks)),
block_id_to_tuple(last_key_block));
return vm::make_tuple_ref(td::make_cnt_ref<std::vector<vm::StackEntry>>(std::move(last_mc_blocks)),
block_id_to_tuple(last_key_block));
}
td::optional<PrecompiledContractsConfig::Contract> PrecompiledContractsConfig::get_contract(

View file

@ -197,6 +197,7 @@ struct McShardHash : public McShardHashI {
: blk_(blk), start_lt_(start_lt), end_lt_(end_lt) {
}
McShardHash(const McShardHash&) = default;
McShardHash& operator=(const McShardHash&) = default;
bool is_valid() const {
return blk_.is_valid();
}
@ -545,7 +546,10 @@ class Config {
};
public:
enum { needValidatorSet = 16, needSpecialSmc = 32, needWorkchainInfo = 256, needCapabilities = 512 };
static constexpr int needValidatorSet = 16;
static constexpr int needSpecialSmc = 32;
static constexpr int needWorkchainInfo = 256;
static constexpr int needCapabilities = 512;
int mode{0};
ton::BlockIdExt block_id;
@ -682,14 +686,12 @@ class Config {
class ConfigInfo : public Config, public ShardConfig {
public:
enum {
needStateRoot = 1,
needLibraries = 2,
needStateExtraRoot = 4,
needShardHashes = 8,
needAccountsRoot = 64,
needPrevBlocks = 128
};
static constexpr int needStateRoot = 1;
static constexpr int needLibraries = 2;
static constexpr int needStateExtraRoot = 4;
static constexpr int needShardHashes = 8;
static constexpr int needAccountsRoot = 64;
static constexpr int needPrevBlocks = 128;
ton::BlockSeqno vert_seqno{~0U};
int global_id_{0};
ton::UnixTime utime{0};

View file

@ -81,7 +81,7 @@ bool CodeBlob::compute_used_code_vars(std::unique_ptr<Op>& ops_ptr, const VarDes
func_assert(ops_ptr->cl == Op::_Nop);
return ops_ptr->set_var_info(var_info);
}
return compute_used_code_vars(ops_ptr->next, var_info, edit) | ops_ptr->compute_used_vars(*this, edit);
return int(compute_used_code_vars(ops_ptr->next, var_info, edit)) | int(ops_ptr->compute_used_vars(*this, edit));
}
bool operator==(const VarDescrList& x, const VarDescrList& y) {
@ -584,7 +584,7 @@ bool prune_unreachable(std::unique_ptr<Op>& ops) {
ops = std::move(op.block1);
return prune_unreachable(ops);
} else {
reach = prune_unreachable(op.block0) | prune_unreachable(op.block1);
reach = int(prune_unreachable(op.block0)) | int(prune_unreachable(op.block1));
}
break;
}
@ -660,7 +660,7 @@ bool prune_unreachable(std::unique_ptr<Op>& ops) {
break;
}
case Op::_TryCatch: {
reach = prune_unreachable(op.block0) | prune_unreachable(op.block1);
reach = int(prune_unreachable(op.block0)) | int(prune_unreachable(op.block1));
break;
}
default:
@ -892,15 +892,15 @@ bool Op::mark_noreturn() {
return set_noreturn(true);
case _If:
case _TryCatch:
return set_noreturn((block0->mark_noreturn() & (block1 && block1->mark_noreturn())) | next->mark_noreturn());
return set_noreturn((int(block0->mark_noreturn()) & int(block1 && block1->mark_noreturn())) | int(next->mark_noreturn()));
case _Again:
block0->mark_noreturn();
return set_noreturn(true);
case _Until:
return set_noreturn(block0->mark_noreturn() | next->mark_noreturn());
return set_noreturn(int(block0->mark_noreturn()) | int(next->mark_noreturn()));
case _While:
block1->mark_noreturn();
return set_noreturn(block0->mark_noreturn() | next->mark_noreturn());
return set_noreturn(int(block0->mark_noreturn()) | int(next->mark_noreturn()));
case _Repeat:
block0->mark_noreturn();
return set_noreturn(next->mark_noreturn());

View file

@ -87,9 +87,23 @@ int get_random_serialization_mode(T &rnd) {
return modes[rnd.fast(0, (int)modes.size() - 1)];
}
class BenchSha256 : public td::Benchmark {
class BenchSha : public td::Benchmark {
public:
explicit BenchSha(size_t n) : str_(n, 'a') {
}
std::string get_description() const override {
return PSTRING() << get_name() << " length=" << str_.size();
}
virtual std::string get_name() const = 0;
protected:
std::string str_;
};
class BenchSha256 : public BenchSha {
public:
using BenchSha::BenchSha;
std::string get_name() const override {
return "SHA256";
}
@ -97,7 +111,7 @@ class BenchSha256 : public td::Benchmark {
int res = 0;
for (int i = 0; i < n; i++) {
digest::SHA256 hasher;
hasher.feed("abcd", 4);
hasher.feed(str_);
unsigned char buf[32];
hasher.extract(buf);
res += buf[0];
@ -105,10 +119,12 @@ class BenchSha256 : public td::Benchmark {
td::do_not_optimize_away(res);
}
};
class BenchSha256Reuse : public td::Benchmark {
class BenchSha256Reuse : public BenchSha {
public:
std::string get_description() const override {
return "SHA256 reuse";
using BenchSha::BenchSha;
std::string get_name() const override {
return "SHA256 reuse (used in DataCell)";
}
void run(int n) override {
@ -116,7 +132,7 @@ class BenchSha256Reuse : public td::Benchmark {
digest::SHA256 hasher;
for (int i = 0; i < n; i++) {
hasher.reset();
hasher.feed("abcd", 4);
hasher.feed(str_);
unsigned char buf[32];
hasher.extract(buf);
res += buf[0];
@ -124,18 +140,28 @@ class BenchSha256Reuse : public td::Benchmark {
td::do_not_optimize_away(res);
}
};
class BenchSha256Low : public td::Benchmark {
class BenchSha256Low : public BenchSha {
public:
std::string get_description() const override {
using BenchSha::BenchSha;
std::string get_name() const override {
return "SHA256 low level";
}
// Use the old method to check for performance degradation
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4996) // Disable deprecated warning for MSVC
#endif
void run(int n) override {
int res = 0;
SHA256_CTX ctx;
for (int i = 0; i < n; i++) {
SHA256_Init(&ctx);
SHA256_Update(&ctx, "abcd", 4);
SHA256_Update(&ctx, str_.data(), str_.size());
unsigned char buf[32];
SHA256_Final(buf, &ctx);
res += buf[0];
@ -143,9 +169,17 @@ class BenchSha256Low : public td::Benchmark {
td::do_not_optimize_away(res);
}
};
class BenchSha256Tdlib : public td::Benchmark {
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
#pragma warning(pop)
#endif
class BenchSha256Tdlib : public BenchSha {
public:
std::string get_description() const override {
using BenchSha::BenchSha;
std::string get_name() const override {
return "SHA256 TDLib";
}
@ -155,7 +189,7 @@ class BenchSha256Tdlib : public td::Benchmark {
for (int i = 0; i < n; i++) {
td::init_thread_local<td::Sha256State>(ctx);
ctx->init();
ctx->feed("abcd");
ctx->feed(str_);
unsigned char buf[32];
ctx->extract(td::MutableSlice(buf, 32), false);
res += buf[0];
@ -180,7 +214,7 @@ void bench_threaded(F &&f) {
void run(int n) override {
std::atomic<int> task_i{0};
int chunk_size = 1024;
size_t num_threads = 1;
int num_threads = 16;
n *= num_threads;
std::vector<td::thread> threads;
for (int i = 0; i < num_threads; i++) {
@ -204,16 +238,20 @@ void bench_threaded(F &&f) {
bench(Threaded(std::forward<F>(f)));
}
TEST(Cell, sha_benchmark) {
bench(BenchSha256Tdlib());
bench(BenchSha256Low());
bench(BenchSha256Reuse());
bench(BenchSha256());
for (size_t n : {4, 64, 128}) {
bench(BenchSha256Tdlib(n));
bench(BenchSha256Low(n));
bench(BenchSha256Reuse(n));
bench(BenchSha256(n));
}
}
TEST(Cell, sha_benchmark_threaded) {
bench_threaded([] { return BenchSha256Tdlib(); });
bench_threaded([]() { return BenchSha256Low(); });
bench_threaded([]() { return BenchSha256Reuse(); });
bench_threaded([]() { return BenchSha256(); });
for (size_t n : {4, 64, 128}) {
bench_threaded([n] { return BenchSha256Tdlib(n); });
bench_threaded([n]() { return BenchSha256Low(n); });
bench_threaded([n]() { return BenchSha256Reuse(n); });
bench_threaded([n]() { return BenchSha256(n); });
}
}
std::string serialize_boc(Ref<Cell> cell, int mode = 31) {
@ -814,12 +852,11 @@ TEST(TonDb, BocMultipleRoots) {
};
TEST(TonDb, InMemoryDynamicBocSimple) {
auto counter = [] {
return td::NamedThreadSafeCounter::get_default().get_counter("DataCell").sum();
};
auto counter = [] { return td::NamedThreadSafeCounter::get_default().get_counter("DataCell").sum(); };
auto before = counter();
SCOPE_EXIT {
LOG_CHECK(before == counter()) << before << " vs " << counter();;
LOG_CHECK(before == counter()) << before << " vs " << counter();
;
};
td::Random::Xorshift128plus rnd{123};
auto kv = std::make_shared<td::MemoryKeyValue>();
@ -854,12 +891,11 @@ TEST(TonDb, InMemoryDynamicBocSimple) {
}
void test_dynamic_boc(std::optional<DynamicBagOfCellsDb::CreateInMemoryOptions> o_in_memory) {
auto counter = [] {
return td::NamedThreadSafeCounter::get_default().get_counter("DataCell").sum();
};
auto counter = [] { return td::NamedThreadSafeCounter::get_default().get_counter("DataCell").sum(); };
auto before = counter();
SCOPE_EXIT {
LOG_CHECK((o_in_memory && o_in_memory->use_arena) || before == counter()) << before << " vs " << counter();;
LOG_CHECK((o_in_memory && o_in_memory->use_arena) || before == counter()) << before << " vs " << counter();
;
};
td::Random::Xorshift128plus rnd{123};
std::string old_root_hash;
@ -870,7 +906,7 @@ void test_dynamic_boc(std::optional<DynamicBagOfCellsDb::CreateInMemoryOptions>
auto res = DynamicBagOfCellsDb::create_in_memory(kv.get(), *o_in_memory);
auto roots_n = old_root_hash.empty() ? 0 : 1;
ASSERT_EQ(roots_n, res->get_stats().ok().roots_total_count);
return std::move(res);
return res;
}
return DynamicBagOfCellsDb::create();
};
@ -945,19 +981,17 @@ void test_dynamic_boc2(std::optional<DynamicBagOfCellsDb::CreateInMemoryOptions>
auto stats = res->get_stats().move_as_ok();
ASSERT_EQ(root_n, stats.roots_total_count);
VLOG(boc) << "reset roots_n=" << stats.roots_total_count << " cells_n=" << stats.cells_total_count;
return std::move(res);
return res;
}
return DynamicBagOfCellsDb::create();
};
auto dboc = create_dboc(0);
dboc->set_loader(std::make_unique<CellLoader>(kv));
auto counter = [] {
return td::NamedThreadSafeCounter::get_default().get_counter("DataCell").sum();
};
auto counter = [] { return td::NamedThreadSafeCounter::get_default().get_counter("DataCell").sum(); };
auto before = counter();
SCOPE_EXIT {
LOG_CHECK((o_in_memory && o_in_memory->use_arena) || before == counter()) << before << " vs " << counter();;
LOG_CHECK((o_in_memory && o_in_memory->use_arena) || before == counter()) << before << " vs " << counter();
};
std::vector<Ref<Cell>> roots(max_roots);
@ -2257,7 +2291,6 @@ TEST(Ref, AtomicRef) {
int threads_n = 10;
std::vector<Node> nodes(threads_n);
std::vector<td::thread> threads(threads_n);
int thread_id = 0;
for (auto &thread : threads) {
thread = td::thread([&] {
for (int i = 0; i < 1000000; i++) {
@ -2272,7 +2305,6 @@ TEST(Ref, AtomicRef) {
}
}
});
thread_id++;
}
for (auto &thread : threads) {
thread.join();

View file

@ -1316,7 +1316,7 @@ void CppTypeCode::clear_context() {
std::string CppTypeCode::new_tmp_var() {
char buffer[16];
while (true) {
sprintf(buffer, "t%d", ++tmp_ints);
snprintf(buffer, sizeof(buffer), "t%d", ++tmp_ints);
if (tmp_cpp_ids.is_good_ident(buffer) && local_cpp_ids.is_good_ident(buffer)) {
break;
}

View file

@ -420,7 +420,7 @@ void AdmissibilityInfo::operator|=(const AdmissibilityInfo& other) {
std::size_t i, j, n = info.size(), n1 = other.info.size();
assert(n1 && !(n1 & (n1 - 1)));
for (i = j = 0; i < n; i++) {
info[i] = info[i] | other.info[j];
info[i] = info[i] || other.info[j];
j = (j + 1) & (n1 - 1);
}
}
@ -2511,7 +2511,7 @@ void define_builtins() {
Bits_type = define_builtin_type("bits", "#", false, 1023, 0, true, 0);
for (int i = 1; i <= 257; i++) {
char buff[8];
sprintf(buff, "uint%d", i);
snprintf(buff, sizeof(buff), "uint%d", i);
define_builtin_type(buff + 1, "", false, i, i, true, -1);
if (i < 257) {
define_builtin_type(buff, "", false, i, i, true, 1);
@ -2519,7 +2519,7 @@ void define_builtins() {
}
for (int i = 1; i <= 1023; i++) {
char buff[12];
sprintf(buff, "bits%d", i);
snprintf(buff, sizeof(buff), "bits%d", i);
define_builtin_type(buff, "", false, i, i, true, 0);
}
Eq_type = define_builtin_type("=", "##", false, 0, 0, true);