diff --git a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp index 183beb6bfb87d..0a0e212f345ed 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp @@ -13,10 +13,8 @@ #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h" #include "clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h" #include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Support/Error.h" -#include -#include -#include namespace clang::tidy::bugprone { using ast_matchers::MatchFinder; @@ -54,7 +52,7 @@ void UncheckedOptionalAccessCheck::check( UncheckedOptionalAccessDiagnoser Diagnoser(ModelOptions); // FIXME: Allow user to set the (defaulted) SAT iterations max for // `diagnoseFunction` with config options. - if (llvm::Expected> Locs = + if (llvm::Expected> Locs = dataflow::diagnoseFunction(*FuncDecl, *Result.Context, Diagnoser)) diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h index abd34f4092212..dd1a685cb48ba 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h @@ -31,6 +31,7 @@ #include "llvm/ADT/Any.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLFunctionalExtras.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" @@ -246,9 +247,9 @@ runDataflowAnalysis( /// - This limit is still low enough to keep runtimes acceptable (on typical /// machines) in cases where we hit the limit. template -llvm::Expected> diagnoseFunction( +llvm::Expected> diagnoseFunction( const FunctionDecl &FuncDecl, ASTContext &ASTCtx, - llvm::function_ref( + llvm::function_ref( const CFGElement &, ASTContext &, const TransferStateForDiagnostics &)> Diagnoser, @@ -263,7 +264,7 @@ llvm::Expected> diagnoseFunction( DataflowAnalysisContext AnalysisContext(std::move(OwnedSolver)); Environment Env(AnalysisContext, FuncDecl); AnalysisT Analysis(ASTCtx); - std::vector Diagnostics; + llvm::SmallVector Diagnostics; if (llvm::Error Err = runTypeErasedDataflowAnalysis( *Context, Analysis, Env, diff --git a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h index 76a567f1399cd..aeaf75b215422 100644 --- a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h +++ b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h @@ -21,7 +21,7 @@ #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h" #include "clang/Analysis/FlowSensitive/NoopLattice.h" #include "clang/Basic/SourceLocation.h" -#include +#include "llvm/ADT/SmallVector.h" namespace clang { namespace dataflow { @@ -74,14 +74,14 @@ class UncheckedOptionalAccessDiagnoser { UncheckedOptionalAccessDiagnoser( UncheckedOptionalAccessModelOptions Options = {}); - std::vector + llvm::SmallVector operator()(const CFGElement &Elt, ASTContext &Ctx, const TransferStateForDiagnostics &State) { return DiagnoseMatchSwitch(Elt, Ctx, State.Env); } private: - CFGMatchSwitch> + CFGMatchSwitch> DiagnoseMatchSwitch; }; diff --git a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp index e40bd3d0199bd..f61f26ff27804 100644 --- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp +++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp @@ -34,7 +34,6 @@ #include #include #include -#include namespace clang { namespace dataflow { @@ -913,8 +912,8 @@ auto buildTransferMatchSwitch() { .Build(); } -std::vector diagnoseUnwrapCall(const Expr *ObjectExpr, - const Environment &Env) { +llvm::SmallVector diagnoseUnwrapCall(const Expr *ObjectExpr, + const Environment &Env) { if (auto *OptionalVal = getValueBehindPossiblePointer(*ObjectExpr, Env)) { auto *Prop = OptionalVal->getProperty("has_value"); if (auto *HasValueVal = cast_or_null(Prop)) { @@ -935,7 +934,8 @@ auto buildDiagnoseMatchSwitch( // lot of duplicated work (e.g. string comparisons), consider providing APIs // that avoid it through memoization. auto IgnorableOptional = ignorableOptional(Options); - return CFGMatchSwitchBuilder>() + return CFGMatchSwitchBuilder>() // optional::value .CaseOfCFGStmt( valueCall(IgnorableOptional), diff --git a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp index af34a2afd2468..3fc1bb6692acf 100644 --- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp @@ -98,7 +98,7 @@ TEST(DataflowAnalysisTest, DiagnoseFunctionDiagnoserCalledOnEachElement) { cast(findValueDecl(AST->getASTContext(), "target")); auto Diagnoser = [](const CFGElement &Elt, ASTContext &, const TransferStateForDiagnostics &) { - std::vector Diagnostics(1); + llvm::SmallVector Diagnostics(1); llvm::raw_string_ostream OS(Diagnostics.front()); Elt.dumpToStream(OS); return Diagnostics;