Files
FairMQ/fairmq/tidy/Transfer.cxx
Claude 3b3446bfcb feat(tidy): add fairmq-bugprone-unchecked-transfer-result
- Report Receive() calls whose result is discarded. On a timeout, an
  error or an interrupt the message stays empty, and only the result
  tells.
- Report Send() too with the option CheckSend: true. Off by default,
  because many devices ignore the result of Send() on purpose.
- A cast to void discards the result on purpose and is not reported.
- Add Transfer.h with matchers for Send() and Receive() of Device,
  Channel and Socket, and isDiscarded(), for this and later checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 09:29:18 +00:00

58 lines
2.0 KiB
C++

/********************************************************************************
* Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <fairmq/tidy/Transfer.h>
#include <clang/AST/ParentMapContext.h>
#include <clang/AST/Stmt.h>
#include <clang/AST/StmtCXX.h>
namespace fair::mq::tidy {
using namespace clang;
bool isDiscarded(Expr const& e, ASTContext& ctx)
{
DynTypedNode node = DynTypedNode::create(e);
while (true) {
auto const parents = ctx.getParents(node);
if (parents.size() != 1) {
return false;
}
auto const& parent = parents[0];
if (parent.get<ExprWithCleanups>() || parent.get<ParenExpr>()) {
node = parent;
continue;
}
auto const* stmt = node.get<Stmt>();
if (parent.get<CompoundStmt>() || parent.get<CaseStmt>() || parent.get<DefaultStmt>()
|| parent.get<LabelStmt>() || parent.get<AttributedStmt>()) {
return true;
}
if (auto const* s = parent.get<IfStmt>()) {
return stmt == s->getThen() || stmt == s->getElse();
}
if (auto const* s = parent.get<WhileStmt>()) {
return stmt == s->getBody();
}
if (auto const* s = parent.get<DoStmt>()) {
return stmt == s->getBody();
}
if (auto const* s = parent.get<ForStmt>()) {
return stmt == s->getBody() || stmt == s->getInc();
}
if (auto const* s = parent.get<CXXForRangeStmt>()) {
return stmt == s->getBody();
}
return false;
}
}
} // namespace fair::mq::tidy