From ce8f264352d4d647efe0f71a67e2fe85aec2d0f5 Mon Sep 17 00:00:00 2001 From: Nazarov Konstantin Date: Tue, 22 Mar 2022 13:00:16 +0300 Subject: [PATCH] fix opensource issues related to codestyle Signed-off-by: Nazarov Konstantin --- assembler/assembly-ins.cpp | 2 +- assembler/lexer.cpp | 7 +--- assembler/tests/emitter_test.cpp | 6 +-- assembler/tests/lexer_test.cpp | 2 +- runtime/mem/refstorage/ref_block.cpp | 23 ++++++----- runtime/tests/class_linker_test.cpp | 2 +- runtime/tests/debugger_test.cpp | 4 +- runtime/thread_manager.cpp | 22 +++++------ verification/absint/abs_int_inl.h | 2 - verification/absint/exec_context.h | 36 ++++++++++------- .../debug/handlers/config_handler_options.cpp | 20 ++++++---- verification/util/addr_map.h | 13 ++++--- verification/verifier/verifier.cpp | 39 +++++++++++-------- 13 files changed, 98 insertions(+), 80 deletions(-) diff --git a/assembler/assembly-ins.cpp b/assembler/assembly-ins.cpp index 8232941..6b2035c 100644 --- a/assembler/assembly-ins.cpp +++ b/assembler/assembly-ins.cpp @@ -98,4 +98,4 @@ std::string panda::pandasm::Ins::OperandsToString(PrintKind print_kind, bool pri return ss.str(); } -} // namespace panda::pandasm \ No newline at end of file +} // namespace panda::pandasm diff --git a/assembler/lexer.cpp b/assembler/lexer.cpp index cb8e4fd..4c0806c 100644 --- a/assembler/lexer.cpp +++ b/assembler/lexer.cpp @@ -340,12 +340,9 @@ void Lexer::LexPreprocess() << std::string_view(&*(curr_line_->buffer.begin() + curr_line_->pos), curr_line_->end - curr_line_->pos); - size_t cmt_pos; - bool inside_str_lit; - // Searching for comment marker located outside of the string literals. - inside_str_lit = curr_line_->buffer.size() > 0 && curr_line_->buffer[0] == '\"'; - cmt_pos = curr_line_->buffer.find_first_of("\"#", 0); + bool inside_str_lit = curr_line_->buffer.size() > 0 && curr_line_->buffer[0] == '\"'; + size_t cmt_pos = curr_line_->buffer.find_first_of("\"#", 0); if (cmt_pos != std::string::npos) { do { if (cmt_pos != 0 && curr_line_->buffer[cmt_pos - 1] != '\\' && curr_line_->buffer[cmt_pos] == '\"') { diff --git a/assembler/tests/emitter_test.cpp b/assembler/tests/emitter_test.cpp index 471070a..98e9435 100644 --- a/assembler/tests/emitter_test.cpp +++ b/assembler/tests/emitter_test.cpp @@ -238,11 +238,11 @@ TEST(emittertests, debuginfo) EXPECT_THAT(opcodes, ::testing::ElementsAreArray(program, opcodes.size())); - size_t size; - bool is_full; + size_t size {}; + bool is_full {}; size_t constant_pool_offset = 0; - uint32_t offset; + uint32_t offset {}; std::tie(offset, size, is_full) = leb128::DecodeUnsigned(&constant_pool[constant_pool_offset]); constant_pool_offset += size; diff --git a/assembler/tests/lexer_test.cpp b/assembler/tests/lexer_test.cpp index f613727..005e0d6 100644 --- a/assembler/tests/lexer_test.cpp +++ b/assembler/tests/lexer_test.cpp @@ -214,4 +214,4 @@ TEST(lexertests, array_type) ASSERT_EQ(tok.first[2].type, Token::Type::DEL_SQUARE_BRACKET_R); } -} // namespace panda::test \ No newline at end of file +} // namespace panda::test diff --git a/runtime/mem/refstorage/ref_block.cpp b/runtime/mem/refstorage/ref_block.cpp index 2ca3ab0..ac6c397 100644 --- a/runtime/mem/refstorage/ref_block.cpp +++ b/runtime/mem/refstorage/ref_block.cpp @@ -76,16 +76,21 @@ void RefBlock::UpdateMovedRefs() continue; } for (size_t index = 0; index < REFS_IN_BLOCK; index++) { - if (block->IsBusyIndex(index)) { - auto object_pointer = block->refs_[index]; - auto *object = object_pointer.ReinterpretCast(); - auto obj = reinterpret_cast(object); - if (obj->IsForwarded()) { - LOG(DEBUG, GC) << " Update pointer for obj: " << mem::GetDebugInfoAboutObject(obj); - ObjectHeader *forward_address = GetForwardAddress(obj); - block->refs_[index] = reinterpret_cast(forward_address); - } + if (!block->IsBusyIndex(index)) { + continue; } + + auto object_pointer = block->refs_[index]; + auto *object = object_pointer.ReinterpretCast(); + auto obj = reinterpret_cast(object); + + if (!obj->IsForwarded()) { + continue; + } + + LOG(DEBUG, GC) << " Update pointer for obj: " << mem::GetDebugInfoAboutObject(obj); + ObjectHeader *forward_address = GetForwardAddress(obj); + block->refs_[index] = reinterpret_cast(forward_address); } } } diff --git a/runtime/tests/class_linker_test.cpp b/runtime/tests/class_linker_test.cpp index bfd99e2..d70f4ff 100644 --- a/runtime/tests/class_linker_test.cpp +++ b/runtime/tests/class_linker_test.cpp @@ -723,7 +723,7 @@ public: private: const uint8_t *descriptor_; - bool need_copy_descriptor_; + bool need_copy_descriptor_ {}; Class *klass_; bool is_success_ {false}; }; diff --git a/runtime/tests/debugger_test.cpp b/runtime/tests/debugger_test.cpp index 5ac60af..e95c364 100644 --- a/runtime/tests/debugger_test.cpp +++ b/runtime/tests/debugger_test.cpp @@ -113,8 +113,8 @@ TEST_F(DebuggerTest, Frame) frame->SetBytecodeOffset(BYTECODE_OFFSET); struct VRegValue { - uint64_t value; - bool is_ref; + uint64_t value {}; + bool is_ref {}; }; std::vector regs {{0x1111111122222222, false}, diff --git a/runtime/thread_manager.cpp b/runtime/thread_manager.cpp index 587d0a0..6e8fa2d 100644 --- a/runtime/thread_manager.cpp +++ b/runtime/thread_manager.cpp @@ -305,20 +305,20 @@ MTManagedThread *ThreadManager::SuspendAndWaitThreadByInternalThreadId(uint32_t ScopedManagedCodeThread sa(current); os::memory::LockHolder lock(thread_lock_); auto *thread = GetThreadByInternalThreadIdWithLockHeld(thread_id); - if (thread != nullptr) { - ASSERT(current != thread); - // CODECHECK-NOLINTNEXTLINE(C_RULE_ID_FUNCTION_NESTING_LEVEL) - if (current->IsSuspended()) { - // Unsafe to suspend as other thread may be waiting for this thread to suspend; - // Should get suspended on ScopedManagedCodeThread - continue; - } - thread->SuspendImpl(true); - suspended = thread; - } else { + + if (thread == nullptr) { // no thread found, exit return nullptr; } + + ASSERT(current != thread); + if (current->IsSuspended()) { + // Unsafe to suspend as other thread may be waiting for this thread to suspend; + // Should get suspended on ScopedManagedCodeThread + continue; + } + thread->SuspendImpl(true); + suspended = thread; } else if (suspended->GetStatus() != ThreadStatus::RUNNING) { // Thread is suspended now return suspended; diff --git a/verification/absint/abs_int_inl.h b/verification/absint/abs_int_inl.h index aef6ac9..ee2c049 100644 --- a/verification/absint/abs_int_inl.h +++ b/verification/absint/abs_int_inl.h @@ -128,7 +128,6 @@ Solutions: */ namespace panda::verifier { -namespace { template PandaVector FilterItems(const PandaVector &items, Handler &&handler) { @@ -151,7 +150,6 @@ bool IsItemPresent(const PandaVector &items, Handler &&handler) } return false; } -} // namespace class AbsIntInstructionHandler { using CachedClass = CacheOfRuntimeThings::CachedClass; diff --git a/verification/absint/exec_context.h b/verification/absint/exec_context.h index f0d78ca..2f069c1 100644 --- a/verification/absint/exec_context.h +++ b/verification/absint/exec_context.h @@ -60,25 +60,33 @@ public: void StoreCurrentRegContextForAddr(const uint8_t *addr, Reporter reporter) { if (HasContext(addr)) { - RegContext &ctx = RegContextOnCheckPoint_[addr]; - auto lub = ctx & CurrentRegContext_; - - if (lub.HasInconsistentRegs()) { - for (int reg_idx : lub.InconsistentRegsNums()) { - if (!reporter(reg_idx, CurrentRegContext_[reg_idx], ctx[reg_idx])) { - break; - } - } - } - ctx &= CurrentRegContext_; - if (ctx.HasInconsistentRegs()) { - ctx.RemoveInconsistentRegs(); - } + StoreCurrentRegContextForAddrIfHasContext(addr, reporter); } else if (IsCheckPoint(addr)) { RegContextOnCheckPoint_[addr] = CurrentRegContext_; } } + template + void StoreCurrentRegContextForAddrIfHasContext(const uint8_t *addr, Reporter reporter) + { + RegContext &ctx = RegContextOnCheckPoint_[addr]; + auto lub = ctx & CurrentRegContext_; + + if (lub.HasInconsistentRegs()) { + for (int reg_idx : lub.InconsistentRegsNums()) { + if (!reporter(reg_idx, CurrentRegContext_[reg_idx], ctx[reg_idx])) { + break; + } + } + } + + ctx &= CurrentRegContext_; + + if (ctx.HasInconsistentRegs()) { + ctx.RemoveInconsistentRegs(); + } + } + void StoreCurrentRegContextForAddr(const uint8_t *addr) { if (HasContext(addr)) { diff --git a/verification/debug/handlers/config_handler_options.cpp b/verification/debug/handlers/config_handler_options.cpp index fce7598..0f68358 100644 --- a/verification/debug/handlers/config_handler_options.cpp +++ b/verification/debug/handlers/config_handler_options.cpp @@ -78,19 +78,23 @@ static bool Verify(const Section §ion, const FlagsSection &flags) std::vector c; const char *start = i.c_str(); const char *end = i.c_str() + i.length(); // NOLINT + if (!LiteralsParser()(c, start, end)) { LOG_VERIFIER_DEBUG_CONFIG_WRONG_OPTIONS_LINE(i); return false; } - if (!c.empty()) { - for (const auto &l : c) { - if (section_flags.count(l) == 0) { - LOG_VERIFIER_DEBUG_CONFIG_WRONG_OPTION_FOR_SECTION(l, s.name, GetKeys(section_flags)); - return false; - } - section_flags.at(l).of(verif_opts) = true; - LOG_VERIFIER_DEBUG_CONFIG_OPTION_IS_ACTIVE_INFO(s.name, l); + + if (c.empty()) { + continue; + } + + for (const auto &l : c) { + if (section_flags.count(l) == 0) { + LOG_VERIFIER_DEBUG_CONFIG_WRONG_OPTION_FOR_SECTION(l, s.name, GetKeys(section_flags)); + return false; } + section_flags.at(l).of(verif_opts) = true; + LOG_VERIFIER_DEBUG_CONFIG_OPTION_IS_ACTIVE_INFO(s.name, l); } } } diff --git a/verification/util/addr_map.h b/verification/util/addr_map.h index a437ae9..a4b7935 100644 --- a/verification/util/addr_map.h +++ b/verification/util/addr_map.h @@ -122,13 +122,14 @@ public: start = reinterpret_cast(addr); } } else { - if (!BitMap_[bit_offset]) { - end = reinterpret_cast(addr - 1); - if (!cb(start, end)) { - return; - } - start = nullptr; + if (BitMap_[bit_offset]) { + continue; } + end = reinterpret_cast(addr - 1); + if (!cb(start, end)) { + return; + } + start = nullptr; } } if (start != nullptr) { diff --git a/verification/verifier/verifier.cpp b/verification/verifier/verifier.cpp index b34b945..008001d 100644 --- a/verification/verifier/verifier.cpp +++ b/verification/verifier/verifier.cpp @@ -82,23 +82,28 @@ bool VerifierProcessFile(const std::string &filename) klass = class_linker.GetExtension(ctx)->GetClass(*file, class_id); } - if (klass != nullptr) { - auto *panda_file = klass->GetPandaFile(); - bool is_system_class = panda_file == nullptr || verifier::JobQueue::IsSystemFile(panda_file); - if (is_system_class) { - continue; - } - if (is_default_context) { - ctx = Runtime::GetCurrent()->GetLanguageContext(*klass); - is_default_context = true; - } - for (auto &method : klass->GetMethods()) { - // we need AccessToManagedObjectsScope for Verify() since it can allocate objects - ScopedManagedCodeThread sj(MTManagedThread::GetCurrent()); - result = method.Verify(); - if (!result) { - return result; - } + if (klass == nullptr) { + continue; + } + + auto *panda_file = klass->GetPandaFile(); + bool is_system_class = panda_file == nullptr || verifier::JobQueue::IsSystemFile(panda_file); + + if (is_system_class) { + continue; + } + + if (is_default_context) { + ctx = Runtime::GetCurrent()->GetLanguageContext(*klass); + is_default_context = true; + } + + for (auto &method : klass->GetMethods()) { + // we need AccessToManagedObjectsScope for Verify() since it can allocate objects + ScopedManagedCodeThread sj(MTManagedThread::GetCurrent()); + result = method.Verify(); + if (!result) { + return result; } } }