File indexing completed on 2026-05-10 08:36:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef CLANG_ANALYSIS_FLOWSENSITIVE_MODELS_UNCHECKEDOPTIONALACCESSMODEL_H
0015 #define CLANG_ANALYSIS_FLOWSENSITIVE_MODELS_UNCHECKEDOPTIONALACCESSMODEL_H
0016
0017 #include "clang/AST/ASTContext.h"
0018 #include "clang/Analysis/CFG.h"
0019 #include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
0020 #include "clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h"
0021 #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
0022 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
0023 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
0024 #include "clang/Basic/SourceLocation.h"
0025 #include "llvm/ADT/SmallVector.h"
0026
0027 namespace clang {
0028 namespace dataflow {
0029
0030
0031
0032
0033 struct UncheckedOptionalAccessModelOptions {
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 bool IgnoreSmartPointerDereference = false;
0048 };
0049
0050 using UncheckedOptionalAccessLattice = CachedConstAccessorsLattice<NoopLattice>;
0051
0052
0053
0054
0055 class UncheckedOptionalAccessModel
0056 : public DataflowAnalysis<UncheckedOptionalAccessModel,
0057 UncheckedOptionalAccessLattice> {
0058 public:
0059 UncheckedOptionalAccessModel(ASTContext &Ctx, dataflow::Environment &Env);
0060
0061
0062 static ast_matchers::DeclarationMatcher optionalClassDecl();
0063
0064 static UncheckedOptionalAccessLattice initialElement() { return {}; }
0065
0066 void transfer(const CFGElement &Elt, UncheckedOptionalAccessLattice &L,
0067 Environment &Env);
0068
0069 private:
0070 CFGMatchSwitch<TransferState<UncheckedOptionalAccessLattice>>
0071 TransferMatchSwitch;
0072 };
0073
0074 class UncheckedOptionalAccessDiagnoser {
0075 public:
0076 UncheckedOptionalAccessDiagnoser(
0077 UncheckedOptionalAccessModelOptions Options = {});
0078
0079 llvm::SmallVector<SourceLocation>
0080 operator()(const CFGElement &Elt, ASTContext &Ctx,
0081 const TransferStateForDiagnostics<UncheckedOptionalAccessLattice>
0082 &State) {
0083 return DiagnoseMatchSwitch(Elt, Ctx, State.Env);
0084 }
0085
0086 private:
0087 CFGMatchSwitch<const Environment, llvm::SmallVector<SourceLocation>>
0088 DiagnoseMatchSwitch;
0089 };
0090
0091 }
0092 }
0093
0094 #endif