From: Arnaud Giersch Date: Wed, 2 Nov 2022 22:33:20 +0000 (+0100) Subject: Don't call function with side effect twice in the same expression. X-Git-Tag: v3.34~713 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cb3dc054a94868005896ba9485179c2ab5280876 Don't call function with side effect twice in the same expression. The evaluation order is undecided and may give different results (e.g. using clang vs. gcc). --- diff --git a/src/kernel/actor/CommObserver.cpp b/src/kernel/actor/CommObserver.cpp index 983ba9483d..73eb450b64 100644 --- a/src/kernel/actor/CommObserver.cpp +++ b/src/kernel/actor/CommObserver.cpp @@ -61,11 +61,13 @@ template static std::string ptr_to_id(A* ptr) static std::string to_string_activity_test(const activity::ActivityImpl* act) { if (auto* comm = dynamic_cast(act)) { + const std::string src_buff_id = ptr_to_id(comm->src_buff_); + const std::string dst_buff_id = ptr_to_id(comm->dst_buff_); return std::string("CommTest(comm_id:") + ptr_to_id(comm) + " src:" + std::to_string(comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1) + " dst:" + std::to_string(comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1) + - " mbox:" + std::to_string(comm->get_mailbox_id()) + " srcbuf:" + ptr_to_id(comm->src_buff_) + - " dstbuf:" + ptr_to_id(comm->dst_buff_) + " bufsize:" + std::to_string(comm->src_buff_size_); + " mbox:" + std::to_string(comm->get_mailbox_id()) + " srcbuf:" + src_buff_id + " dstbuf:" + dst_buff_id + + " bufsize:" + std::to_string(comm->src_buff_size_); } else { return "TestUnknownType()"; } @@ -112,13 +114,14 @@ static void serialize_activity_wait(const activity::ActivityImpl* act, bool time static std::string to_string_activity_wait(const activity::ActivityImpl* act) { if (auto* comm = dynamic_cast(act)) { + const std::string src_buff_id = ptr_to_id(comm->src_buff_); + const std::string dst_buff_id = ptr_to_id(comm->dst_buff_); return std::string("CommWait(comm_id:") + ptr_to_id(comm) + " src:" + std::to_string(comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1) + " dst:" + std::to_string(comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1) + " mbox:" + std::string(comm->get_mailbox() == nullptr ? xbt::string("-") : comm->get_mailbox()->get_name()) + - "(id:" + std::to_string(comm->get_mailbox_id()) + ") srcbuf:" + ptr_to_id(comm->src_buff_) + - " dstbuf:" + ptr_to_id(comm->dst_buff_) + " bufsize:" + std::to_string(comm->src_buff_size_) + - ")"; + "(id:" + std::to_string(comm->get_mailbox_id()) + ") srcbuf:" + src_buff_id + " dstbuf:" + dst_buff_id + + " bufsize:" + std::to_string(comm->src_buff_size_) + ")"; } else { return "WaitUnknownType()"; }