File indexing completed on 2026-05-10 08:36:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H
0025 #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H
0026
0027 #include <cassert>
0028
0029 #include "clang/AST/Decl.h"
0030 #include "clang/AST/Expr.h"
0031 #include "clang/AST/Stmt.h"
0032 #include "clang/ASTMatchers/ASTMatchers.h"
0033 #include "clang/Analysis/FlowSensitive/MatchSwitch.h"
0034 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
0035 #include "clang/Analysis/FlowSensitive/Value.h"
0036 #include "llvm/ADT/STLFunctionalExtras.h"
0037
0038 namespace clang::dataflow {
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 ast_matchers::StatementMatcher isSmartPointerLikeOperatorStar();
0062 ast_matchers::StatementMatcher isSmartPointerLikeOperatorArrow();
0063 ast_matchers::StatementMatcher isSmartPointerLikeValueMethodCall();
0064 ast_matchers::StatementMatcher isSmartPointerLikeGetMethodCall();
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 const FunctionDecl *
0077 getCanonicalSmartPointerLikeOperatorCallee(const CallExpr *CE);
0078
0079
0080
0081
0082
0083
0084
0085
0086 template <typename LatticeT>
0087 void transferSmartPointerLikeCachedDeref(
0088 const CallExpr *DerefExpr, RecordStorageLocation *SmartPointerLoc,
0089 TransferState<LatticeT> &State,
0090 llvm::function_ref<void(StorageLocation &)> InitializeLoc);
0091
0092
0093
0094
0095
0096
0097
0098 template <typename LatticeT>
0099 void transferSmartPointerLikeCachedGet(
0100 const CallExpr *GetExpr, RecordStorageLocation *SmartPointerLoc,
0101 TransferState<LatticeT> &State,
0102 llvm::function_ref<void(StorageLocation &)> InitializeLoc);
0103
0104 template <typename LatticeT>
0105 void transferSmartPointerLikeCachedDeref(
0106 const CallExpr *DerefExpr, RecordStorageLocation *SmartPointerLoc,
0107 TransferState<LatticeT> &State,
0108 llvm::function_ref<void(StorageLocation &)> InitializeLoc) {
0109 if (State.Env.getStorageLocation(*DerefExpr) != nullptr)
0110 return;
0111 if (SmartPointerLoc == nullptr)
0112 return;
0113
0114 const FunctionDecl *Callee = DerefExpr->getDirectCallee();
0115 if (Callee == nullptr)
0116 return;
0117 const FunctionDecl *CanonicalCallee =
0118 getCanonicalSmartPointerLikeOperatorCallee(DerefExpr);
0119
0120 assert(CanonicalCallee != nullptr);
0121 if (CanonicalCallee != Callee) {
0122
0123
0124 assert(CanonicalCallee->getReturnType()->isReferenceType() &&
0125 Callee->getReturnType()->isReferenceType());
0126 assert(CanonicalCallee->getReturnType()
0127 .getNonReferenceType()
0128 ->getCanonicalTypeUnqualified() ==
0129 Callee->getReturnType()
0130 .getNonReferenceType()
0131 ->getCanonicalTypeUnqualified());
0132 }
0133
0134 StorageLocation &LocForValue =
0135 State.Lattice.getOrCreateConstMethodReturnStorageLocation(
0136 *SmartPointerLoc, CanonicalCallee, State.Env, InitializeLoc);
0137 State.Env.setStorageLocation(*DerefExpr, LocForValue);
0138 }
0139
0140 template <typename LatticeT>
0141 void transferSmartPointerLikeCachedGet(
0142 const CallExpr *GetExpr, RecordStorageLocation *SmartPointerLoc,
0143 TransferState<LatticeT> &State,
0144 llvm::function_ref<void(StorageLocation &)> InitializeLoc) {
0145 if (SmartPointerLoc == nullptr)
0146 return;
0147
0148 const FunctionDecl *CanonicalCallee =
0149 getCanonicalSmartPointerLikeOperatorCallee(GetExpr);
0150
0151 if (CanonicalCallee != nullptr) {
0152 auto &LocForValue =
0153 State.Lattice.getOrCreateConstMethodReturnStorageLocation(
0154 *SmartPointerLoc, CanonicalCallee, State.Env, InitializeLoc);
0155 State.Env.setValue(*GetExpr,
0156 State.Env.template create<PointerValue>(LocForValue));
0157 } else {
0158
0159 Value *Val = State.Lattice.getOrCreateConstMethodReturnValue(
0160 *SmartPointerLoc, GetExpr, State.Env);
0161 if (Val == nullptr)
0162 return;
0163 State.Env.setValue(*GetExpr, *Val);
0164 }
0165 }
0166
0167 }
0168
0169 #endif