#include "UseAfterMoveCheck.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
#include "clang/Analysis/CFG.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "../utils/ExprSequence.h"
#include "../utils/Matchers.h"
#include <optional>
usingnamespaceclang::ast_matchers;
usingnamespaceclang::tidy::utils;
namespace clang::tidy::bugprone {
hasUnevaluatedContext;
namespace {
struct UseAfterMove { … };
class UseAfterMoveFinder { … };
}
static StatementMatcher inDecltypeOrTemplateArg() { … }
UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)
: … { … }
std::optional<UseAfterMove>
UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall,
const DeclRefExpr *MovedVariable) { … }
std::optional<UseAfterMove>
UseAfterMoveFinder::findInternal(const CFGBlock *Block, const Expr *MovingCall,
const ValueDecl *MovedVariable) { … }
void UseAfterMoveFinder::getUsesAndReinits(
const CFGBlock *Block, const ValueDecl *MovedVariable,
llvm::SmallVectorImpl<const DeclRefExpr *> *Uses,
llvm::SmallPtrSetImpl<const Stmt *> *Reinits) { … }
bool isStandardSmartPointer(const ValueDecl *VD) { … }
void UseAfterMoveFinder::getDeclRefs(
const CFGBlock *Block, const Decl *MovedVariable,
llvm::SmallPtrSetImpl<const DeclRefExpr *> *DeclRefs) { … }
void UseAfterMoveFinder::getReinits(
const CFGBlock *Block, const ValueDecl *MovedVariable,
llvm::SmallPtrSetImpl<const Stmt *> *Stmts,
llvm::SmallPtrSetImpl<const DeclRefExpr *> *DeclRefs) { … }
enum class MoveType { … };
static MoveType determineMoveType(const FunctionDecl *FuncDecl) { … }
static void emitDiagnostic(const Expr *MovingCall, const DeclRefExpr *MoveArg,
const UseAfterMove &Use, ClangTidyCheck *Check,
ASTContext *Context, MoveType Type) { … }
void UseAfterMoveCheck::registerMatchers(MatchFinder *Finder) { … }
void UseAfterMoveCheck::check(const MatchFinder::MatchResult &Result) { … }
}