Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Assert that the pointer is not null when dereferenced.
[simgrid.git] / src / mc / compare.cpp
index 0e3887d..47cfabd 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008-2017. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2008-2019. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 #include "src/mc/ObjectInformation.hpp"
 #include "src/mc/Type.hpp"
 #include "src/mc/Variable.hpp"
+#include "src/mc/mc_config.hpp"
 #include "src/mc/mc_dwarf.hpp"
 #include "src/mc/mc_forward.hpp"
 #include "src/mc/mc_private.hpp"
 #include "src/mc/mc_smx.hpp"
-#include "src/mc/mc_snapshot.hpp"
+#include "src/mc/sosp/mc_snapshot.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, xbt, "Logging specific to mc_compare in mc");
 
@@ -122,7 +123,8 @@ namespace {
  *
  *  It can hash pairs: the standard hash currently doesn't include this.
  */
-template<class X> struct hash : public std::hash<X> {};
+template <class X> class hash : public std::hash<X> {
+};
 
 template <class X, class Y> class hash<std::pair<X, Y>> {
 public:
@@ -343,9 +345,9 @@ int mmalloc_compare_heap(
 
   // This is in snapshot do not use them directly:
   const malloc_info* heapinfos1 = snapshot1->read<malloc_info*>(
-    (std::uint64_t)heapinfo_address, simgrid::mc::ProcessIndexMissing);
+      RemotePtr<malloc_info*>((std::uint64_t)heapinfo_address), simgrid::mc::ProcessIndexMissing);
   const malloc_info* heapinfos2 = snapshot2->read<malloc_info*>(
-    (std::uint64_t)heapinfo_address, simgrid::mc::ProcessIndexMissing);
+      RemotePtr<malloc_info*>((std::uint64_t)heapinfo_address), simgrid::mc::ProcessIndexMissing);
 
   while (i1 < state.heaplimit) {
 
@@ -706,7 +708,6 @@ static int compare_heap_area_with_type(
 
     simgrid::mc::Type* subtype;
     simgrid::mc::Type* subsubtype;
-    int res;
     int elm_size;
     const void* addr_pointed1;
     const void* addr_pointed2;
@@ -730,7 +731,6 @@ static int compare_heap_area_with_type(
           else
             return MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0;
         }
-        break;
 
       case DW_TAG_enumeration_type:
         if (area_size != -1 && type->byte_size != area_size)
@@ -773,13 +773,12 @@ static int compare_heap_area_with_type(
             break;
           default:
             return 0;
-            break;
         }
         for (int i = 0; i < type->element_count; i++) {
           // TODO, add support for variable stride (DW_AT_byte_stride)
-          res = compare_heap_area_with_type(state, process_index, (char*)real_area1 + (i * elm_size),
-                                            (char*)real_area2 + (i * elm_size), snapshot1, snapshot2, previous,
-                                            type->subtype, subtype->byte_size, check_ignore, pointer_level);
+          int res = compare_heap_area_with_type(state, process_index, (char*)real_area1 + (i * elm_size),
+                                                (char*)real_area2 + (i * elm_size), snapshot1, snapshot2, previous,
+                                                type->subtype, subtype->byte_size, check_ignore, pointer_level);
           if (res == 1)
             return res;
         }
@@ -807,6 +806,7 @@ static int compare_heap_area_with_type(
         for (size_t i = 0; i < (area_size / sizeof(void*)); i++) {
           addr_pointed1 = snapshot1->read(remote((void**)((char*)real_area1 + i * sizeof(void*))), process_index);
           addr_pointed2 = snapshot2->read(remote((void**)((char*)real_area2 + i * sizeof(void*))), process_index);
+          int res;
           if (addr_pointed1 > state.std_heap_copy.heapbase && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1) &&
               addr_pointed2 > state.std_heap_copy.heapbase && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
             res = compare_heap_area(state, process_index, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous,
@@ -1031,14 +1031,12 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index,
       return 0;
     }
 
-    if (type_size != -1) {
-      if (type_size != (ssize_t) heapinfo1->busy_block.busy_size
-          && type_size != (ssize_t)   heapinfo2->busy_block.busy_size
-          && (type->name.empty() || type->name == "struct s_smx_context")) {
-        if (match_pairs)
-          state.match_equals(previous);
-        return -1;
-      }
+    if (type_size != -1 && type_size != (ssize_t)heapinfo1->busy_block.busy_size &&
+        type_size != (ssize_t)heapinfo2->busy_block.busy_size &&
+        (type->name.empty() || type->name == "struct s_smx_context")) {
+      if (match_pairs)
+        state.match_equals(previous);
+      return -1;
     }
 
     if (heapinfo1->busy_block.size != heapinfo2->busy_block.size)
@@ -1098,12 +1096,11 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index,
     }
 
     // Check if the blocks are already matched together:
-    if (state.equals_to1_(block1, frag1).valid_ && state.equals_to2_(block2, frag2).valid_) {
-      if (offset1==offset2 && state.fragmentsEqual(block1, frag1, block2, frag2)) {
-        if (match_pairs)
-          state.match_equals(previous);
-        return 0;
-      }
+    if (state.equals_to1_(block1, frag1).valid_ && state.equals_to2_(block2, frag2).valid_ && offset1 == offset2 &&
+        state.fragmentsEqual(block1, frag1, block2, frag2)) {
+      if (match_pairs)
+        state.match_equals(previous);
+      return 0;
     }
     // Compare the size of both fragments:
     if (heapinfo1->busy_frag.frag_size[frag1] != heapinfo2->busy_frag.frag_size[frag2]) {
@@ -1239,6 +1236,7 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state,
   int res;
 
   do {
+    xbt_assert(type != nullptr);
     switch (type->type) {
       case DW_TAG_unspecified_type:
         return 1;
@@ -1281,7 +1279,6 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state,
             break;
           default:
             return 0;
-            break;
         }
         for (i = 0; i < type->element_count; i++) {
           size_t off = i * elm_size;
@@ -1336,7 +1333,6 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state,
 
           return (addr_pointed1 != addr_pointed2);
         }
-        break;
       }
       case DW_TAG_structure_type:
       case DW_TAG_class_type:
@@ -1353,7 +1349,6 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state,
         break;
       case DW_TAG_subroutine_type:
         return -1;
-        break;
       default:
         XBT_VERB("Unknown case: %d", type->type);
         break;
@@ -1383,12 +1378,9 @@ static int compare_global_variables(
       && process_count == r2->privatized_data().size());
 
     // Compare the global variables separately for each simulates process:
-    for (size_t process_index = 0; process_index < process_count; process_index++) {
-      if (compare_global_variables(state,
-          object_info, process_index,
-          &r1->privatized_data()[process_index],
-          &r2->privatized_data()[process_index],
-          snapshot1, snapshot2))
+    for (size_t i = 0; i < process_count; i++) {
+      if (compare_global_variables(state, object_info, i, &r1->privatized_data()[i], &r2->privatized_data()[i],
+                                   snapshot1, snapshot2))
         return 1;
     }
     return 0;