Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Replace redundant type with "auto" (src/mc/).
[simgrid.git] / src / mc / inspect / mc_dwarf.cpp
index f6f8601..a6d44f9 100644 (file)
@@ -396,8 +396,7 @@ static uint64_t MC_dwarf_array_element_count(Dwarf_Die* die, Dwarf_Die* unit)
 
   int result = 1;
   Dwarf_Die child;
-  int res;
-  for (res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child)) {
+  for (int res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child)) {
     int child_tag = dwarf_tag(&child);
     if (child_tag == DW_TAG_subrange_type || child_tag == DW_TAG_enumeration_type)
       result *= MC_dwarf_subrange_element_count(&child, unit);
@@ -487,10 +486,9 @@ static void MC_dwarf_fill_member_location(const simgrid::mc::Type* type, simgrid
 static void MC_dwarf_add_members(const simgrid::mc::ObjectInformation* /*info*/, Dwarf_Die* die,
                                  const Dwarf_Die* /*unit*/, simgrid::mc::Type* type)
 {
-  int res;
   Dwarf_Die child;
   xbt_assert(type->members.empty());
-  for (res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child)) {
+  for (int res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child)) {
     int tag = dwarf_tag(&child);
     if (tag == DW_TAG_member || tag == DW_TAG_inheritance) {
       // Skip declarations:
@@ -660,10 +658,10 @@ static std::unique_ptr<simgrid::mc::Variable> MC_die_to_variable(simgrid::mc::Ob
     // No location: do not add it ?
     return nullptr;
 
-  std::unique_ptr<simgrid::mc::Variable> variable = std::unique_ptr<simgrid::mc::Variable>(new simgrid::mc::Variable());
-  variable->id                                    = dwarf_dieoffset(die);
-  variable->global                                = frame == nullptr; // Can be override base on DW_AT_location
-  variable->object_info                           = info;
+  auto variable         = std::make_unique<simgrid::mc::Variable>();
+  variable->id          = dwarf_dieoffset(die);
+  variable->global      = frame == nullptr; // Can be override base on DW_AT_location
+  variable->object_info = info;
 
   const char* name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
   if (name)
@@ -690,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))};
@@ -786,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);
@@ -853,8 +851,7 @@ static void MC_dwarf_handle_children(simgrid::mc::ObjectInformation* info, Dwarf
 {
   // For each child DIE:
   Dwarf_Die child;
-  int res;
-  for (res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child))
+  for (int res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child))
     MC_dwarf_handle_die(info, &child, unit, frame, ns);
 }
 
@@ -1193,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());