Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sonar fixes
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 18 Feb 2022 07:17:42 +0000 (08:17 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 18 Feb 2022 18:24:36 +0000 (19:24 +0100)
- use uintptr_t instead of void* on the Checker side.
  They cannot be dereferenced anyway.
- various small things (const, remove empty statements)

src/kernel/actor/SimcallObserver.cpp
src/mc/api/TransitionComm.cpp
src/mc/api/TransitionComm.hpp
src/mc/checker/CommunicationDeterminismChecker.cpp

index 9727778..3ee3402 100644 (file)
@@ -134,11 +134,11 @@ static void serialize_activity_test(const activity::ActivityImpl* act, std::stri
 {
   if (auto* comm = dynamic_cast<activity::CommImpl const*>(act)) {
     stream << "  " << (short)mc::Transition::Type::COMM_TEST;
-    stream << ' ' << (void*)comm;
+    stream << ' ' << (uintptr_t)comm;
     stream << ' ' << (comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1);
     stream << ' ' << (comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1);
     stream << ' ' << comm->get_mailbox_id();
-    stream << ' ' << (void*)comm->src_buff_ << ' ' << (void*)comm->dst_buff_ << ' ' << comm->src_buff_size_;
+    stream << ' ' << (uintptr_t)comm->src_buff_ << ' ' << (uintptr_t)comm->dst_buff_ << ' ' << comm->src_buff_size_;
   } else {
     stream << (short)mc::Transition::Type::UNKNOWN;
   }
@@ -159,12 +159,12 @@ static void serialize_activity_wait(const activity::ActivityImpl* act, bool time
 {
   if (auto* comm = dynamic_cast<activity::CommImpl const*>(act)) {
     stream << (short)mc::Transition::Type::COMM_WAIT << ' ';
-    stream << timeout << ' ' << comm;
+    stream << timeout << ' ' << (uintptr_t)comm;
 
     stream << ' ' << (comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1);
     stream << ' ' << (comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1);
     stream << ' ' << comm->get_mailbox_id();
-    stream << ' ' << (void*)comm->src_buff_ << ' ' << (void*)comm->dst_buff_ << ' ' << comm->src_buff_size_;
+    stream << ' ' << (uintptr_t)comm->src_buff_ << ' ' << (uintptr_t)comm->dst_buff_ << ' ' << comm->src_buff_size_;
   } else {
     stream << (short)mc::Transition::Type::UNKNOWN;
   }
@@ -237,14 +237,14 @@ void ActivityWaitanySimcall::prepare(int times_considered)
 void CommIsendSimcall::serialize(std::stringstream& stream) const
 {
   stream << (short)mc::Transition::Type::COMM_SEND << ' ';
-  stream << (void*)comm_ << ' ' << mbox_->get_id() << ' ' << (void*)src_buff_ << ' ' << src_buff_size_;
+  stream << (uintptr_t)comm_ << ' ' << mbox_->get_id() << ' ' << (uintptr_t)src_buff_ << ' ' << src_buff_size_;
   XBT_DEBUG("SendObserver mbox:%u buff:%p size:%zu", mbox_->get_id(), src_buff_, src_buff_size_);
 }
 
 void CommIrecvSimcall::serialize(std::stringstream& stream) const
 {
   stream << (short)mc::Transition::Type::COMM_RECV << ' ';
-  stream << (void*)comm_ << ' ' << mbox_->get_id() << ' ' << (void*)dst_buff_;
+  stream << (uintptr_t)comm_ << ' ' << mbox_->get_id() << ' ' << (uintptr_t)dst_buff_;
 }
 
 } // namespace actor
index 0a846d6..ff40128 100644 (file)
@@ -23,17 +23,17 @@ namespace mc {
 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
     : Transition(Type::COMM_WAIT, issuer, times_considered)
 {
-  xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_);
-  XBT_DEBUG("CommWaitTransition %s comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu",
-            (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, src_buff_, dst_buff_, size_);
+  xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
+  XBT_DEBUG("CommWaitTransition %s comm:%lx, sender:%ld receiver:%ld mbox:%u sbuff:%lx rbuff:%lx size:%zu",
+            (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
 }
 std::string CommWaitTransition::to_string(bool verbose) const
 {
   auto res = xbt::string_printf("%ld: WaitComm(from %ld to %ld, mbox=%u, %s", aid_, sender_, receiver_, mbox_,
                                 (timeout_ ? "timeout" : "no timeout"));
   if (verbose) {
-    res += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
-    res += ", dst_buff=" + xbt::string_printf("%p", dst_buff_);
+    res += ", sbuff=" + xbt::string_printf("%lx", sbuff_) + ", size=" + std::to_string(size_);
+    res += ", rbuff=" + xbt::string_printf("%lx", rbuff_);
   }
   res += ")";
   return res;
@@ -50,10 +50,10 @@ bool CommWaitTransition::depends(const Transition* other) const
     if (timeout_ || wait->timeout_)
       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
 
-    if (src_buff_ == wait->src_buff_ && dst_buff_ == wait->dst_buff_)
+    if (sbuff_ == wait->sbuff_ && rbuff_ == wait->rbuff_)
       return false;
-    if (src_buff_ != nullptr && dst_buff_ != nullptr && wait->src_buff_ != nullptr && wait->dst_buff_ != nullptr &&
-        dst_buff_ != wait->src_buff_ && dst_buff_ != wait->dst_buff_ && dst_buff_ != src_buff_)
+    if (sbuff_ != 0 && rbuff_ != 0 && wait->sbuff_ != 0 && wait->rbuff_ != 0 && rbuff_ != wait->sbuff_ &&
+        rbuff_ != wait->rbuff_ && rbuff_ != sbuff_)
       return false;
   }
 
@@ -62,16 +62,16 @@ bool CommWaitTransition::depends(const Transition* other) const
 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
     : Transition(Type::COMM_TEST, issuer, times_considered)
 {
-  xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_);
-  XBT_DEBUG("CommTestTransition comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu", comm_, sender_,
-            receiver_, mbox_, src_buff_, dst_buff_, size_);
+  xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
+  XBT_DEBUG("CommTestTransition comm:%lx, sender:%ld receiver:%ld mbox:%u sbuff:%lx rbuff:%lx size:%zu", comm_, sender_,
+            receiver_, mbox_, sbuff_, rbuff_, size_);
 }
 std::string CommTestTransition::to_string(bool verbose) const
 {
   auto res = xbt::string_printf("%ld: TestComm(from %ld to %ld, mbox=%u", aid_, sender_, receiver_, mbox_);
   if (verbose) {
-    res += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
-    res += ", dst_buff=" + xbt::string_printf("%p", dst_buff_);
+    res += ", sbuff=" + xbt::string_printf("%lx", sbuff_) + ", size=" + std::to_string(size_);
+    res += ", rbuff=" + xbt::string_printf("%lx", rbuff_);
   }
   res += ")";
   return res;
@@ -101,13 +101,13 @@ bool CommTestTransition::depends(const Transition* other) const
 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
     : Transition(Type::COMM_RECV, issuer, times_considered)
 {
-  xbt_assert(stream >> comm_ >> mbox_ >> dst_buff_);
+  xbt_assert(stream >> comm_ >> mbox_ >> rbuff_);
 }
 std::string CommRecvTransition::to_string(bool verbose) const
 {
   auto res = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_);
   if (verbose)
-    res += ", buff=" + xbt::string_printf("%p", dst_buff_);
+    res += ", rbuff=" + xbt::string_printf("%lx", rbuff_);
   res += ")";
   return res;
 }
@@ -129,7 +129,7 @@ bool CommRecvTransition::depends(const Transition* other) const
     if (mbox_ != test->mbox_)
       return false;
 
-    if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->dst_buff_ != dst_buff_))
+    if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
       return false;
   }
 
@@ -140,7 +140,7 @@ bool CommRecvTransition::depends(const Transition* other) const
     if (mbox_ != wait->mbox_)
       return false;
 
-    if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->dst_buff_ != dst_buff_))
+    if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
       return false;
   }
 
@@ -150,14 +150,14 @@ bool CommRecvTransition::depends(const Transition* other) const
 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
     : Transition(Type::COMM_SEND, issuer, times_considered)
 {
-  xbt_assert(stream >> comm_ >> mbox_ >> src_buff_ >> size_);
-  XBT_DEBUG("SendTransition comm:%p mbox:%u buff:%p size:%zu", comm_, mbox_, src_buff_, size_);
+  xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_);
+  XBT_DEBUG("SendTransition comm:%lx mbox:%u sbuff:%lx size:%ld", comm_, mbox_, sbuff_, size_);
 }
 std::string CommSendTransition::to_string(bool verbose = false) const
 {
   auto res = xbt::string_printf("%ld: iSend(mbox=%u", aid_, mbox_);
   if (verbose)
-    res += ", buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
+    res += ", sbuff=" + xbt::string_printf("%lx", sbuff_) + ", size=" + std::to_string(size_);
   res += ")";
   return res;
 }
@@ -225,7 +225,7 @@ bool CommSendTransition::depends(const Transition* other) const
     if (mbox_ != test->mbox_)
       return false;
 
-    if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->src_buff_ != src_buff_))
+    if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
       return false;
   }
 
@@ -236,7 +236,7 @@ bool CommSendTransition::depends(const Transition* other) const
     if (mbox_ != wait->mbox_)
       return false;
 
-    if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->src_buff_ != src_buff_))
+    if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
       return false;
   }
 
index 9d4a748..d6bbf69 100644 (file)
@@ -22,12 +22,12 @@ class CommTestTransition;
 
 class CommWaitTransition : public Transition {
   bool timeout_;
-  void* comm_;
+  uintptr_t comm_;
   aid_t sender_;
   aid_t receiver_;
   unsigned mbox_;
-  void* src_buff_;
-  void* dst_buff_;
+  uintptr_t sbuff_;
+  uintptr_t rbuff_;
   size_t size_;
   friend CommRecvTransition;
   friend CommSendTransition;
@@ -39,12 +39,12 @@ public:
   bool depends(const Transition* other) const override;
 };
 class CommTestTransition : public Transition {
-  void* comm_;
+  uintptr_t comm_;
   aid_t sender_;
   aid_t receiver_;
   unsigned mbox_;
-  void* src_buff_;
-  void* dst_buff_;
+  uintptr_t sbuff_;
+  uintptr_t rbuff_;
   size_t size_;
   friend CommSendTransition;
   friend CommRecvTransition;
@@ -56,9 +56,9 @@ public:
 };
 
 class CommRecvTransition : public Transition {
-  void* comm_; /* Addr of the CommImpl */
+  uintptr_t comm_; /* Addr of the CommImpl */
   unsigned mbox_;
-  void* dst_buff_;
+  uintptr_t rbuff_;
 
 public:
   CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream);
@@ -67,9 +67,9 @@ public:
 };
 
 class CommSendTransition : public Transition {
-  void* comm_; /* Addr of the CommImpl */
+  uintptr_t comm_; /* Addr of the CommImpl */
   unsigned mbox_;
-  void* src_buff_;
+  uintptr_t sbuff_;
   size_t size_;
 
 public:
index 7bf5134..69f2ab2 100644 (file)
@@ -101,11 +101,11 @@ struct CommDetExtension {
   std::string send_diff;
   std::string recv_diff;
 
-  void restore_communications_pattern(simgrid::mc::State* state);
+  void restore_communications_pattern(const simgrid::mc::State* state);
   void deterministic_comm_pattern(aid_t process, const PatternCommunication* comm, bool backtracking);
   void get_comm_pattern(smx_simcall_t request, CallType call_type, bool backtracking);
   void complete_comm_pattern(RemotePtr<kernel::activity::CommImpl> const& comm_addr, aid_t issuer, bool backtracking);
-  void handle_comm_pattern(Transition* transition, smx_simcall_t req, int value, bool backtracking);
+  void handle_comm_pattern(const Transition* transition, smx_simcall_t req, int value, bool backtracking);
 };
 simgrid::xbt::Extension<simgrid::mc::Checker, CommDetExtension> CommDetExtension::EXTENSION_ID;
 /********** State Extension ***********/
@@ -166,7 +166,7 @@ static simgrid::mc::CommPatternDifference compare_comm_pattern(const simgrid::mc
   return CommPatternDifference::NONE;
 }
 
-void CommDetExtension::restore_communications_pattern(simgrid::mc::State* state)
+void CommDetExtension::restore_communications_pattern(const simgrid::mc::State* state)
 {
   for (size_t i = 0; i < initial_communications_pattern.size(); i++)
     initial_communications_pattern[i].index_comm =
@@ -453,7 +453,8 @@ void CommunicationDeterminismChecker::restoreState()
   }
 }
 
-void CommDetExtension::handle_comm_pattern(Transition* transition, smx_simcall_t req, int value, bool backtracking)
+void CommDetExtension::handle_comm_pattern(const Transition* transition, smx_simcall_t req, int value,
+                                           bool backtracking)
 {
   if (not _sg_mc_comms_determinism && not _sg_mc_send_determinism)
     return;
@@ -476,7 +477,6 @@ void CommDetExtension::handle_comm_pattern(Transition* transition, smx_simcall_t
     }
     case CallType::WAITANY: {
       auto comm_addr = api::get().get_comm_waitany_raw_addr(req, value);
-      ;
       auto simcall_issuer = api::get().simcall_get_issuer(req);
       complete_comm_pattern(comm_addr, simcall_issuer->get_pid(), backtracking);
     } break;