Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void InfiniteLoopCheck::check(const MatchFinder::MatchResult &Result) {
}
}

if (ExprMutationAnalyzer::isUnevaluated(LoopStmt, *LoopStmt, *Result.Context))
if (ExprMutationAnalyzer::isUnevaluated(LoopStmt, *Result.Context))
return;

if (isAtLeastOneCondVarChanged(Func, LoopStmt, Cond, Result.Context))
Expand Down
13 changes: 4 additions & 9 deletions clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class ExprMutationAnalyzer {

const Stmt *findPointeeMutation(const Expr *Exp);
const Stmt *findPointeeMutation(const Decl *Dec);
static bool isUnevaluated(const Stmt *Smt, const Stmt &Stm,
ASTContext &Context);

private:
using MutationFinder = const Stmt *(Analyzer::*)(const Expr *);
Expand All @@ -58,8 +56,6 @@ class ExprMutationAnalyzer {
Memoized::ResultMap &MemoizedResults);
const Stmt *tryEachDeclRef(const Decl *Dec, MutationFinder Finder);

bool isUnevaluated(const Expr *Exp);

const Stmt *findExprMutation(ArrayRef<ast_matchers::BoundNodes> Matches);
const Stmt *findDeclMutation(ArrayRef<ast_matchers::BoundNodes> Matches);
const Stmt *
Expand All @@ -83,6 +79,10 @@ class ExprMutationAnalyzer {
ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context)
: Memorized(), A(Stm, Context, Memorized) {}

/// check whether stmt is unevaluated. mutation analyzer will ignore the
/// content in unevaluated stmt.
static bool isUnevaluated(const Stmt *Stm, ASTContext &Context);

bool isMutated(const Expr *Exp) { return findMutation(Exp) != nullptr; }
bool isMutated(const Decl *Dec) { return findMutation(Dec) != nullptr; }
const Stmt *findMutation(const Expr *Exp) { return A.findMutation(Exp); }
Expand All @@ -101,11 +101,6 @@ class ExprMutationAnalyzer {
return A.findPointeeMutation(Dec);
}

static bool isUnevaluated(const Stmt *Smt, const Stmt &Stm,
ASTContext &Context) {
return Analyzer::isUnevaluated(Smt, Stm, Context);
}

private:
Memoized Memorized;
Analyzer A;
Expand Down
60 changes: 24 additions & 36 deletions clang/lib/Analysis/ExprMutationAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ const Stmt *ExprMutationAnalyzer::Analyzer::findMutationMemoized(
if (!Inserted)
return Memoized->second;

if (isUnevaluated(Exp))
if (ExprMutationAnalyzer::isUnevaluated(Exp, Context))
return nullptr;

for (const auto &Finder : Finders) {
Expand Down Expand Up @@ -268,41 +268,29 @@ ExprMutationAnalyzer::Analyzer::tryEachDeclRef(const Decl *Dec,
return nullptr;
}

bool ExprMutationAnalyzer::Analyzer::isUnevaluated(const Stmt *Exp,
const Stmt &Stm,
ASTContext &Context) {
return selectFirst<Stmt>(
NodeID<Expr>::value,
match(
findFirst(
stmt(canResolveToExpr(Exp),
anyOf(
// `Exp` is part of the underlying expression of
// decltype/typeof if it has an ancestor of
// typeLoc.
hasAncestor(typeLoc(unless(
hasAncestor(unaryExprOrTypeTraitExpr())))),
hasAncestor(expr(anyOf(
// `UnaryExprOrTypeTraitExpr` is unevaluated
// unless it's sizeof on VLA.
unaryExprOrTypeTraitExpr(unless(sizeOfExpr(
hasArgumentOfType(variableArrayType())))),
// `CXXTypeidExpr` is unevaluated unless it's
// applied to an expression of glvalue of
// polymorphic class type.
cxxTypeidExpr(
unless(isPotentiallyEvaluated())),
// The controlling expression of
// `GenericSelectionExpr` is unevaluated.
genericSelectionExpr(hasControllingExpr(
hasDescendant(equalsNode(Exp)))),
cxxNoexceptExpr())))))
.bind(NodeID<Expr>::value)),
Stm, Context)) != nullptr;
}

bool ExprMutationAnalyzer::Analyzer::isUnevaluated(const Expr *Exp) {
return isUnevaluated(Exp, Stm, Context);
bool ExprMutationAnalyzer::isUnevaluated(const Stmt *Stm, ASTContext &Context) {
return !match(stmt(anyOf(
// `Exp` is part of the underlying expression of
// decltype/typeof if it has an ancestor of
// typeLoc.
hasAncestor(typeLoc(
unless(hasAncestor(unaryExprOrTypeTraitExpr())))),
hasAncestor(expr(anyOf(
// `UnaryExprOrTypeTraitExpr` is unevaluated
// unless it's sizeof on VLA.
unaryExprOrTypeTraitExpr(unless(sizeOfExpr(
hasArgumentOfType(variableArrayType())))),
// `CXXTypeidExpr` is unevaluated unless it's
// applied to an expression of glvalue of
// polymorphic class type.
cxxTypeidExpr(unless(isPotentiallyEvaluated())),
// The controlling expression of
// `GenericSelectionExpr` is unevaluated.
genericSelectionExpr(
hasControllingExpr(hasDescendant(equalsNode(Stm)))),
cxxNoexceptExpr()))))),
*Stm, Context)
.empty();
}

const Stmt *
Expand Down
Loading