From: Arnaud Giersch Date: Sun, 22 Dec 2019 20:43:59 +0000 (+0100) Subject: [sonar] Initialize data members with class initializers, or initialization lists. X-Git-Tag: v3.25~237 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c6bbeb1829c36ff45b43ab25f9d8d3f53f554d98 [sonar] Initialize data members with class initializers, or initialization lists. --- diff --git a/examples/s4u/dht-chord/s4u-dht-chord.hpp b/examples/s4u/dht-chord/s4u-dht-chord.hpp index eea1f2f41a..dd3c7b2b28 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.hpp +++ b/examples/s4u/dht-chord/s4u-dht-chord.hpp @@ -37,16 +37,13 @@ enum e_message_type_t { class ChordMessage { public: e_message_type_t type; // type of message - std::string issuer_host_name; // used for logging + std::string issuer_host_name = simgrid::s4u::this_actor::get_host()->get_name(); // used for logging int request_id = -1; // id (used by some types of messages) int request_finger = 1; // finger parameter (used by some types of messages) int answer_id = -1; // answer (used by some types of messages) simgrid::s4u::Mailbox* answer_to = nullptr; // mailbox to send an answer to (if any) - explicit ChordMessage(e_message_type_t type) - : type(type), issuer_host_name(simgrid::s4u::this_actor::get_host()->get_name()) - { - } + explicit ChordMessage(e_message_type_t type) : type(type) {} static void destroy(void* message); }; diff --git a/examples/s4u/dht-kademlia/node.hpp b/examples/s4u/dht-kademlia/node.hpp index 0aa8d80310..400461525e 100644 --- a/examples/s4u/dht-kademlia/node.hpp +++ b/examples/s4u/dht-kademlia/node.hpp @@ -17,11 +17,11 @@ class Node { unsigned int id_; // node id - 160 bits RoutingTable table; // node routing table public: - simgrid::s4u::CommPtr receive_comm; + simgrid::s4u::CommPtr receive_comm = nullptr; void* received_msg = nullptr; unsigned int find_node_success = 0; // Number of find_node which have succeeded. unsigned int find_node_failed = 0; // Number of find_node which have failed. - explicit Node(unsigned int node_id) : id_(node_id), table(node_id), receive_comm(nullptr) {} + explicit Node(unsigned int node_id) : id_(node_id), table(node_id) {} Node(const Node&) = delete; Node& operator=(const Node&) = delete; unsigned int getId() { return id_; } diff --git a/include/simgrid/kernel/future.hpp b/include/simgrid/kernel/future.hpp index d938b44f70..c55f741d95 100644 --- a/include/simgrid/kernel/future.hpp +++ b/include/simgrid/kernel/future.hpp @@ -445,17 +445,13 @@ template Future unwrap_future(Future> future) template class Promise { public: - Promise() : state_(std::make_shared>()) {} + Promise() = default; explicit Promise(std::shared_ptr> state) : state_(std::move(state)) {} // Move type Promise(Promise const&) = delete; Promise& operator=(Promise const&) = delete; - Promise(Promise&& that) : - state_(std::move(that.state_)), future_get_(that.future_get_) - { - that.future_get_ = false; - } + Promise(Promise&& that) : state_(std::move(that.state_)) { std::swap(future_get_, that.future_get_); } Promise& operator=(Promise&& that) { @@ -493,14 +489,14 @@ public: } private: - std::shared_ptr> state_; + std::shared_ptr> state_{new FutureState()}; bool future_get_ = false; }; template<> class Promise { public: - Promise() : state_(std::make_shared>()) {} + Promise() = default; explicit Promise(std::shared_ptr> state) : state_(std::move(state)) {} ~Promise() { @@ -512,11 +508,7 @@ public: // Move type Promise(Promise const&) = delete; Promise& operator=(Promise const&) = delete; - Promise(Promise&& that) : - state_(std::move(that.state_)), future_get_(that.future_get_) - { - that.future_get_ = false; - } + Promise(Promise&& that) : state_(std::move(that.state_)) { std::swap(future_get_, that.future_get_); } Promise& operator=(Promise&& that) { this->state_ = std::move(that.state_); @@ -548,7 +540,7 @@ public: } private: - std::shared_ptr> state_; + std::shared_ptr> state_{new FutureState()}; bool future_get_ = false; }; diff --git a/include/simgrid/kernel/routing/FloydZone.hpp b/include/simgrid/kernel/routing/FloydZone.hpp index b16ea00ce3..f768867da5 100644 --- a/include/simgrid/kernel/routing/FloydZone.hpp +++ b/include/simgrid/kernel/routing/FloydZone.hpp @@ -35,9 +35,9 @@ public: private: /* vars to compute the Floyd algorithm. */ - int* predecessor_table_; - double* cost_table_; - RouteCreationArgs** link_table_; + int* predecessor_table_ = nullptr; + double* cost_table_ = nullptr; + RouteCreationArgs** link_table_ = nullptr; }; } // namespace routing } // namespace kernel diff --git a/include/simgrid/s4u/Barrier.hpp b/include/simgrid/s4u/Barrier.hpp index db8e05e830..207615555f 100644 --- a/include/simgrid/s4u/Barrier.hpp +++ b/include/simgrid/s4u/Barrier.hpp @@ -20,8 +20,8 @@ namespace s4u { class XBT_PUBLIC Barrier { private: - MutexPtr mutex_; - ConditionVariablePtr cond_; + MutexPtr mutex_ = Mutex::create(); + ConditionVariablePtr cond_ = ConditionVariable::create(); unsigned int expected_actors_; unsigned int arrived_actors_ = 0; @@ -30,7 +30,7 @@ private: public: /** Creates a barrier for the given amount of actors */ - explicit Barrier(unsigned int count); + explicit Barrier(unsigned int expected_processes) : expected_actors_(expected_processes) {} #ifndef DOXYGEN ~Barrier() = default; Barrier(Barrier const&) = delete; diff --git a/include/simgrid/smpi/replay.hpp b/include/simgrid/smpi/replay.hpp index d295586b74..715f52ee93 100644 --- a/include/simgrid/smpi/replay.hpp +++ b/include/simgrid/smpi/replay.hpp @@ -183,11 +183,11 @@ public: template class ReplayAction { protected: const std::string name; - const aid_t my_proc_id; + const aid_t my_proc_id = s4u::this_actor::get_pid(); T args; public: - explicit ReplayAction(const std::string& name) : name(name), my_proc_id(s4u::this_actor::get_pid()) {} + explicit ReplayAction(const std::string& name) : name(name) {} virtual ~ReplayAction() = default; void execute(xbt::ReplayAction& action) diff --git a/include/xbt/Extendable.hpp b/include/xbt/Extendable.hpp index c85201fec6..369e3a3462 100644 --- a/include/xbt/Extendable.hpp +++ b/include/xbt/Extendable.hpp @@ -19,12 +19,12 @@ template class Extendable; template class Extension { - static const std::size_t INVALID_ID = std::numeric_limits::max(); - std::size_t id_; + static constexpr std::size_t INVALID_ID = std::numeric_limits::max(); + std::size_t id_ = INVALID_ID; friend class Extendable; explicit constexpr Extension(std::size_t id) : id_(id) {} public: - explicit constexpr Extension() : id_(INVALID_ID) {} + explicit constexpr Extension() {} std::size_t id() const { return id_; } bool valid() const { return id_ != INVALID_ID; } }; @@ -48,7 +48,8 @@ template class Extendable { private: static std::vector deleters_; - std::vector extensions_; + std::vector extensions_{(deleters_.size() > 0 ? deleters_.size() : 1), nullptr}; + public: static size_t extension_create(void (*deleter)(void*)) { @@ -68,7 +69,7 @@ public: { return Extension(extension_create([](void* p) { delete static_cast(p); })); } - Extendable() : extensions_((deleters_.size() > 0 ? deleters_.size() : 1), nullptr) {} + Extendable() {} Extendable(const Extendable&) = delete; Extendable& operator=(const Extendable&) = delete; ~Extendable() diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index 5d1b98c302..228d6fa770 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -115,13 +115,14 @@ public: }; class Pt2PtTIData : public TIData { - int tag; + int tag = 0; + public: explicit Pt2PtTIData(const std::string& name, int endpoint, int size, int tag, const std::string& datatype) : TIData(name, endpoint, size, datatype), tag(tag){}; explicit Pt2PtTIData(const std::string& name, int endpoint, int size, const std::string& datatype) - : TIData(name, endpoint, size, datatype), tag(0){}; + : TIData(name, endpoint, size, datatype){}; std::string print() override { std::stringstream stream; diff --git a/src/instr/jedule/jedule_platform.cpp b/src/instr/jedule/jedule_platform.cpp index fd248982e9..3c6a59117c 100644 --- a/src/instr/jedule/jedule_platform.cpp +++ b/src/instr/jedule/jedule_platform.cpp @@ -19,9 +19,8 @@ std::unordered_map container_name2container; namespace simgrid { namespace jedule { Subset::Subset(int start_idx, int end_idx, Container* parent) -: start_idx(start_idx), parent(parent) + : start_idx(start_idx), nres(end_idx - start_idx + 1), parent(parent) { - nres=end_idx-start_idx+1; } Container::Container(const std::string& name) : name(name) diff --git a/src/kernel/activity/MailboxImpl.hpp b/src/kernel/activity/MailboxImpl.hpp index 5cb5a9f95e..55b5656cb7 100644 --- a/src/kernel/activity/MailboxImpl.hpp +++ b/src/kernel/activity/MailboxImpl.hpp @@ -29,10 +29,7 @@ class MailboxImpl { friend s4u::Mailbox* s4u::Mailbox::by_name(const std::string& name); friend mc::CommunicationDeterminismChecker; - explicit MailboxImpl(const std::string& name) - : piface_(this), name_(name), comm_queue_(MAX_MAILBOX_SIZE), done_comm_queue_(MAX_MAILBOX_SIZE) - { - } + explicit MailboxImpl(const std::string& name) : piface_(this), name_(name) {} public: const xbt::string& get_name() const { return name_; } @@ -47,9 +44,9 @@ public: const CommImplPtr& my_synchro, bool done, bool remove_matching); actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached - boost::circular_buffer_space_optimized comm_queue_; - boost::circular_buffer_space_optimized done_comm_queue_; // messages already received in the permanent - // receive mode + boost::circular_buffer_space_optimized comm_queue_{MAX_MAILBOX_SIZE}; + // messages already received in the permanent receive mode + boost::circular_buffer_space_optimized done_comm_queue_{MAX_MAILBOX_SIZE}; }; } // namespace activity } // namespace kernel diff --git a/src/kernel/lmm/maxmin.cpp b/src/kernel/lmm/maxmin.cpp index 96cc184dac..d0a9f1f01e 100644 --- a/src/kernel/lmm/maxmin.cpp +++ b/src/kernel/lmm/maxmin.cpp @@ -4,7 +4,6 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/kernel/lmm/maxmin.hpp" -#include "src/surf/surf_interface.hpp" #include "xbt/backtrace.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf, "Logging specific to SURF (maxmin)"); @@ -172,17 +171,6 @@ void System::cnst_free(Constraint* cnst) Constraint::Constraint(resource::Resource* id_value, double bound_value) : bound_(bound_value), id_(id_value) { rank_ = next_rank_++; - - remaining_ = 0.0; - usage_ = 0.0; - concurrency_limit_ = sg_concurrency_limit; - concurrency_current_ = 0; - concurrency_maximum_ = 0; - sharing_policy_ = s4u::Link::SharingPolicy::SHARED; - - lambda_ = 0.0; - new_lambda_ = 0.0; - cnst_light_ = nullptr; } Constraint* System::constraint_new(resource::Resource* id, double bound_value) diff --git a/src/kernel/lmm/maxmin.hpp b/src/kernel/lmm/maxmin.hpp index 670e24a795..4244c994d3 100644 --- a/src/kernel/lmm/maxmin.hpp +++ b/src/kernel/lmm/maxmin.hpp @@ -8,6 +8,7 @@ #include "simgrid/kernel/resource/Action.hpp" #include "simgrid/s4u/Link.hpp" +#include "src/surf/surf_interface.hpp" #include "xbt/asserts.h" #include "xbt/mallocator.h" @@ -260,24 +261,24 @@ public: boost::intrusive::list, &Element::active_element_set_hook>> active_element_set_; - double remaining_; - double usage_; + double remaining_ = 0.0; + double usage_ = 0.0; double bound_; // TODO MARTIN Check maximum value across resources at the end of simulation and give a warning is more than e.g. 500 - int concurrency_current_; /* The current concurrency */ - int concurrency_maximum_; /* The maximum number of (enabled and disabled) variables associated to the constraint at - * any given time (essentially for tracing)*/ + int concurrency_current_ = 0; /* The current concurrency */ + int concurrency_maximum_ = 0; /* The maximum number of (enabled and disabled) variables associated to the constraint + * at any given time (essentially for tracing)*/ - s4u::Link::SharingPolicy sharing_policy_; + s4u::Link::SharingPolicy sharing_policy_ = s4u::Link::SharingPolicy::SHARED; int rank_; // Only used in debug messages to identify the constraint - double lambda_; - double new_lambda_; - ConstraintLight* cnst_light_; + double lambda_ = 0.0; + double new_lambda_ = 0.0; + ConstraintLight* cnst_light_ = nullptr; private: static int next_rank_; // To give a separate rank_ to each constraint - int concurrency_limit_; /* The maximum number of variables that may be enabled at any time (stage variables if - * necessary) */ + int concurrency_limit_ = sg_concurrency_limit; /* The maximum number of variables that may be enabled at any time + * (stage variables if necessary) */ resource::Resource* id_; }; diff --git a/src/kernel/routing/FloydZone.cpp b/src/kernel/routing/FloydZone.cpp index c7bb065442..d9b7ab832b 100644 --- a/src/kernel/routing/FloydZone.cpp +++ b/src/kernel/routing/FloydZone.cpp @@ -26,9 +26,6 @@ namespace routing { FloydZone::FloydZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel) : RoutedZone(father, name, netmodel) { - predecessor_table_ = nullptr; - cost_table_ = nullptr; - link_table_ = nullptr; } FloydZone::~FloydZone() diff --git a/src/mc/AddressSpace.hpp b/src/mc/AddressSpace.hpp index d14040e0f2..847ee77caf 100644 --- a/src/mc/AddressSpace.hpp +++ b/src/mc/AddressSpace.hpp @@ -19,10 +19,10 @@ namespace mc { * integers are not allowed. */ class ReadOptions { - std::uint32_t value_; + std::uint32_t value_ = 0; constexpr explicit ReadOptions(std::uint32_t value) : value_(value) {} public: - constexpr ReadOptions() : value_(0) {} + constexpr ReadOptions() {} explicit constexpr operator bool() const { return value_ != 0; } constexpr bool operator!() const { return value_ == 0; } diff --git a/src/mc/ModelChecker.cpp b/src/mc/ModelChecker.cpp index 52c7796954..f5ef3b49cb 100644 --- a/src/mc/ModelChecker.cpp +++ b/src/mc/ModelChecker.cpp @@ -32,14 +32,7 @@ using simgrid::mc::remote; namespace simgrid { namespace mc { -ModelChecker::ModelChecker(std::unique_ptr process) - : base_(nullptr) - , socket_event_(nullptr) - , signal_event_(nullptr) - , page_store_(500) - , process_(std::move(process)) -{ -} +ModelChecker::ModelChecker(std::unique_ptr process) : process_(std::move(process)) {} ModelChecker::~ModelChecker() { diff --git a/src/mc/ModelChecker.hpp b/src/mc/ModelChecker.hpp index d5016d3287..fcbff13718 100644 --- a/src/mc/ModelChecker.hpp +++ b/src/mc/ModelChecker.hpp @@ -21,14 +21,14 @@ namespace mc { /** State of the model-checker (global variables for the model checker) */ class ModelChecker { - struct event_base *base_; - struct event* socket_event_; - struct event* signal_event_; + struct event_base* base_ = nullptr; + struct event* socket_event_ = nullptr; + struct event* signal_event_ = nullptr; /** String pool for host names */ // TODO, use std::set with heterogeneous comparison lookup (C++14)? std::set hostnames_; // This is the parent snapshot of the current state: - PageStore page_store_; + PageStore page_store_{500}; std::unique_ptr process_; Checker* checker_ = nullptr; public: diff --git a/src/mc/VisitedState.cpp b/src/mc/VisitedState.cpp index cb4d2d9b17..5b8919be6e 100644 --- a/src/mc/VisitedState.cpp +++ b/src/mc/VisitedState.cpp @@ -27,7 +27,6 @@ VisitedState::VisitedState(unsigned long state_number) : num(state_number) this->actors_count = mc_model_checker->process().actors().size(); this->system_state = std::make_shared(state_number); - this->original_num = -1; } void VisitedStates::prune() diff --git a/src/mc/VisitedState.hpp b/src/mc/VisitedState.hpp index ea116d9dbb..6926485aa1 100644 --- a/src/mc/VisitedState.hpp +++ b/src/mc/VisitedState.hpp @@ -21,7 +21,7 @@ public: std::size_t heap_bytes_used = 0; int actors_count = 0; int num = 0; // unique id of that state in the storage of all stored IDs - int original_num = 0; // num field of the VisitedState to which I was declared equal to (used for dot_output) + int original_num = -1; // num field of the VisitedState to which I was declared equal to (used for dot_output) explicit VisitedState(unsigned long state_number); ~VisitedState() = default; diff --git a/src/mc/inspect/DwarfExpression.hpp b/src/mc/inspect/DwarfExpression.hpp index efb089e10b..0f695ee345 100644 --- a/src/mc/inspect/DwarfExpression.hpp +++ b/src/mc/inspect/DwarfExpression.hpp @@ -42,21 +42,12 @@ typedef std::vector DwarfExpression; * the process memory, etc. All those informations are gathered in * the evaluation context. */ -class ExpressionContext { -public: - ExpressionContext() - : cursor(nullptr) - , frame_base(nullptr) - , address_space(nullptr) - , object_info(nullptr) - { - } +struct ExpressionContext { /** CPU state (registers) */ - unw_cursor_t* cursor; - void* frame_base; - /** Address space used to read memory */ - const simgrid::mc::AddressSpace* address_space; - simgrid::mc::ObjectInformation* object_info; + unw_cursor_t* cursor = nullptr; + void* frame_base = nullptr; + const simgrid::mc::AddressSpace* address_space = nullptr; /** Address space used to read memory */ + simgrid::mc::ObjectInformation* object_info = nullptr; }; /** When an error happens in the execution of a DWARF expression */ @@ -77,11 +68,9 @@ public: private: // Values of the stack (the top is stack_[size_ - 1]): uintptr_t stack_[max_size]{0}; - size_t size_; + size_t size_ = 0; public: - ExpressionStack() : size_(0) {} - // Access: std::size_t size() const { return size_; } bool empty() const { return size_ == 0; } diff --git a/src/mc/inspect/Frame.hpp b/src/mc/inspect/Frame.hpp index 0d653ed26e..a9526f45f0 100644 --- a/src/mc/inspect/Frame.hpp +++ b/src/mc/inspect/Frame.hpp @@ -23,8 +23,6 @@ namespace mc { /** Debug information about a given function or scope within a function */ class Frame { public: - Frame(); - /** Kind of scope (DW_TAG_subprogram, DW_TAG_inlined_subroutine, etc.) */ int tag = DW_TAG_invalid; @@ -32,7 +30,7 @@ public: std::string name; /** Range of instruction addresses for which this scope is valid */ - simgrid::xbt::Range range; + simgrid::xbt::Range range{0, 0}; simgrid::dwarf::LocationList frame_base_location; @@ -59,15 +57,6 @@ public: void remove_variable(char* name); }; -inline Frame::Frame() -{ - this->tag = 0; - this->range = {0, 0}; - this->id = 0; - this->abstract_origin_id = 0; - this->object_info = nullptr; -} - } // namespace mc } // namespace simgrid diff --git a/src/mc/inspect/LocationList.hpp b/src/mc/inspect/LocationList.hpp index 07dcb7c991..adb4b4e90b 100644 --- a/src/mc/inspect/LocationList.hpp +++ b/src/mc/inspect/LocationList.hpp @@ -49,12 +49,12 @@ typedef std::vector LocationList; */ class Location { private: - void* memory_; + void* memory_ = nullptr; int register_id_ = 0; public: explicit Location(void* x) : memory_(x) {} - explicit Location(int register_id) : memory_(nullptr), register_id_(register_id) {} + explicit Location(int register_id) : register_id_(register_id) {} // Type of location: bool in_register() const { return memory_ == nullptr; } bool in_memory() const { return memory_ != nullptr; } diff --git a/src/mc/mc_state.cpp b/src/mc/mc_state.cpp index 96692005c9..5670d07021 100644 --- a/src/mc/mc_state.cpp +++ b/src/mc/mc_state.cpp @@ -19,8 +19,6 @@ namespace mc { State::State(unsigned long state_number) : num_(state_number) { this->internal_comm_.clear(); - this->internal_req_ = s_smx_simcall(); - this->executed_req_ = s_smx_simcall(); actor_states_.resize(MC_smx_get_maxpid()); /* Stateful model checking */ diff --git a/src/mc/remote/Channel.hpp b/src/mc/remote/Channel.hpp index a3e234410c..0acbf1590d 100644 --- a/src/mc/remote/Channel.hpp +++ b/src/mc/remote/Channel.hpp @@ -38,8 +38,7 @@ public: Channel(Channel&& that) : socket_(that.socket_) { that.socket_ = -1; } Channel& operator=(Channel&& that) { - this->socket_ = that.socket_; - that.socket_ = -1; + std::swap(this->socket_, that.socket_); return *this; } diff --git a/src/mc/remote/RemotePtr.hpp b/src/mc/remote/RemotePtr.hpp index 5da8005458..f4f38ef154 100644 --- a/src/mc/remote/RemotePtr.hpp +++ b/src/mc/remote/RemotePtr.hpp @@ -59,11 +59,11 @@ public: * as a `uint64_t`. */ template class RemotePtr { - std::uint64_t address_; + std::uint64_t address_ = 0; public: - RemotePtr() : address_(0) {} - explicit RemotePtr(std::nullptr_t) : address_(0) {} + RemotePtr() = default; + explicit RemotePtr(std::nullptr_t) {} explicit RemotePtr(std::uint64_t address) : address_(address) {} explicit RemotePtr(T* address) : address_((std::uintptr_t)address) {} explicit RemotePtr(Remote p) : address_((std::uintptr_t)*p.get_buffer()) {} diff --git a/src/mc/sosp/ChunkedData.cpp b/src/mc/sosp/ChunkedData.cpp index 808fc60501..14796c4120 100644 --- a/src/mc/sosp/ChunkedData.cpp +++ b/src/mc/sosp/ChunkedData.cpp @@ -16,8 +16,8 @@ namespace mc { * @return Snapshot page numbers of this new snapshot */ ChunkedData::ChunkedData(PageStore& store, AddressSpace& as, RemotePtr addr, std::size_t page_count) + : store_(&store) { - store_ = &store; this->pagenos_.resize(page_count); std::vector buffer(xbt_pagesize); diff --git a/src/mc/sosp/ChunkedData.hpp b/src/mc/sosp/ChunkedData.hpp index 2545954bc3..8d5f1baa06 100644 --- a/src/mc/sosp/ChunkedData.hpp +++ b/src/mc/sosp/ChunkedData.hpp @@ -46,9 +46,9 @@ public: for (std::size_t const& pageno : pagenos_) store_->ref_page(pageno); } - ChunkedData(ChunkedData&& that) : store_(that.store_), pagenos_(std::move(that.pagenos_)) + ChunkedData(ChunkedData&& that) : pagenos_(std::move(that.pagenos_)) { - that.store_ = nullptr; + std::swap(store_, that.store_); that.pagenos_.clear(); } ChunkedData& operator=(ChunkedData const& that) diff --git a/src/mc/sosp/PageStore.cpp b/src/mc/sosp/PageStore.cpp index e3702c83f8..149e36dc0b 100644 --- a/src/mc/sosp/PageStore.cpp +++ b/src/mc/sosp/PageStore.cpp @@ -50,7 +50,7 @@ static XBT_ALWAYS_INLINE PageStore::hash_type mc_hash_page(const void* data) // ***** snapshot_page_manager -PageStore::PageStore(std::size_t size) : memory_(nullptr), capacity_(size), top_index_(0) +PageStore::PageStore(std::size_t size) : capacity_(size) { // Using mmap in order to be able to expand the region by relocating it somewhere else in the virtual memory space: void* memory = diff --git a/src/mc/sosp/Snapshot.cpp b/src/mc/sosp/Snapshot.cpp index e42e3d3f65..de20ddddde 100644 --- a/src/mc/sosp/Snapshot.cpp +++ b/src/mc/sosp/Snapshot.cpp @@ -197,8 +197,7 @@ static void snapshot_ignore_restore(simgrid::mc::Snapshot* snapshot) snapshot->process()->write_bytes(ignored_data.data.data(), ignored_data.data.size(), remote(ignored_data.start)); } -Snapshot::Snapshot(int num_state, RemoteClient* process) - : AddressSpace(process), num_state_(num_state), heap_bytes_used_(0), enabled_processes_(), hash_(0) +Snapshot::Snapshot(int num_state, RemoteClient* process) : AddressSpace(process), num_state_(num_state) { XBT_DEBUG("Taking snapshot %i", num_state); diff --git a/src/mc/sosp/Snapshot.hpp b/src/mc/sosp/Snapshot.hpp index f227fe72ee..674108460b 100644 --- a/src/mc/sosp/Snapshot.hpp +++ b/src/mc/sosp/Snapshot.hpp @@ -78,7 +78,7 @@ public: // To be private int num_state_; - std::size_t heap_bytes_used_; + std::size_t heap_bytes_used_ = 0; std::vector> snapshot_regions_; std::set enabled_processes_; std::vector stack_sizes_; diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index 88ec37b6d4..fce578d9f1 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -479,10 +479,9 @@ FileSystemDiskExt::FileSystemDiskExt(simgrid::s4u::Disk* ptr) content_.reset(parse_content(content_str)); } -FileSystemStorageExt::FileSystemStorageExt(simgrid::s4u::Storage* ptr) +FileSystemStorageExt::FileSystemStorageExt(simgrid::s4u::Storage* ptr) : size_(ptr->get_impl()->size_) { content_.reset(parse_content(ptr->get_impl()->content_name_)); - size_ = ptr->get_impl()->size_; } std::map* FileSystemDiskExt::parse_content(const std::string& filename) diff --git a/src/plugins/host_dvfs.cpp b/src/plugins/host_dvfs.cpp index af145fb790..f477c5f3c5 100644 --- a/src/plugins/host_dvfs.cpp +++ b/src/plugins/host_dvfs.cpp @@ -85,15 +85,15 @@ namespace dvfs { class Governor { simgrid::s4u::Host* const host_; double sampling_rate_; - int min_pstate; //< Never use a pstate less than this one - int max_pstate; //< Never use a pstate larger than this one + int min_pstate = cfg_min_pstate; //< Never use a pstate less than this one + int max_pstate = cfg_max_pstate; //< Never use a pstate larger than this one public: explicit Governor(simgrid::s4u::Host* ptr) : host_(ptr) - , min_pstate(cfg_min_pstate) - , max_pstate(cfg_max_pstate == max_pstate_not_limited ? host_->get_pstate_count() - 1 : cfg_max_pstate) { + if (cfg_max_pstate == max_pstate_not_limited) + max_pstate = host_->get_pstate_count() - 1; init(); } virtual ~Governor() = default; diff --git a/src/plugins/host_energy.cpp b/src/plugins/host_energy.cpp index c7ea34026a..6eac380e31 100644 --- a/src/plugins/host_energy.cpp +++ b/src/plugins/host_energy.cpp @@ -160,7 +160,7 @@ public: double watts_off_ = 0.0; /*< Consumption when the machine is turned off (shutdown) */ double total_energy_ = 0.0; /*< Total energy consumed by the host */ - double last_updated_; /*< Timestamp of the last energy update event*/ + double last_updated_ = surf_get_clock(); /*< Timestamp of the last energy update event*/ }; simgrid::xbt::Extension HostEnergy::EXTENSION_ID; @@ -198,7 +198,7 @@ void HostEnergy::update() this->pstate_ = host_->is_on() ? host_->get_pstate() : pstate_off_; } -HostEnergy::HostEnergy(simgrid::s4u::Host* ptr) : host_(ptr), last_updated_(surf_get_clock()) +HostEnergy::HostEnergy(simgrid::s4u::Host* ptr) : host_(ptr) { init_watts_range_list(); diff --git a/src/plugins/host_load.cpp b/src/plugins/host_load.cpp index f84ffc0404..cf0141a8c6 100644 --- a/src/plugins/host_load.cpp +++ b/src/plugins/host_load.cpp @@ -63,7 +63,6 @@ public: , last_reset_(surf_get_clock()) , current_speed_(host_->get_speed()) , current_flops_(host_->get_load()) - , theor_max_flops_(0) { } ~HostLoad() = default; diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index b7ccd74e5f..ee173f3370 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -158,7 +158,7 @@ double VMModel::next_occurring_event(double now) VirtualMachineImpl::VirtualMachineImpl(simgrid::s4u::VirtualMachine* piface, simgrid::s4u::Host* host_PM, int core_amount, size_t ramsize) - : HostImpl(piface), physical_host_(host_PM), core_amount_(core_amount), user_bound_(std::numeric_limits::max()), ramsize_(ramsize) + : HostImpl(piface), physical_host_(host_PM), core_amount_(core_amount), ramsize_(ramsize) { /* Register this VM to the list of all VMs */ allVms_.push_back(piface); diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index 8f27c16fba..aa9013bb58 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -66,7 +66,7 @@ public: private: s4u::Host* physical_host_; int core_amount_; - double user_bound_; + double user_bound_ = std::numeric_limits::max(); size_t ramsize_ = 0; s4u::VirtualMachine::state vm_state_ = s4u::VirtualMachine::state::CREATED; }; diff --git a/src/s4u/s4u_Barrier.cpp b/src/s4u/s4u_Barrier.cpp index 7289a6ccb6..5002e6f487 100644 --- a/src/s4u/s4u_Barrier.cpp +++ b/src/s4u/s4u_Barrier.cpp @@ -17,11 +17,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_barrier, s4u, "S4U barrier"); namespace simgrid { namespace s4u { -Barrier::Barrier(unsigned int expected_processes) - : mutex_(Mutex::create()), cond_(ConditionVariable::create()), expected_actors_(expected_processes) -{ -} - /** @brief Create a new barrier * * See @ref s4u_raii. diff --git a/src/smpi/include/smpi_comm.hpp b/src/smpi/include/smpi_comm.hpp index 3f57cfa260..1febed343e 100644 --- a/src/smpi/include/smpi_comm.hpp +++ b/src/smpi/include/smpi_comm.hpp @@ -19,20 +19,20 @@ namespace smpi{ class Comm : public F2C, public Keyval{ friend Topo; MPI_Group group_; - SMPI_Topo_type topoType_; + SMPI_Topo_type topoType_ = MPI_INVALID_TOPO; MPI_Topology topo_; // to be replaced by an union - int refcount_; - MPI_Comm leaders_comm_; // inter-node communicator - MPI_Comm intra_comm_; // intra-node communicator . For MPI_COMM_WORLD this can't be used, as var is global. - // use an intracomm stored in the process data instead - int* leaders_map_; // who is the leader of each process - int is_uniform_; - int* non_uniform_map_; // set if smp nodes have a different number of processes allocated - int is_blocked_; // are ranks allocated on the same smp node contiguous ? + int refcount_ = 1; + MPI_Comm leaders_comm_ = MPI_COMM_NULL; // inter-node communicator + MPI_Comm intra_comm_ = MPI_COMM_NULL; // intra-node communicator. For MPI_COMM_WORLD this can't be used, as var is + // global. Use an intracomm stored in the process data instead + int* leaders_map_ = nullptr; // who is the leader of each process + int is_uniform_ = 1; + int* non_uniform_map_ = nullptr; // set if smp nodes have a different number of processes allocated + int is_blocked_ = 0; // are ranks allocated on the same smp node contiguous ? int is_smp_comm_; // set to 0 in case this is already an intra-comm or a leader-comm to avoid recursion std::list rma_wins_; // attached windows for synchronization. std::string name_; - MPI_Info info_; + MPI_Info info_ = MPI_INFO_NULL; int id_; MPI_Errhandler errhandler_; diff --git a/src/smpi/include/smpi_datatype.hpp b/src/smpi/include/smpi_datatype.hpp index 09a821b650..196ab80cbf 100644 --- a/src/smpi/include/smpi_datatype.hpp +++ b/src/smpi/include/smpi_datatype.hpp @@ -77,7 +77,7 @@ namespace simgrid{ namespace smpi{ class Datatype : public F2C, public Keyval{ - char* name_; + char* name_ = nullptr; /* The id here is the (unique) datatype id used for this datastructure. * It's default value is set to -1 since some code expects this return value * when no other id has been assigned @@ -87,7 +87,7 @@ class Datatype : public F2C, public Keyval{ MPI_Aint lb_; MPI_Aint ub_; int flags_; - int refcount_; + int refcount_ = 1; public: static std::unordered_map keyvals_; diff --git a/src/smpi/include/smpi_f2c.hpp b/src/smpi/include/smpi_f2c.hpp index 455973c74d..867800fa63 100644 --- a/src/smpi/include/smpi_f2c.hpp +++ b/src/smpi/include/smpi_f2c.hpp @@ -23,7 +23,7 @@ class F2C { // Beware of collisions if id in mpif.h is not unique static std::unordered_map* f2c_lookup_; static int f2c_id_; - int my_f2c_id_; + int my_f2c_id_ = -1; protected: static std::unordered_map* f2c_lookup(); @@ -36,7 +36,6 @@ class F2C { static char* get_key(char* key, int id); static void delete_lookup(); static std::unordered_map* lookup(); - F2C() : my_f2c_id_(-1){} virtual ~F2C() = default; //Override these to handle specific values. diff --git a/src/smpi/include/smpi_win.hpp b/src/smpi/include/smpi_win.hpp index 54862977f6..242c7efcdf 100644 --- a/src/smpi/include/smpi_win.hpp +++ b/src/smpi/include/smpi_win.hpp @@ -23,7 +23,7 @@ class Win : public F2C, public Keyval { void* base_; MPI_Aint size_; int disp_unit_; - int assert_; + int assert_ = 0; MPI_Info info_; MPI_Comm comm_; std::vector *requests_; diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index e4e9929a0b..ac061c0115 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -30,15 +30,6 @@ int Comm::keyval_id_=0; Comm::Comm(MPI_Group group, MPI_Topology topo, int smp, int in_id) : group_(group), topo_(topo),is_smp_comm_(smp), id_(in_id) { - refcount_ = 1; - topoType_ = MPI_INVALID_TOPO; - intra_comm_ = MPI_COMM_NULL; - leaders_comm_ = MPI_COMM_NULL; - is_uniform_ = 1; - non_uniform_map_ = nullptr; - leaders_map_ = nullptr; - is_blocked_ = 0; - info_ = MPI_INFO_NULL; errhandler_ = MPI_ERRORS_ARE_FATAL; errhandler_->ref(); //First creation of comm is done before SIMIX_run, so only do comms for others diff --git a/src/smpi/mpi/smpi_datatype.cpp b/src/smpi/mpi/smpi_datatype.cpp index 3829b155f9..8a7773cb2b 100644 --- a/src/smpi/mpi/smpi_datatype.cpp +++ b/src/smpi/mpi/smpi_datatype.cpp @@ -107,14 +107,16 @@ Datatype::Datatype(int ident, int size, MPI_Aint lb, MPI_Aint ub, int flags) : D { id = std::to_string(ident); } -Datatype::Datatype(int size,MPI_Aint lb, MPI_Aint ub, int flags) : name_(nullptr), size_(size), lb_(lb), ub_(ub), flags_(flags), refcount_(1){ + +Datatype::Datatype(int size, MPI_Aint lb, MPI_Aint ub, int flags) : size_(size), lb_(lb), ub_(ub), flags_(flags) +{ #if SIMGRID_HAVE_MC if(MC_is_active()) MC_ignore(&(refcount_), sizeof(refcount_)); #endif } -//for predefined types, so in_use = 0. +// for predefined types, so refcount_ = 0. Datatype::Datatype(char* name, int ident, int size, MPI_Aint lb, MPI_Aint ub, int flags) : name_(name), id(std::to_string(ident)), size_(size), lb_(lb), ub_(ub), flags_(flags), refcount_(0) { @@ -125,7 +127,8 @@ Datatype::Datatype(char* name, int ident, int size, MPI_Aint lb, MPI_Aint ub, in #endif } -Datatype::Datatype(Datatype *datatype, int* ret) : name_(nullptr), size_(datatype->size_), lb_(datatype->lb_), ub_(datatype->ub_), flags_(datatype->flags_), refcount_(1) +Datatype::Datatype(Datatype* datatype, int* ret) + : size_(datatype->size_), lb_(datatype->lb_), ub_(datatype->ub_), flags_(datatype->flags_) { flags_ &= ~DT_FLAG_PREDEFINED; *ret = MPI_SUCCESS; diff --git a/src/smpi/mpi/smpi_datatype_derived.cpp b/src/smpi/mpi/smpi_datatype_derived.cpp index 9b1140dc2a..dcfbdee0a8 100644 --- a/src/smpi/mpi/smpi_datatype_derived.cpp +++ b/src/smpi/mpi/smpi_datatype_derived.cpp @@ -93,11 +93,13 @@ Type_Vector::Type_Vector(int size, MPI_Aint lb, MPI_Aint ub, int flags, int coun Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths, const MPI_Aint* block_indices, MPI_Datatype old_type) - : Datatype(size, lb, ub, flags), block_count_(count), old_type_(old_type) + : Datatype(size, lb, ub, flags) + , block_count_(count) + , block_lengths_(new int[count]) + , block_indices_(new MPI_Aint[count]) + , old_type_(old_type) { old_type_->ref(); - block_lengths_ = new int[count]; - block_indices_ = new MPI_Aint[count]; for (int i = 0; i < count; i++) { block_lengths_[i] = block_lengths[i]; block_indices_[i] = block_indices[i]; @@ -106,11 +108,13 @@ Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths, const int* block_indices, MPI_Datatype old_type, MPI_Aint factor) - : Datatype(size, lb, ub, flags), block_count_(count), old_type_(old_type) + : Datatype(size, lb, ub, flags) + , block_count_(count) + , block_lengths_(new int[count]) + , block_indices_(new MPI_Aint[count]) + , old_type_(old_type) { old_type_->ref(); - block_lengths_ = new int[count]; - block_indices_ = new MPI_Aint[count]; for (int i = 0; i < count; i++) { block_lengths_[i] = block_lengths[i]; block_indices_[i] = block_indices[i] * factor; @@ -177,10 +181,14 @@ Type_Indexed::Type_Indexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int co { } -Type_Struct::Type_Struct(int size,MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths, const MPI_Aint* block_indices, const MPI_Datatype* old_types): Datatype(size, lb, ub, flags), block_count_(count){ - block_lengths_= new int[count]; - block_indices_= new MPI_Aint[count]; - old_types_= new MPI_Datatype[count]; +Type_Struct::Type_Struct(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths, + const MPI_Aint* block_indices, const MPI_Datatype* old_types) + : Datatype(size, lb, ub, flags) + , block_count_(count) + , block_lengths_(new int[count]) + , block_indices_(new MPI_Aint[count]) + , old_types_(new MPI_Datatype[count]) +{ for (int i = 0; i < count; i++) { block_lengths_[i]=block_lengths[i]; block_indices_[i]=block_indices[i]; diff --git a/src/smpi/mpi/smpi_win.cpp b/src/smpi/mpi/smpi_win.cpp index c7450299fe..19ca7bec3b 100644 --- a/src/smpi/mpi/smpi_win.cpp +++ b/src/smpi/mpi/smpi_win.cpp @@ -22,12 +22,20 @@ namespace smpi{ std::unordered_map Win::keyvals_; int Win::keyval_id_=0; -Win::Win(void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, int allocated, int dynamic): base_(base), size_(size), disp_unit_(disp_unit), assert_(0), info_(info), comm_(comm), allocated_(allocated), dynamic_(dynamic){ - int comm_size = comm->size(); - rank_ = comm->rank(); +Win::Win(void* base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, int allocated, int dynamic) + : base_(base) + , size_(size) + , disp_unit_(disp_unit) + , info_(info) + , comm_(comm) + , rank_(comm->rank()) + , allocated_(allocated) + , dynamic_(dynamic) +{ XBT_DEBUG("Creating window"); if(info!=MPI_INFO_NULL) info->ref(); + int comm_size = comm->size(); name_ = nullptr; opened_ = 0; group_ = MPI_GROUP_NULL; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index b97d8fa965..53da8a24e7 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -222,7 +222,6 @@ CpuTiTmgr::CpuTiTmgr(kernel::profile::Profile* speed_profile, double value) : sp /* no availability file, fixed trace */ if (not speed_profile) { - type_ = Type::FIXED; value_ = value; XBT_DEBUG("No availability trace. Constant value = %f", value); return; @@ -230,7 +229,6 @@ CpuTiTmgr::CpuTiTmgr(kernel::profile::Profile* speed_profile, double value) : sp /* only one point available, fixed trace */ if (speed_profile->event_list.size() == 1) { - type_ = Type::FIXED; value_ = speed_profile->event_list.front().value_; return; } diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index d2cfa0e045..823149a421 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -45,7 +45,7 @@ class CpuTiTmgr { }; public: - explicit CpuTiTmgr(double value) : type_(Type::FIXED), value_(value){}; + explicit CpuTiTmgr(double value) : value_(value){}; CpuTiTmgr(profile::Profile* speed_profile, double value); CpuTiTmgr(const CpuTiTmgr&) = delete; CpuTiTmgr& operator=(const CpuTiTmgr&) = delete; @@ -55,7 +55,7 @@ public: double get_power_scale(double a); private: - Type type_; + Type type_ = Type::FIXED; double value_; /*< Percentage of cpu speed available. Value fixed between 0 and 1 */ /* Dynamic */ diff --git a/src/surf/network_ib.hpp b/src/surf/network_ib.hpp index ee3367768e..2d843a7f36 100644 --- a/src/surf/network_ib.hpp +++ b/src/surf/network_ib.hpp @@ -19,13 +19,10 @@ namespace resource { class XBT_PRIVATE IBNode; -class XBT_PRIVATE ActiveComm { -public: - IBNode* destination; - NetworkAction* action; - double init_rate; - ActiveComm() : destination(nullptr), action(nullptr), init_rate(-1){}; - virtual ~ActiveComm() = default; +struct XBT_PRIVATE ActiveComm { + IBNode* destination = nullptr; + NetworkAction* action = nullptr; + double init_rate = -1; }; class IBNode { @@ -36,8 +33,8 @@ public: // store the number of comms received from each node std::map ActiveCommsDown; // number of comms the node is receiving - int nbActiveCommsDown; - explicit IBNode(int id) : id(id), nbActiveCommsDown(0){}; + int nbActiveCommsDown = 0; + explicit IBNode(int id) : id(id){}; virtual ~IBNode() = default; }; diff --git a/src/xbt/backtrace.cpp b/src/xbt/backtrace.cpp index 17f5e9c7bf..5ed2b0a096 100644 --- a/src/xbt/backtrace.cpp +++ b/src/xbt/backtrace.cpp @@ -83,17 +83,16 @@ Backtrace::Backtrace() impl_->st = boost::stacktrace::stacktrace(); #endif } -Backtrace::Backtrace(const Backtrace& bt) + +Backtrace::Backtrace(const Backtrace& bt) : impl_(bt.impl_) { - impl_ = bt.impl_; if (impl_) impl_->ref(); } Backtrace::Backtrace(Backtrace&& bt) { - impl_ = bt.impl_; - bt.impl_ = nullptr; + std::swap(impl_, bt.impl_); } Backtrace& Backtrace::operator=(const Backtrace& rhs)