Skip to content

Commit 5fe649b

Browse files
committed
backport llvm commit ae20dbd to clang-tidy plugin
1 parent c6fe39c commit 5fe649b

File tree

2 files changed

+28
-50
lines changed

2 files changed

+28
-50
lines changed

utils/clang-tidy-auto-const/ExprAutoMutationAnalyzer.cpp

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ namespace clang
353353

354354
// Assume Exp is not mutated before analyzing Exp.
355355
MemoizedResults[Exp] = nullptr;
356-
if (isUnevaluated(Exp)) {
356+
if (ExprAutoMutationAnalyzer::isUnevaluated(Exp, Context)) {
357357
return nullptr;
358358
}
359359

@@ -390,45 +390,29 @@ namespace clang
390390
return nullptr;
391391
}
392392

393-
bool ExprAutoMutationAnalyzer::Analyzer::isUnevaluated(
394-
Stmt const *Exp, Stmt const &Stm, ASTContext &Context)
395-
{
396-
return selectFirst<Stmt>(
397-
NodeID<Expr>::value,
398-
match(
399-
findFirst(
400-
stmt(
401-
canResolveToExpr(Exp),
402-
anyOf(
403-
// `Exp` is part of the underlying expression
404-
// of decltype/typeof if it has an ancestor
405-
// of typeLoc.
406-
hasAncestor(typeLoc(unless(hasAncestor(
407-
unaryExprOrTypeTraitExpr())))),
408-
hasAncestor(expr(anyOf(
409-
// `UnaryExprOrTypeTraitExpr` is
410-
// unevaluated unless it's sizeof on VLA.
411-
unaryExprOrTypeTraitExpr(
412-
unless(sizeOfExpr(hasArgumentOfType(
413-
variableArrayType())))),
414-
// `CXXTypeidExpr` is unevaluated unless
415-
// it's applied to an expression of
416-
// glvalue of polymorphic class type.
417-
cxxTypeidExpr(
418-
unless(isPotentiallyEvaluated())),
419-
// The controlling expression of
420-
// `GenericSelectionExpr` is unevaluated.
421-
genericSelectionExpr(hasControllingExpr(
422-
hasDescendant(equalsNode(Exp)))),
423-
cxxNoexceptExpr())))))
424-
.bind(NodeID<Expr>::value)),
425-
Stm,
426-
Context)) != nullptr;
427-
}
428-
429-
bool ExprAutoMutationAnalyzer::Analyzer::isUnevaluated(Expr const *Exp)
430-
{
431-
return isUnevaluated(Exp, Stm, Context);
393+
bool ExprAutoMutationAnalyzer::isUnevaluated(const Stmt *Stm, ASTContext &Context) {
394+
return !match(stmt(anyOf(
395+
// `Exp` is part of the underlying expression of
396+
// decltype/typeof if it has an ancestor of
397+
// typeLoc.
398+
hasAncestor(typeLoc(
399+
unless(hasAncestor(unaryExprOrTypeTraitExpr())))),
400+
hasAncestor(expr(anyOf(
401+
// `UnaryExprOrTypeTraitExpr` is unevaluated
402+
// unless it's sizeof on VLA.
403+
unaryExprOrTypeTraitExpr(unless(sizeOfExpr(
404+
hasArgumentOfType(variableArrayType())))),
405+
// `CXXTypeidExpr` is unevaluated unless it's
406+
// applied to an expression of glvalue of
407+
// polymorphic class type.
408+
cxxTypeidExpr(unless(isPotentiallyEvaluated())),
409+
// The controlling expression of
410+
// `GenericSelectionExpr` is unevaluated.
411+
genericSelectionExpr(
412+
hasControllingExpr(hasDescendant(equalsNode(Stm)))),
413+
cxxNoexceptExpr()))))),
414+
*Stm, Context)
415+
.empty();
432416
}
433417

434418
Stmt const *ExprAutoMutationAnalyzer::Analyzer::findExprMutation(

utils/clang-tidy-auto-const/ExprAutoMutationAnalyzer.hpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ namespace clang
5959

6060
Stmt const *findPointeeMutation(Expr const *Exp);
6161
Stmt const *findPointeeMutation(Decl const *Dec);
62-
static bool isUnevaluated(
63-
Stmt const *Smt, Stmt const &Stm, ASTContext &Context);
6462

6563
private:
6664
using MutationFinder = Stmt const *(Analyzer::*)(Expr const *);
@@ -71,8 +69,6 @@ namespace clang
7169
Stmt const *tryEachDeclRef(Decl const *Dec, MutationFinder Finder);
7270
Stmt const *findMaybeRemovedIfConstexpr(Decl const *Dec);
7371

74-
bool isUnevaluated(Expr const *Exp);
75-
7672
Stmt const *
7773
findExprMutation(ArrayRef<ast_matchers::BoundNodes> Matches);
7874
Stmt const *
@@ -101,6 +97,10 @@ namespace clang
10197
{
10298
}
10399

100+
/// check whether stmt is unevaluated. mutation analyzer will ignore the
101+
/// content in unevaluated stmt.
102+
static bool isUnevaluated(const Stmt *Stm, ASTContext &Context);
103+
104104
bool isMutated(Expr const *Exp)
105105
{
106106
return findMutation(Exp) != nullptr;
@@ -141,12 +141,6 @@ namespace clang
141141
return A.findPointeeMutation(Dec);
142142
}
143143

144-
static bool
145-
isUnevaluated(Stmt const *Smt, Stmt const &Stm, ASTContext &Context)
146-
{
147-
return Analyzer::isUnevaluated(Smt, Stm, Context);
148-
}
149-
150144
private:
151145
Memoized Memorized;
152146
Analyzer A;

0 commit comments

Comments
 (0)