11#include "clang/AST/Expr.h"
12#include "clang/AST/ExprCXX.h"
18 if (
const auto *DRE = dyn_cast<DeclRefExpr>(S))
19 return DRE->getDecl() == Var;
25 return llvm::any_of(RD->captures(), [Var](
const LambdaCapture &
C) {
26 return C.capturesVariable() && C.getCaptureKind() == LCK_ByRef &&
27 C.getCapturedVar() == Var;
34 if (Var->isEscapingByref())
37 if (
const auto *DS = dyn_cast<DeclStmt>(S)) {
38 for (
const Decl *D : DS->getDeclGroup()) {
39 if (
const auto *LeftVar = dyn_cast<VarDecl>(D)) {
40 if (LeftVar->hasInit() && LeftVar->getType()->isReferenceType()) {
45 }
else if (
const auto *UnOp = dyn_cast<UnaryOperator>(S)) {
46 if (UnOp->getOpcode() == UO_AddrOf)
48 }
else if (
const auto *LE = dyn_cast<LambdaExpr>(S)) {
51 }
else if (
const auto *ILE = dyn_cast<InitListExpr>(S)) {
52 return llvm::any_of(ILE->inits(), [Var](
const Expr *ChildE) {
56 return isAccessForVar(ChildE, Var);
68 for (
const Stmt *Child : S->children()) {
81 const auto *MD = dyn_cast<CXXMethodDecl>(Func);
85 const CXXRecordDecl *RD = MD->getParent();
const FunctionDecl * Decl
static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var)
Return whether Var has a pointer or reference in S.
static bool isAccessForVar(const Stmt *S, const VarDecl *Var)
Return whether S is a reference to the declaration of Var.
static bool capturesByRef(const CXXRecordDecl *RD, const VarDecl *Var)
bool hasPtrOrReferenceInFunc(const Decl *Func, const VarDecl *Var)
Returns whether Var has a pointer or reference in Func.
static bool hasPtrOrReferenceInStmt(const Stmt *S, const VarDecl *Var)
Return whether Var has a pointer or reference in S.
static bool refersToEnclosingLambdaCaptureByRef(const Decl *Func, const VarDecl *Var)