Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill an unreachable statement (thanks sonar)
[simgrid.git] / src / mc / compare.cpp
index e7b5ada..a477e83 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008-2016. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2008-2017. 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. */
@@ -23,7 +23,6 @@
 #include "src/internal_config.h"
 
 #include "src/xbt/mmalloc/mmprivate.h"
-#include "src/xbt/ex_interface.h"
 
 #if HAVE_SMPI
 #include "src/smpi/private.h"
@@ -289,8 +288,8 @@ void StateComparator::match_equals(HeapLocationPairs* list)
 void ProcessComparisonState::initHeapInformation(xbt_mheap_t heap,
                         std::vector<simgrid::mc::IgnoredHeapRegion>* i)
 {
-  auto heaplimit = ((struct mdesc *) heap)->heaplimit;
-  this->heapsize = ((struct mdesc *) heap)->heapsize;
+  auto heaplimit  = heap->heaplimit;
+  this->heapsize  = heap->heapsize;
   this->to_ignore = i;
   this->equals_to.assign(heaplimit * MAX_FRAGMENT_PER_BLOCK, HeapArea());
   this->types.assign(heaplimit * MAX_FRAGMENT_PER_BLOCK, nullptr);
@@ -300,13 +299,9 @@ int StateComparator::initHeapInformation(xbt_mheap_t heap1, xbt_mheap_t heap2,
                           std::vector<simgrid::mc::IgnoredHeapRegion>* i1,
                           std::vector<simgrid::mc::IgnoredHeapRegion>* i2)
 {
-  if ((((struct mdesc *) heap1)->heaplimit !=
-       ((struct mdesc *) heap2)->heaplimit)
-      ||
-      ((((struct mdesc *) heap1)->heapsize !=
-        ((struct mdesc *) heap2)->heapsize)))
+  if ((heap1->heaplimit != heap2->heaplimit) || (heap1->heapsize != heap2->heapsize))
     return -1;
-  this->heaplimit = ((struct mdesc *) heap1)->heaplimit;
+  this->heaplimit     = heap1->heaplimit;
   this->std_heap_copy = *mc_model_checker->process().get_heap();
   this->processStates[0].initHeapInformation(heap1, i1);
   this->processStates[1].initHeapInformation(heap2, i2);
@@ -337,7 +332,6 @@ int mmalloc_compare_heap(
   int equal, res_compare = 0;
 
   /* Check busy blocks */
-
   i1 = 1;
 
   malloc_info heapinfo_temp1, heapinfo_temp2;
@@ -448,7 +442,6 @@ int mmalloc_compare_heap(
         }
 
         i2++;
-
       }
 
       if (!equal) {
@@ -510,7 +503,7 @@ int mmalloc_compare_heap(
           }
 
           if (heapinfo2b->type < 0) {
-            fprintf(stderr, "Unkown mmalloc block type.\n");
+            fprintf(stderr, "Unknown mmalloc block type.\n");
             abort();
           }
 
@@ -537,11 +530,9 @@ int mmalloc_compare_heap(
               equal = 1;
               break;
             }
-
           }
 
           i2++;
-
         }
 
         if (!equal) {
@@ -554,13 +545,10 @@ int mmalloc_compare_heap(
           nb_diff1++;
           break;
         }
-
       }
 
       i1++;
-
     }
-
   }
 
   /* All blocks/fragments are equal to another block/fragment ? */
@@ -715,7 +703,7 @@ static int compare_heap_area_without_type(
  * @param snapshot1      Snapshot of state 1
  * @param snapshot2      Snapshot of state 2
  * @param previous
- * @param type_id
+ * @param type
  * @param area_size      either a byte_size or an elements_count (?)
  * @param check_ignore
  * @param pointer_level
@@ -919,7 +907,6 @@ top:
     return compare_heap_area_without_type(state, process_index, real_area1, real_area2,
                                           snapshot1, snapshot2, previous,
                                           type->byte_size, check_ignore);
-    return 0;
 
   default:
     return 0;
@@ -934,7 +921,7 @@ top:
  *
  * TODO, handle subfields ((*p).bar.foo, (*p)[5].bar…)
  *
- * @param  type_id            DWARF type ID of the root address
+ * @param  type               DWARF type ID of the root address
  * @param  area_size
  * @return                    DWARF type ID for given offset
  */
@@ -1511,12 +1498,12 @@ static int compare_global_variables(
 
     // Compare the global variables separately for each simulates process:
     for (size_t process_index = 0; process_index < process_count; process_index++) {
-      int is_diff = compare_global_variables(state,
-        object_info, process_index,
-        &r1->privatized_data()[process_index],
-        &r2->privatized_data()[process_index],
-        snapshot1, snapshot2);
-      if (is_diff) return 1;
+      if (compare_global_variables(state,
+          object_info, process_index,
+          &r1->privatized_data()[process_index],
+          &r2->privatized_data()[process_index],
+          snapshot1, snapshot2))
+        return 1;
     }
     return 0;
   }
@@ -1628,7 +1615,6 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc:
   simgrid::mc::Process* process = &mc_model_checker->process();
 
   int errors = 0;
-  int res_init;
 
   int hash_result = 0;
   if (_sg_mc_hash) {
@@ -1644,18 +1630,15 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc:
 
   /* Compare enabled processes */
   if (s1->enabled_processes != s2->enabled_processes) {
-      XBT_VERB("(%d - %d) Different enabled processes", num1, num2);
-      // return 1; ??
+    XBT_VERB("(%d - %d) Different amount of enabled processes", num1, num2);
+    return 1;
   }
 
-  unsigned long i = 0;
-  size_t size_used1, size_used2;
-  int is_diff = 0;
-
   /* Compare size of stacks */
-  while (i < s1->stacks.size()) {
-    size_used1 = s1->stack_sizes[i];
-    size_used2 = s2->stack_sizes[i];
+  int is_diff = 0;
+  for (unsigned long i = 0; i < s1->stacks.size(); i++) {
+    size_t size_used1 = s1->stack_sizes[i];
+    size_t size_used2 = s2->stack_sizes[i];
     if (size_used1 != size_used2) {
 #ifdef MC_DEBUG
       XBT_DEBUG("(%d - %d) Different size used in stacks: %zu - %zu", num1, num2, size_used1, size_used2);
@@ -1668,8 +1651,9 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc:
       return 1;
 #endif
     }
-    i++;
   }
+  if (is_diff) // do not proceed if there is any stacks that don't match
+    return 1;
 
   /* Init heap information used in heap comparison algorithm */
   xbt_mheap_t heap1 = (xbt_mheap_t)s1->read_bytes(
@@ -1680,8 +1664,7 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc:
     alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
     remote(process->heap_address),
     simgrid::mc::ProcessIndexMissing, simgrid::mc::ReadOptions::lazy());
-  res_init = state_comparator->initHeapInformation(
-    heap1, heap2, &s1->to_ignore, &s2->to_ignore);
+  int res_init = state_comparator->initHeapInformation(heap1, heap2, &s1->to_ignore, &s2->to_ignore);
 
   if (res_init == -1) {
 #ifdef MC_DEBUG
@@ -1698,9 +1681,6 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc:
 
   /* Stacks comparison */
   int diff_local = 0;
-#ifdef MC_DEBUG
-  is_diff = 0;
-#endif
   for (unsigned int cursor = 0; cursor < s1->stacks.size(); cursor++) {
     mc_snapshot_stack_t stack1 = &s1->stacks[cursor];
     mc_snapshot_stack_t stack2 = &s2->stacks[cursor];
@@ -1749,12 +1729,9 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc:
     std::string const& name = region1->object_info()->file_name;
 
     /* Compare global variables */
-    is_diff =
-      compare_global_variables(*state_comparator,
-        region1->object_info(), simgrid::mc::ProcessIndexDisabled,
-        region1, region2, s1, s2);
+    if (compare_global_variables(*state_comparator, region1->object_info(), simgrid::mc::ProcessIndexDisabled, region1,
+                                 region2, s1, s2)) {
 
-    if (is_diff != 0) {
 #ifdef MC_DEBUG
       XBT_DEBUG("(%d - %d) Different global variables in %s",
         num1, num2, name.c_str());