================ @@ -0,0 +1,171 @@ +//===--- NullCheckAfterDereferenceCheck.cpp - clang-tidy-------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "NullCheckAfterDereferenceCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclTemplate.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Analysis/CFG.h" +#include "clang/Analysis/FlowSensitive/ControlFlowContext.h" +#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h" +#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h" +#include "clang/Analysis/FlowSensitive/DataflowLattice.h" +#include "clang/Analysis/FlowSensitive/Models/NullPointerAnalysisModel.h" +#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h" +#include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/Any.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/Support/Error.h" +#include <memory> +#include <vector> + +namespace clang::tidy::bugprone { + +using ast_matchers::MatchFinder; +using dataflow::NullCheckAfterDereferenceDiagnoser; +using dataflow::NullPointerAnalysisModel; + +static constexpr llvm::StringLiteral FuncID("fun"); + +struct ExpandedResult { + SourceLocation WarningLoc; + std::optional<SourceLocation> DerefLoc; +}; + +using ExpandedResultType = + std::pair<std::vector<ExpandedResult>, std::vector<ExpandedResult>>; + +static std::optional<ExpandedResultType> +analyzeFunction(const FunctionDecl &FuncDecl) { + using dataflow::ControlFlowContext; + using dataflow::DataflowAnalysisState; + using llvm::Expected; + + ASTContext &ASTCtx = FuncDecl.getASTContext(); + + if (FuncDecl.getBody() == nullptr) { + return std::nullopt; + } + + Expected<ControlFlowContext> Context = + ControlFlowContext::build(FuncDecl, *FuncDecl.getBody(), ASTCtx); + if (!Context) + return std::nullopt; + + dataflow::DataflowAnalysisContext AnalysisContext( + std::make_unique<dataflow::WatchedLiteralsSolver>()); + dataflow::Environment Env(AnalysisContext, FuncDecl); + NullPointerAnalysisModel Analysis(ASTCtx); + NullCheckAfterDereferenceDiagnoser Diagnoser; + NullCheckAfterDereferenceDiagnoser::ResultType Diagnostics; + + using LatticeState = DataflowAnalysisState<NullPointerAnalysisModel::Lattice>; ---------------- Discookie wrote:
`State` works, yep. https://github.com/llvm/llvm-project/pull/84166 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits