mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 21:21:37 +00:00
- Report uses of a MessagePtr after a Send() whose result is discarded. After the send the message is empty with zeromq, and still points to the sent buffer with shmem, so the same code acts differently per transport. - Walk the CFG from the send with ExprSequence, like bugprone-use-after-move. A loop back to the send counts as a use. - Assignment, reset(), Rebuild(), a new declaration in a loop and passing by non-const reference (e.g. to Receive()) give a new message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
#include <fairmq/Device.h>
|
|
|
|
#include <cstring>
|
|
|
|
struct Sampler : fair::mq::Device
|
|
{
|
|
bool ConditionalRun() override
|
|
{
|
|
auto msg(NewMessage(16));
|
|
Send(msg, "data");
|
|
// CHECK-MESSAGES: :[[@LINE+1]]:21: warning: 'msg' is used after it was sent; a sent message is empty (zeromq) or shared with the receiver (shmem) [fairmq-bugprone-use-after-send]
|
|
std::memset(msg->GetData(), 0, 16);
|
|
return true;
|
|
}
|
|
|
|
void Run() override
|
|
{
|
|
fair::mq::MessagePtr msg(NewMessage(16));
|
|
while (!NewStatePending()) {
|
|
// CHECK-MESSAGES: :[[@LINE+1]]:18: warning: 'msg' is used after it was sent; a sent message is empty (zeromq) or shared with the receiver (shmem) [fairmq-bugprone-use-after-send]
|
|
Send(msg, "data");
|
|
}
|
|
}
|
|
|
|
void Branch(bool flag)
|
|
{
|
|
auto msg(NewMessage(16));
|
|
GetChannel("data").Send(msg);
|
|
if (flag) {
|
|
// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: 'msg' is used after it was sent; a sent message is empty (zeromq) or shared with the receiver (shmem) [fairmq-bugprone-use-after-send]
|
|
auto size = msg->GetSize();
|
|
static_cast<void>(size);
|
|
}
|
|
}
|
|
|
|
// Not reported below.
|
|
void NewEachIteration()
|
|
{
|
|
while (!NewStatePending()) {
|
|
auto msg(NewMessage(16));
|
|
Send(msg, "data");
|
|
}
|
|
}
|
|
|
|
void Reinit()
|
|
{
|
|
auto msg(NewMessage(16));
|
|
Send(msg, "data");
|
|
msg = NewMessage(8);
|
|
Send(msg, "data");
|
|
msg->Rebuild(4);
|
|
Send(msg, "data");
|
|
Receive(msg, "data");
|
|
static_cast<void>(msg->GetSize());
|
|
Send(msg, "data");
|
|
msg.reset();
|
|
}
|
|
|
|
void Checked()
|
|
{
|
|
auto msg(NewMessage(16));
|
|
if (Send(msg, "data") < 0) {
|
|
static_cast<void>(msg->GetSize());
|
|
}
|
|
}
|
|
|
|
void Parts()
|
|
{
|
|
fair::mq::Parts parts;
|
|
Send(parts, "data");
|
|
static_cast<void>(parts.Size());
|
|
}
|
|
};
|