Skip to content

Commit

Permalink
Revert FallthroughMapper to use CRTP
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirraide committed Aug 19, 2024
1 parent ad00026 commit 1d2fdba
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions clang/lib/Sema/AnalysisBasedWarnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/EvaluatedExprVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/OperationKinds.h"
#include "clang/AST/ParentMap.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/StmtObjC.h"
#include "clang/AST/StmtVisitor.h"
Expand Down Expand Up @@ -1067,14 +1068,18 @@ static bool DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,
}

namespace {
class FallthroughMapper final : public DynamicRecursiveASTVisitor {
// This is not a dynamic visitor because it ends up traversing an
// order of magnitude more statements than every other visitor combined.
class FallthroughMapper final
: public RecursiveASTVisitor<FallthroughMapper> {
public:
FallthroughMapper(Sema &S)
: FoundSwitchStatements(false),
S(S) {
ShouldWalkTypesOfTypeLocs = false;
}

bool shouldWalkTypesOfTypeLocs() const { return false; }

bool foundSwitchStatements() const { return FoundSwitchStatements; }

void markFallthroughVisited(const AttributedStmt *Stmt) {
Expand Down Expand Up @@ -1187,23 +1192,23 @@ namespace {
return !!UnannotatedCnt;
}

bool VisitAttributedStmt(AttributedStmt *S) override {
bool VisitAttributedStmt(AttributedStmt *S) {
if (asFallThroughAttr(S))
FallthroughStmts.insert(S);
return true;
}

bool VisitSwitchStmt(SwitchStmt *S) override {
bool VisitSwitchStmt(SwitchStmt *S) {
FoundSwitchStatements = true;
return true;
}

// We don't want to traverse local type declarations. We analyze their
// methods separately.
bool TraverseDecl(Decl *D) override { return true; }
bool TraverseDecl(Decl *D) { return true; }

// We analyze lambda bodies separately. Skip them here.
bool TraverseLambdaExpr(LambdaExpr *LE) override {
bool TraverseLambdaExpr(LambdaExpr *LE) {
// Traverse the captures, but not the body.
for (const auto C : zip(LE->captures(), LE->capture_inits()))
TraverseLambdaCapture(LE, &std::get<0>(C), std::get<1>(C));
Expand Down

0 comments on commit 1d2fdba

Please sign in to comment.