Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Replace redundant type with "auto" (src/mc/).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 3 Oct 2020 20:34:45 +0000 (22:34 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 4 Oct 2020 20:18:38 +0000 (22:18 +0200)
12 files changed:
src/mc/checker/LivenessChecker.cpp
src/mc/checker/simgrid_mc.cpp
src/mc/compare.cpp
src/mc/inspect/LocationList.cpp
src/mc/inspect/mc_dwarf.cpp
src/mc/inspect/mc_unw.cpp
src/mc/inspect/mc_unw_vmread.cpp
src/mc/mc_comm_pattern.cpp
src/mc/mc_smx.cpp
src/mc/remote/RemoteSimulation.cpp
src/mc/sosp/Snapshot.cpp
src/mc/sosp/Snapshot_test.cpp

index 37bf222..3a690f4 100644 (file)
@@ -82,9 +82,8 @@ std::shared_ptr<const std::vector<int>> LivenessChecker::get_proposition_values(
 
 std::shared_ptr<VisitedPair> LivenessChecker::insert_acceptance_pair(simgrid::mc::Pair* pair)
 {
-  std::shared_ptr<VisitedPair> new_pair = std::make_shared<VisitedPair>(
-    pair->num, pair->automaton_state, pair->atomic_propositions,
-    pair->graph_state);
+  auto new_pair =
+      std::make_shared<VisitedPair>(pair->num, pair->automaton_state, pair->atomic_propositions, pair->graph_state);
 
   auto res = boost::range::equal_range(acceptance_pairs_, new_pair.get(), DerefAndCompareByActorsCountAndUsedHeap());
 
@@ -264,7 +263,7 @@ std::shared_ptr<Pair> LivenessChecker::create_pair(const Pair* current_pair, xbt
                                                    std::shared_ptr<const std::vector<int>> propositions)
 {
   expanded_pairs_count_++;
-  std::shared_ptr<Pair> next_pair = std::make_shared<Pair>(expanded_pairs_count_);
+  auto next_pair                  = std::make_shared<Pair>(expanded_pairs_count_);
   next_pair->automaton_state      = state;
   next_pair->graph_state          = std::make_shared<State>(++expanded_states_count_);
   next_pair->atomic_propositions  = std::move(propositions);
index ff0fda6..9168cc9 100644 (file)
@@ -22,7 +22,7 @@
 static inline
 char** argvdup(int argc, char** argv)
 {
-  char** argv_copy = new char*[argc + 1];
+  auto* argv_copy = new char*[argc + 1];
   std::memcpy(argv_copy, argv, sizeof(char*) * argc);
   argv_copy[argc] = nullptr;
   return argv_copy;
index f13a96a..aec0a0c 100644 (file)
@@ -242,10 +242,10 @@ static bool mmalloc_heap_differ(StateComparator& state, const Snapshot& snapshot
       snapshot2.read<malloc_info*>(RemotePtr<malloc_info*>((std::uint64_t)heapinfo_address));
 
   while (i1 < state.heaplimit) {
-    const malloc_info* heapinfo1 =
-        (const malloc_info*)heap_region1->read(&heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
-    const malloc_info* heapinfo2 =
-        (const malloc_info*)heap_region2->read(&heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
+    const auto* heapinfo1 =
+        static_cast<malloc_info*>(heap_region1->read(&heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info)));
+    const auto* heapinfo2 =
+        static_cast<malloc_info*>(heap_region2->read(&heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info)));
 
     if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) {      /* Free block */
       i1 ++;
@@ -295,8 +295,8 @@ static bool mmalloc_heap_differ(StateComparator& state, const Snapshot& snapshot
           continue;
         }
 
-        const malloc_info* heapinfo2b =
-            (const malloc_info*)heap_region2->read(&heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
+        const auto* heapinfo2b =
+            static_cast<malloc_info*>(heap_region2->read(&heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info)));
 
         if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
           i2++;
@@ -331,7 +331,7 @@ static bool mmalloc_heap_differ(StateComparator& state, const Snapshot& snapshot
         if (state.equals_to_<1>(i1, j1).valid_)
           continue;
 
-        void* addr_frag1 = (void*)((char*)addr_block1 + (j1 << heapinfo1->type));
+        void* addr_frag1 = (char*)addr_block1 + (j1 << heapinfo1->type);
 
         size_t i2 = 1;
         bool equal = false;
@@ -345,8 +345,8 @@ static bool mmalloc_heap_differ(StateComparator& state, const Snapshot& snapshot
         }
 
         while (i2 < state.heaplimit && not equal) {
-          const malloc_info* heapinfo2b =
-              (const malloc_info*)heap_region2->read(&heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
+          const auto* heapinfo2b =
+              static_cast<malloc_info*>(heap_region2->read(&heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info)));
 
           if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
             i2 ++;
@@ -391,8 +391,8 @@ static bool mmalloc_heap_differ(StateComparator& state, const Snapshot& snapshot
 
   /* All blocks/fragments are equal to another block/fragment_ ? */
   for (size_t i = 1; i < state.heaplimit; i++) {
-    const malloc_info* heapinfo1 =
-        (const malloc_info*)heap_region1->read(&heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
+    const auto* heapinfo1 =
+        static_cast<malloc_info*>(heap_region1->read(&heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info)));
 
     if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo1->busy_block.busy_size > 0 &&
         not state.equals_to_<1>(i, 0).valid_) {
@@ -410,8 +410,8 @@ static bool mmalloc_heap_differ(StateComparator& state, const Snapshot& snapshot
   }
 
   for (size_t i = 1; i < state.heaplimit; i++) {
-    const malloc_info* heapinfo2 =
-        (const malloc_info*)heap_region2->read(&heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
+    const auto* heapinfo2 =
+        static_cast<malloc_info*>(heap_region2->read(&heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info)));
     if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo2->busy_block.busy_size > 0 &&
         not state.equals_to_<2>(i, 0).valid_) {
       XBT_DEBUG("Block %zu not found (size used = %zu)", i,
@@ -810,10 +810,10 @@ static bool heap_area_differ(StateComparator& state, const void* area1, const vo
   const Region* heap_region1 = MC_get_heap_region(snapshot1);
   const Region* heap_region2 = MC_get_heap_region(snapshot2);
 
-  const malloc_info* heapinfo1 =
-      (const malloc_info*)heap_region1->read(&heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
-  const malloc_info* heapinfo2 =
-      (const malloc_info*)heap_region2->read(&heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
+  const auto* heapinfo1 =
+      static_cast<malloc_info*>(heap_region1->read(&heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info)));
+  const auto* heapinfo2 =
+      static_cast<malloc_info*>(heap_region2->read(&heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info)));
 
   if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
     && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
@@ -877,8 +877,8 @@ static bool heap_area_differ(StateComparator& state, const void* area1, const vo
     ssize_t frag2 = (ADDR2UINT(area2) % BLOCKSIZE) >> heapinfo2->type;
 
     // Process address of the fragment_:
-    void* real_addr_frag1 = (void*)((char*)real_addr_block1 + (frag1 << heapinfo1->type));
-    void* real_addr_frag2 = (void*)((char*)real_addr_block2 + (frag2 << heapinfo2->type));
+    void* real_addr_frag1 = (char*)real_addr_block1 + (frag1 << heapinfo1->type);
+    void* real_addr_frag2 = (char*)real_addr_block2 + (frag2 << heapinfo2->type);
 
     // Check the size of the fragments against the size of the type:
     if (type_size != -1) {
index 07c7c3d..212c25e 100644 (file)
@@ -79,7 +79,7 @@ LocationList location_list(const simgrid::mc::ObjectInformation& info, Dwarf_Att
     else if (offset == -1)
       xbt_die("Error while loading location list");
 
-    std::uint64_t base_address = (std::uint64_t)info.base_address();
+    auto base_address = reinterpret_cast<std::uint64_t>(info.base_address());
 
     LocationListEntry::range_type range;
     if (start == 0)
index efd6755..a6d44f9 100644 (file)
@@ -688,9 +688,9 @@ static std::unique_ptr<simgrid::mc::Variable> MC_die_to_variable(simgrid::mc::Ob
 
         if (len == 1 && expr[0].atom == DW_OP_addr) {
           variable->global  = true;
-          uintptr_t offset  = (uintptr_t)expr[0].number;
-          uintptr_t base    = (uintptr_t)info->base_address();
-          variable->address = (void*)(base + offset);
+          auto offset       = static_cast<uintptr_t>(expr[0].number);
+          auto base         = reinterpret_cast<uintptr_t>(info->base_address());
+          variable->address = reinterpret_cast<void*>(base + offset);
         } else
           variable->location_list = {
               simgrid::dwarf::LocationListEntry(simgrid::dwarf::DwarfExpression(expr, expr + len))};
@@ -784,7 +784,7 @@ static void MC_dwarf_handle_scope_die(simgrid::mc::ObjectInformation* info, Dwar
   // This is the base address for DWARF addresses.
   // Relocated addresses are offset from this base address.
   // See DWARF4 spec 7.5
-  std::uint64_t base = (std::uint64_t)info->base_address();
+  auto base = reinterpret_cast<std::uint64_t>(info->base_address());
 
   // TODO, support DW_AT_ranges
   uint64_t low_pc     = MC_dwarf_attr_integrate_addr(die, DW_AT_low_pc);
@@ -1190,8 +1190,8 @@ namespace mc {
 /** @brief Finds information about a given shared object/executable */
 std::shared_ptr<ObjectInformation> createObjectInformation(std::vector<xbt::VmMap> const& maps, const char* name)
 {
-  std::shared_ptr<ObjectInformation> result = std::make_shared<ObjectInformation>();
-  result->file_name                         = name;
+  auto result       = std::make_shared<ObjectInformation>();
+  result->file_name = name;
   simgrid::mc::find_object_address(maps, result.get());
   MC_load_dwarf(result.get());
   MC_post_process_variables(result.get());
index a9c273f..509c765 100644 (file)
@@ -172,8 +172,8 @@ void* UnwindContext::get_reg(unw_context_t* context, unw_regnum_t regnum) noexce
 int UnwindContext::access_reg(unw_addr_space_t /*as*/, unw_regnum_t regnum, unw_word_t* valp, int write,
                               void* arg) noexcept
 {
-  simgrid::mc::UnwindContext* as_context = (simgrid::mc::UnwindContext*)arg;
-  unw_context_t* context                 = &as_context->unwind_context_;
+  auto* as_context       = static_cast<simgrid::mc::UnwindContext*>(arg);
+  unw_context_t* context = &as_context->unwind_context_;
   if (write)
     return -UNW_EREADONLYREG;
   const greg_t* preg = (greg_t*)get_reg(context, regnum);
index 08e6bfa..f44e404 100644 (file)
@@ -66,8 +66,8 @@ static int access_mem(const unw_addr_space_t as, const unw_word_t addr, unw_word
   // On recent kernels, we do not need to ptrace the target process.
   // On older kernels, it is necessary to ptrace the target process.
   size_t count = size;
-  off_t off    = (off_t)addr;
-  char* buf    = (char*)valp;
+  auto off     = static_cast<off_t>(addr);
+  auto* buf    = reinterpret_cast<char*>(valp);
   int fd       = simgrid::mc::open_vm(pid, O_RDONLY);
   if (fd < 0)
     return -UNW_EINVAL;
index 661d830..d2fb5e6 100644 (file)
@@ -15,7 +15,7 @@ static void MC_patterns_copy(std::vector<simgrid::mc::PatternCommunication*>& de
 {
   dest.clear();
   for (simgrid::mc::PatternCommunication const& comm : source) {
-    simgrid::mc::PatternCommunication* copy_comm = new simgrid::mc::PatternCommunication(comm.dup());
+    auto* copy_comm = new simgrid::mc::PatternCommunication(comm.dup());
     dest.push_back(copy_comm);
   }
 }
@@ -50,8 +50,7 @@ void MC_state_copy_index_communications_pattern(simgrid::mc::State* state)
 void MC_handle_comm_pattern(e_mc_call_type_t call_type, smx_simcall_t req, int value, int backtracking)
 {
   // HACK, do not rely on the Checker implementation outside of it
-  simgrid::mc::CommunicationDeterminismChecker* checker =
-    (simgrid::mc::CommunicationDeterminismChecker*) mc_model_checker->getChecker();
+  auto* checker = static_cast<simgrid::mc::CommunicationDeterminismChecker*>(mc_model_checker->getChecker());
 
   switch(call_type) {
   case MC_CALL_TYPE_NONE:
index d9ba8b9..417758d 100644 (file)
@@ -21,7 +21,7 @@ static inline simgrid::mc::ActorInformation* actor_info_cast(smx_actor_t actor)
   simgrid::mc::ActorInformation temp;
   std::size_t offset = (char*)temp.copy.get_buffer() - (char*)&temp;
 
-  simgrid::mc::ActorInformation* process_info = (simgrid::mc::ActorInformation*)((char*)actor - offset);
+  auto* process_info = reinterpret_cast<simgrid::mc::ActorInformation*>((char*)actor - offset);
   return process_info;
 }
 
@@ -40,7 +40,7 @@ static void MC_process_refresh_simix_actor_dynar(const simgrid::mc::RemoteSimula
   s_xbt_dynar_t dynar;
   process->read_bytes(&dynar, sizeof(dynar), remote_dynar);
 
-  smx_actor_t* data = static_cast<smx_actor_t*>(::operator new(dynar.elmsize * dynar.used));
+  auto* data = static_cast<smx_actor_t*>(::operator new(dynar.elmsize * dynar.used));
   process->read_bytes(data, dynar.elmsize * dynar.used, simgrid::mc::RemotePtr<void>(dynar.data));
 
   // Load each element of the vector from the MCed process:
index e56c9bd..078e3ad 100644 (file)
@@ -146,7 +146,7 @@ static std::string get_lib_name(const std::string& pathname)
 
 static ssize_t pread_whole(int fd, void* buf, size_t count, off_t offset)
 {
-  char* buffer       = (char*)buf;
+  auto* buffer       = static_cast<char*>(buf);
   ssize_t real_count = count;
   while (count) {
     ssize_t res = pread(fd, buffer, count, offset);
@@ -166,7 +166,7 @@ static ssize_t pread_whole(int fd, void* buf, size_t count, off_t offset)
 
 static ssize_t pwrite_whole(int fd, const void* buf, size_t count, off_t offset)
 {
-  const char* buffer = (const char*)buf;
+  const auto* buffer = static_cast<const char*>(buf);
   ssize_t real_count = count;
   while (count) {
     ssize_t res = pwrite(fd, buffer, count, offset);
index ccc1ac9..5393c8f 100644 (file)
@@ -227,7 +227,7 @@ void Snapshot::add_region(RegionType type, ObjectInformation* object_info, void*
   else if (type == RegionType::Heap)
     xbt_assert(not object_info, "Unexpected object info for heap region.");
 
-  Region* region = new Region(type, start_addr, size);
+  auto* region = new Region(type, start_addr, size);
   region->object_info(object_info);
   snapshot_regions_.push_back(std::unique_ptr<Region>(std::move(region)));
 }
index c961a37..79b9485 100644 (file)
@@ -45,7 +45,7 @@ std::unique_ptr<simgrid::mc::RemoteSimulation> snap_test_helper::process = nullp
 
 void snap_test_helper::init_memory(void* mem, size_t size)
 {
-  char* dest = (char*)mem;
+  auto* dest = static_cast<char*>(mem);
   for (size_t i = 0; i < size; ++i) {
     dest[i] = simgrid::xbt::random::uniform_int(0, 0xff);
   }
@@ -71,11 +71,11 @@ snap_test_helper::prologue_return snap_test_helper::prologue(int n)
 
   // Init memory and take snapshots:
   init_memory(source, byte_size);
-  simgrid::mc::Region* region0 = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size);
+  auto* region0 = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size);
   for (int i = 0; i < n; i += 2) {
     init_memory((char*)source + i * xbt_pagesize, xbt_pagesize);
   }
-  simgrid::mc::Region* region = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size);
+  auto* region = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size);
 
   void* destination = mmap(nullptr, byte_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   INFO("Could not allocate destination memory");