================ @@ -0,0 +1,186 @@ +//===- AssignmentQuery.cpp - C++ Lifetime Safety Checker --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements the LifetimeChecker, which detects use-after-free +// errors by checking if live origins hold loans that have expired. +// +//===----------------------------------------------------------------------===// + +#include "clang/Analysis/Analyses/LifetimeSafety/AssignmentQuery.h" +#include <optional> + +namespace { +using namespace clang; +using namespace clang::lifetimes; +using namespace clang::lifetimes::internal; + +/// Locate the rightmost sub expression of the RHS, given that the LHS is +/// already known. To ensure printability, we invoke `Explorc->isValid()`. +/// +/// Typically, we select the rightmost subexpression, as it can be further +/// decomposed and parsed recursively. +/// +/// Since we are traversing assignments in reverse order, this function used +/// to determines whether `TargetExpr` meets the requirements of the RHS. +/// A match here triggers a subsequent attempt to match the LHS. +/// Because the function is not re-invoked until the LHS is matched, +/// it generally precludes the possibility of matching multiple +/// subexpressions within the same RHS. +const Expr *getRootSrcExpr(const Expr *TargetExpr) { + assert(TargetExpr); + const Expr *SExpr = TargetExpr->IgnoreParenCasts(); + + if (isa_and_nonnull<DeclRefExpr, CXXTemporaryObjectExpr, CXXConstructExpr, + MemberExpr, CXXMemberCallExpr, UnaryOperator, + CXXBindTemporaryExpr>(SExpr) && ---------------- suoyuan666 wrote:
This part is indeed suboptimal and warrants refactoring. It seems I could simply remove these type filters; a straightforward check of `ExprLoc`—followed by an immediate `return`—doesn't seem out of the question. I'll run some simple tests locally first and get back to you once I have some results. https://github.com/llvm/llvm-project/pull/196075 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
