Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 1 | // Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 2 | // Exceptions. See /LICENSE for license information. |
| 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | |
Googler | 7f19b2b | 2023-05-01 09:44:57 -0700 | [diff] [blame] | 5 | #include "nullability/pointer_nullability_analysis.h" |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 6 | |
Googler | bad7052 | 2023-01-31 04:37:38 -0800 | [diff] [blame] | 7 | #include <optional> |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 8 | #include <string> |
Martin Brænne | 66bc243 | 2023-04-18 23:48:49 -0700 | [diff] [blame] | 9 | #include <vector> |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 10 | |
Lukasz Anforowicz | 2c34cae | 2022-08-26 07:19:20 -0700 | [diff] [blame] | 11 | #include "absl/log/check.h" |
Googler | 7f19b2b | 2023-05-01 09:44:57 -0700 | [diff] [blame] | 12 | #include "nullability/pointer_nullability.h" |
| 13 | #include "nullability/pointer_nullability_lattice.h" |
| 14 | #include "nullability/pointer_nullability_matchers.h" |
Sam McCall | 5fc2a80 | 2023-05-02 05:41:27 -0700 | [diff] [blame] | 15 | #include "nullability/type_nullability.h" |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Googler | d443731 | 2023-01-17 15:10:29 -0800 | [diff] [blame] | 17 | #include "clang/AST/ASTDumper.h" |
Martin Brænne | ef1c7af | 2023-06-29 06:13:27 -0700 | [diff] [blame^] | 18 | #include "clang/AST/DeclTemplate.h" |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Wei Yi Tee | 1cd62af | 2022-06-09 00:56:46 -0700 | [diff] [blame] | 20 | #include "clang/AST/OperationKinds.h" |
| 21 | #include "clang/AST/Stmt.h" |
| 22 | #include "clang/AST/Type.h" |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 23 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
Martin Brænne | c490306 | 2023-04-24 23:40:36 -0700 | [diff] [blame] | 24 | #include "clang/ASTMatchers/ASTMatchers.h" |
Wei Yi Tee | 217eb5f | 2022-09-15 03:18:28 -0700 | [diff] [blame] | 25 | #include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h" |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 26 | #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h" |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 27 | #include "clang/Analysis/FlowSensitive/Value.h" |
| 28 | #include "clang/Basic/LLVM.h" |
Wei Yi Tee | f5e8e57 | 2022-08-02 11:31:12 -0700 | [diff] [blame] | 29 | #include "clang/Basic/Specifiers.h" |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 30 | |
Sam McCall | 4f6be42 | 2023-06-27 02:51:22 -0700 | [diff] [blame] | 31 | namespace clang::tidy::nullability { |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 32 | |
| 33 | using ast_matchers::MatchFinder; |
| 34 | using dataflow::BoolValue; |
Wei Yi Tee | 217eb5f | 2022-09-15 03:18:28 -0700 | [diff] [blame] | 35 | using dataflow::CFGMatchSwitchBuilder; |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 36 | using dataflow::Environment; |
Wei Yi Tee | 721ee97 | 2022-08-11 01:14:54 -0700 | [diff] [blame] | 37 | using dataflow::PointerValue; |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 38 | using dataflow::TransferState; |
| 39 | using dataflow::Value; |
| 40 | |
| 41 | namespace { |
| 42 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 43 | TypeNullability prepend(NullabilityKind Head, const TypeNullability &Tail) { |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 44 | TypeNullability Result = {Head}; |
Googler | 2bccf74 | 2023-01-18 03:53:14 -0800 | [diff] [blame] | 45 | Result.insert(Result.end(), Tail.begin(), Tail.end()); |
| 46 | return Result; |
| 47 | } |
| 48 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 49 | void computeNullability(const Expr *E, |
| 50 | TransferState<PointerNullabilityLattice> &State, |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 51 | std::function<TypeNullability()> Compute) { |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 52 | (void)State.Lattice.insertExprNullabilityIfAbsent(E, [&] { |
| 53 | auto Nullability = Compute(); |
| 54 | if (unsigned ExpectedSize = countPointersInType(E); |
| 55 | ExpectedSize != Nullability.size()) { |
| 56 | // A nullability vector must have one entry per pointer in the type. |
| 57 | // If this is violated, we probably failed to handle some AST node. |
Martin Brænne | 9d2afac | 2023-04-06 05:20:46 -0700 | [diff] [blame] | 58 | llvm::dbgs() |
| 59 | << "=== Nullability vector has wrong number of entries: ===\n"; |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 60 | llvm::dbgs() << "Expression: \n"; |
| 61 | dump(E, llvm::dbgs()); |
| 62 | llvm::dbgs() << "\nNullability (" << Nullability.size() |
| 63 | << " pointers): " << nullabilityToString(Nullability) |
| 64 | << "\n"; |
| 65 | llvm::dbgs() << "\nType (" << ExpectedSize << " pointers): \n"; |
| 66 | dump(exprType(E), llvm::dbgs()); |
| 67 | llvm::dbgs() << "=================================\n"; |
| 68 | |
| 69 | // We can't meaningfully interpret the vector, so discard it. |
| 70 | // TODO: fix all broken cases and upgrade to CHECK or DCHECK or so. |
| 71 | Nullability.assign(ExpectedSize, NullabilityKind::Unspecified); |
| 72 | } |
| 73 | return Nullability; |
| 74 | }); |
| 75 | } |
| 76 | |
Sam McCall | 5fc2a80 | 2023-05-02 05:41:27 -0700 | [diff] [blame] | 77 | // Returns the computed nullability for a subexpr of the current expression. |
| 78 | // This is always available as we compute bottom-up. |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 79 | const TypeNullability &getNullabilityForChild( |
| 80 | const Expr *E, TransferState<PointerNullabilityLattice> &State) { |
Sam McCall | 5fc2a80 | 2023-05-02 05:41:27 -0700 | [diff] [blame] | 81 | return State.Lattice.insertExprNullabilityIfAbsent(E, [&] { |
| 82 | // Since we process child nodes before parents, we should already have |
| 83 | // computed the child nullability. However, this is not true in all test |
| 84 | // cases. So, we return unspecified nullability annotations. |
| 85 | // TODO: fix this issue, and CHECK() instead. |
| 86 | llvm::dbgs() << "=== Missing child nullability: ===\n"; |
| 87 | dump(E, llvm::dbgs()); |
| 88 | llvm::dbgs() << "==================================\n"; |
| 89 | |
| 90 | return unspecifiedNullability(E); |
| 91 | }); |
| 92 | } |
| 93 | |
Dani Ferreira Franco Moura | 82c1758 | 2023-01-17 10:58:53 -0800 | [diff] [blame] | 94 | /// Compute the nullability annotation of type `T`, which contains types |
| 95 | /// originally written as a class template type parameter. |
Dani Ferreira Franco Moura | 7ca32fc | 2022-11-24 04:19:16 -0800 | [diff] [blame] | 96 | /// |
Dani Ferreira Franco Moura | 82c1758 | 2023-01-17 10:58:53 -0800 | [diff] [blame] | 97 | /// Example: |
Dani Ferreira Franco Moura | 7ca32fc | 2022-11-24 04:19:16 -0800 | [diff] [blame] | 98 | /// |
Dani Ferreira Franco Moura | 82c1758 | 2023-01-17 10:58:53 -0800 | [diff] [blame] | 99 | /// \code |
| 100 | /// template <typename F, typename S> |
| 101 | /// struct pair { |
| 102 | /// S *_Nullable getNullablePtrToSecond(); |
| 103 | /// }; |
| 104 | /// \endcode |
| 105 | /// |
| 106 | /// Consider the following member call: |
| 107 | /// |
| 108 | /// \code |
| 109 | /// pair<int *, int *_Nonnull> x; |
| 110 | /// x.getNullablePtrToSecond(); |
| 111 | /// \endcode |
| 112 | /// |
| 113 | /// The class template specialization `x` has the following substitutions: |
| 114 | /// |
| 115 | /// F=int *, whose nullability is [_Unspecified] |
| 116 | /// S=int * _Nonnull, whose nullability is [_Nonnull] |
| 117 | /// |
| 118 | /// The return type of the member call `x.getNullablePtrToSecond()` is |
| 119 | /// S * _Nullable. |
| 120 | /// |
| 121 | /// When we call `substituteNullabilityAnnotationsInClassTemplate` with the type |
| 122 | /// `S * _Nullable` and the `base` node of the member call (in this case, a |
| 123 | /// `DeclRefExpr`), it returns the nullability of the given type after applying |
| 124 | /// substitutions, which in this case is [_Nullable, _Nonnull]. |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 125 | TypeNullability substituteNullabilityAnnotationsInClassTemplate( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 126 | QualType T, const TypeNullability &BaseNullabilityAnnotations, |
Dani Ferreira Franco Moura | 7ca32fc | 2022-11-24 04:19:16 -0800 | [diff] [blame] | 127 | QualType BaseType) { |
Sam McCall | 932b743 | 2023-01-23 04:41:22 -0800 | [diff] [blame] | 128 | return getNullabilityAnnotationsFromType( |
| 129 | T, |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 130 | [&](const SubstTemplateTypeParmType *ST) |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 131 | -> std::optional<TypeNullability> { |
Sam McCall | 28ab01a | 2023-01-23 05:15:48 -0800 | [diff] [blame] | 132 | // The class specialization that is BaseType and owns ST. |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 133 | const ClassTemplateSpecializationDecl *Specialization = nullptr; |
Sam McCall | 28ab01a | 2023-01-23 05:15:48 -0800 | [diff] [blame] | 134 | if (auto RT = BaseType->getAs<RecordType>()) |
| 135 | Specialization = |
| 136 | dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl()); |
| 137 | // TODO: handle nested templates, where associated decl != base type |
| 138 | // (e.g. PointerNullabilityTest.MemberFunctionTemplateOfTemplateStruct) |
| 139 | if (!Specialization || Specialization != ST->getAssociatedDecl()) |
| 140 | return std::nullopt; |
Martin Brænne | ef1c7af | 2023-06-29 06:13:27 -0700 | [diff] [blame^] | 141 | // TODO: The code below does not deal correctly with partial |
| 142 | // specializations. We should eventually handle these, but for now, just |
| 143 | // bail out. |
| 144 | if (isa<ClassTemplatePartialSpecializationDecl>( |
| 145 | ST->getReplacedParameter()->getDeclContext())) |
| 146 | return std::nullopt; |
Sam McCall | 28ab01a | 2023-01-23 05:15:48 -0800 | [diff] [blame] | 147 | |
Dani Ferreira Franco Moura | 82c1758 | 2023-01-17 10:58:53 -0800 | [diff] [blame] | 148 | unsigned ArgIndex = ST->getIndex(); |
Sam McCall | 28ab01a | 2023-01-23 05:15:48 -0800 | [diff] [blame] | 149 | auto TemplateArgs = Specialization->getTemplateArgs().asArray(); |
Dani Ferreira Franco Moura | 82c1758 | 2023-01-17 10:58:53 -0800 | [diff] [blame] | 150 | |
Sam McCall | a45d260 | 2023-04-28 13:20:15 -0700 | [diff] [blame] | 151 | unsigned PointerCount = |
| 152 | countPointersInType(Specialization->getDeclContext()); |
Sam McCall | 28ab01a | 2023-01-23 05:15:48 -0800 | [diff] [blame] | 153 | for (auto TA : TemplateArgs.take_front(ArgIndex)) { |
| 154 | PointerCount += countPointersInType(TA); |
Dani Ferreira Franco Moura | 82c1758 | 2023-01-17 10:58:53 -0800 | [diff] [blame] | 155 | } |
Sam McCall | 28ab01a | 2023-01-23 05:15:48 -0800 | [diff] [blame] | 156 | unsigned SliceSize = countPointersInType(TemplateArgs[ArgIndex]); |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 157 | return ArrayRef(BaseNullabilityAnnotations) |
| 158 | .slice(PointerCount, SliceSize) |
| 159 | .vec(); |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 160 | }); |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Dani Ferreira Franco Moura | 82c1758 | 2023-01-17 10:58:53 -0800 | [diff] [blame] | 163 | /// Compute nullability annotations of `T`, which might contain template type |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 164 | /// variable substitutions bound by the call `CE`. |
| 165 | /// |
| 166 | /// Example: |
| 167 | /// |
| 168 | /// \code |
| 169 | /// template<typename F, typename S> |
| 170 | /// std::pair<S, F> flip(std::pair<F, S> p); |
| 171 | /// \endcode |
| 172 | /// |
| 173 | /// Consider the following CallExpr: |
| 174 | /// |
Dani Ferreira Franco Moura | 82c1758 | 2023-01-17 10:58:53 -0800 | [diff] [blame] | 175 | /// \code |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 176 | /// flip<int * _Nonnull, int * _Nullable>(std::make_pair(&x, &y)); |
Dani Ferreira Franco Moura | 82c1758 | 2023-01-17 10:58:53 -0800 | [diff] [blame] | 177 | /// \endcode |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 178 | /// |
| 179 | /// This CallExpr has the following substitutions: |
| 180 | /// F=int * _Nonnull, whose nullability is [_Nonnull] |
| 181 | /// S=int * _Nullable, whose nullability is [_Nullable] |
| 182 | /// |
| 183 | /// The return type of this CallExpr is `std::pair<S, F>`. |
| 184 | /// |
| 185 | /// When we call `substituteNullabilityAnnotationsInFunctionTemplate` with the |
| 186 | /// type `std::pair<S, F>` and the above CallExpr, it returns the nullability |
| 187 | /// the given type after applying substitutions, which in this case is |
| 188 | /// [_Nullable, _Nonnull]. |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 189 | TypeNullability substituteNullabilityAnnotationsInFunctionTemplate( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 190 | QualType T, const CallExpr *CE) { |
Sam McCall | 932b743 | 2023-01-23 04:41:22 -0800 | [diff] [blame] | 191 | return getNullabilityAnnotationsFromType( |
| 192 | T, |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 193 | [&](const SubstTemplateTypeParmType *ST) |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 194 | -> std::optional<TypeNullability> { |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 195 | // TODO: Handle calls that use template argument deduction. |
Lukasz Anforowicz | 60ed6c8 | 2023-04-26 12:05:26 -0700 | [diff] [blame] | 196 | // TODO: Handle nested templates (...->getDepth() > 0). |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 197 | if (auto *DRE = |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 198 | dyn_cast<DeclRefExpr>(CE->getCallee()->IgnoreImpCasts()); |
Martin Brænne | c490306 | 2023-04-24 23:40:36 -0700 | [diff] [blame] | 199 | DRE != nullptr && ST->getReplacedParameter()->getDepth() == 0 && |
Martin Brænne | 8cdb0b1 | 2023-04-27 03:47:50 -0700 | [diff] [blame] | 200 | // Some or all of the template arguments may be deduced, and we |
| 201 | // won't see those on the `DeclRefExpr`. If the template argument |
| 202 | // was deduced, we don't have any sugar for it. |
Martin Brænne | 684cf70 | 2023-04-28 04:36:23 -0700 | [diff] [blame] | 203 | // TODO(b/268348533): Can we somehow obtain it from the function |
| 204 | // param it was deduced from? |
| 205 | // TODO(b/268345783): This check, as well as the index into |
| 206 | // `template_arguments` below, may be incorrect in the presence of |
| 207 | // parameters packs. In function templates, parameter packs may |
| 208 | // appear anywhere in the parameter list. The index may therefore |
| 209 | // refer to one of the pack arguments, but we might incorrectly |
| 210 | // interpret it as referring to an argument that follows the pack. |
Martin Brænne | 8cdb0b1 | 2023-04-27 03:47:50 -0700 | [diff] [blame] | 211 | ST->getIndex() < DRE->template_arguments().size()) { |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 212 | TypeSourceInfo *TSI = |
Martin Brænne | 61d4e36 | 2023-04-27 01:07:59 -0700 | [diff] [blame] | 213 | DRE->template_arguments()[ST->getIndex()].getTypeSourceInfo(); |
| 214 | if (TSI == nullptr) return std::nullopt; |
| 215 | return getNullabilityAnnotationsFromType(TSI->getType()); |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 216 | } |
Sam McCall | 932b743 | 2023-01-23 04:41:22 -0800 | [diff] [blame] | 217 | return std::nullopt; |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 218 | }); |
Dani Ferreira Franco Moura | 7ca32fc | 2022-11-24 04:19:16 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 221 | NullabilityKind getPointerNullability(const Expr *E, |
| 222 | PointerNullabilityAnalysis::Lattice &L) { |
Dani Ferreira Franco Moura | 309f2d7 | 2022-11-15 07:09:00 -0800 | [diff] [blame] | 223 | QualType ExprType = E->getType(); |
Googler | bad7052 | 2023-01-31 04:37:38 -0800 | [diff] [blame] | 224 | std::optional<NullabilityKind> Nullability = ExprType->getNullability(); |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 225 | |
| 226 | // If the expression's type does not contain nullability information, it may |
| 227 | // be a template instantiation. Look up the nullability in the |
| 228 | // `ExprToNullability` map. |
| 229 | if (Nullability.value_or(NullabilityKind::Unspecified) == |
| 230 | NullabilityKind::Unspecified) { |
| 231 | if (auto MaybeNullability = L.getExprNullability(E)) { |
| 232 | if (!MaybeNullability->empty()) { |
| 233 | // Return the nullability of the topmost pointer in the type. |
| 234 | Nullability = (*MaybeNullability)[0]; |
| 235 | } |
| 236 | } |
| 237 | } |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 238 | return Nullability.value_or(NullabilityKind::Unspecified); |
Dani Ferreira Franco Moura | 309f2d7 | 2022-11-15 07:09:00 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Dani Ferreira Franco Moura | 1d41c11 | 2022-12-21 08:43:32 -0800 | [diff] [blame] | 241 | void initPointerFromAnnotations( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 242 | PointerValue &PointerVal, const Expr *E, |
| 243 | TransferState<PointerNullabilityLattice> &State) { |
Dani Ferreira Franco Moura | 1d41c11 | 2022-12-21 08:43:32 -0800 | [diff] [blame] | 244 | NullabilityKind Nullability = getPointerNullability(E, State.Lattice); |
Wei Yi Tee | f5e8e57 | 2022-08-02 11:31:12 -0700 | [diff] [blame] | 245 | switch (Nullability) { |
| 246 | case NullabilityKind::NonNull: |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 247 | initNotNullPointer(PointerVal, State.Env); |
Wei Yi Tee | f5e8e57 | 2022-08-02 11:31:12 -0700 | [diff] [blame] | 248 | break; |
Wei Yi Tee | ae43f39 | 2022-08-02 11:33:23 -0700 | [diff] [blame] | 249 | case NullabilityKind::Nullable: |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 250 | initNullablePointer(PointerVal, State.Env); |
Wei Yi Tee | ae43f39 | 2022-08-02 11:33:23 -0700 | [diff] [blame] | 251 | break; |
| 252 | default: |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 253 | initUnknownPointer(PointerVal, State.Env); |
Wei Yi Tee | 8374c8f | 2022-08-11 01:18:41 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 257 | void transferFlowSensitiveNullPointer( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 258 | const Expr *NullPointer, const MatchFinder::MatchResult &, |
| 259 | TransferState<PointerNullabilityLattice> &State) { |
| 260 | if (auto *PointerVal = getPointerValueFromExpr(NullPointer, State.Env)) { |
Wei Yi Tee | 8374c8f | 2022-08-11 01:18:41 -0700 | [diff] [blame] | 261 | initNullPointer(*PointerVal, State.Env); |
| 262 | } |
| 263 | } |
| 264 | |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 265 | void transferFlowSensitiveNotNullPointer( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 266 | const Expr *NotNullPointer, const MatchFinder::MatchResult &, |
| 267 | TransferState<PointerNullabilityLattice> &State) { |
| 268 | if (auto *PointerVal = getPointerValueFromExpr(NotNullPointer, State.Env)) { |
Wei Yi Tee | 8374c8f | 2022-08-11 01:18:41 -0700 | [diff] [blame] | 269 | initNotNullPointer(*PointerVal, State.Env); |
| 270 | } |
| 271 | } |
| 272 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 273 | const PointerTypeNullability *getOverriddenNullability( |
| 274 | const Expr *E, PointerNullabilityLattice &Lattice) { |
| 275 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
Sam McCall | 74bf864 | 2023-06-16 11:21:42 -0700 | [diff] [blame] | 276 | return Lattice.getDeclNullability(DRE->getDecl()); |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 277 | if (const auto *ME = dyn_cast<MemberExpr>(E)) |
Sam McCall | 74bf864 | 2023-06-16 11:21:42 -0700 | [diff] [blame] | 278 | return Lattice.getDeclNullability(ME->getMemberDecl()); |
| 279 | return nullptr; |
| 280 | } |
| 281 | |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 282 | void transferFlowSensitivePointer( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 283 | const Expr *PointerExpr, const MatchFinder::MatchResult &Result, |
| 284 | TransferState<PointerNullabilityLattice> &State) { |
| 285 | auto &Env = State.Env; |
| 286 | if (auto *PointerVal = getPointerValueFromExpr(PointerExpr, Env)) { |
| 287 | if (auto *Override = getOverriddenNullability(PointerExpr, State.Lattice)) { |
Sam McCall | 74bf864 | 2023-06-16 11:21:42 -0700 | [diff] [blame] | 288 | // is_known = (nonnull | nullable) |
| 289 | initPointerNullState( |
| 290 | *PointerVal, Env, |
| 291 | &Env.makeOr(*Override->Nonnull, *Override->Nullable)); |
| 292 | // nonnull => !is_null |
| 293 | auto [IsKnown, IsNull] = getPointerNullState(*PointerVal); |
| 294 | Env.addToFlowCondition( |
| 295 | Env.makeImplication(*Override->Nonnull, Env.makeNot(IsNull))); |
| 296 | } else { |
| 297 | initPointerFromAnnotations(*PointerVal, PointerExpr, State); |
| 298 | } |
Wei Yi Tee | f5e8e57 | 2022-08-02 11:31:12 -0700 | [diff] [blame] | 299 | } |
Wei Yi Tee | 1cd62af | 2022-06-09 00:56:46 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Wei Yi Tee | 8b58e19 | 2022-08-02 10:15:40 -0700 | [diff] [blame] | 302 | // TODO(b/233582219): Implement promotion of nullability knownness for initially |
| 303 | // unknown pointers when there is evidence that it is nullable, for example |
| 304 | // when the pointer is compared to nullptr, or casted to boolean. |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 305 | void transferFlowSensitiveNullCheckComparison( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 306 | const BinaryOperator *BinaryOp, const MatchFinder::MatchResult &result, |
| 307 | TransferState<PointerNullabilityLattice> &State) { |
Wei Yi Tee | 1cd62af | 2022-06-09 00:56:46 -0700 | [diff] [blame] | 308 | // Boolean representing the comparison between the two pointer values, |
Dani Ferreira Franco Moura | 309f2d7 | 2022-11-15 07:09:00 -0800 | [diff] [blame] | 309 | // automatically created by the dataflow framework. |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 310 | auto &PointerComparison = |
Martin Brænne | 0da5885 | 2023-05-23 06:43:57 -0700 | [diff] [blame] | 311 | *cast<BoolValue>(State.Env.getValueStrict(*BinaryOp)); |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 312 | |
Wei Yi Tee | 1cd62af | 2022-06-09 00:56:46 -0700 | [diff] [blame] | 313 | CHECK(BinaryOp->getOpcode() == BO_EQ || BinaryOp->getOpcode() == BO_NE); |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 314 | auto &PointerEQ = BinaryOp->getOpcode() == BO_EQ |
Wei Yi Tee | 1cd62af | 2022-06-09 00:56:46 -0700 | [diff] [blame] | 315 | ? PointerComparison |
| 316 | : State.Env.makeNot(PointerComparison); |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 317 | auto &PointerNE = BinaryOp->getOpcode() == BO_EQ |
Wei Yi Tee | 1cd62af | 2022-06-09 00:56:46 -0700 | [diff] [blame] | 318 | ? State.Env.makeNot(PointerComparison) |
| 319 | : PointerComparison; |
| 320 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 321 | auto *LHS = getPointerValueFromExpr(BinaryOp->getLHS(), State.Env); |
| 322 | auto *RHS = getPointerValueFromExpr(BinaryOp->getRHS(), State.Env); |
Wei Yi Tee | 8374c8f | 2022-08-11 01:18:41 -0700 | [diff] [blame] | 323 | |
| 324 | if (!LHS || !RHS) return; |
| 325 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 326 | auto &LHSNull = getPointerNullState(*LHS).second; |
| 327 | auto &RHSNull = getPointerNullState(*RHS).second; |
| 328 | auto &LHSNotNull = State.Env.makeNot(LHSNull); |
| 329 | auto &RHSNotNull = State.Env.makeNot(RHSNull); |
Wei Yi Tee | 1cd62af | 2022-06-09 00:56:46 -0700 | [diff] [blame] | 330 | |
Wei Yi Tee | 06f0696 | 2022-08-02 09:49:50 -0700 | [diff] [blame] | 331 | // nullptr == nullptr |
Wei Yi Tee | 1cd62af | 2022-06-09 00:56:46 -0700 | [diff] [blame] | 332 | State.Env.addToFlowCondition(State.Env.makeImplication( |
Googler | b1c6681 | 2023-06-09 10:20:46 -0700 | [diff] [blame] | 333 | State.Env.makeAnd(LHSNull, RHSNull), PointerEQ)); |
Wei Yi Tee | 06f0696 | 2022-08-02 09:49:50 -0700 | [diff] [blame] | 334 | // nullptr != notnull |
Wei Yi Tee | 1cd62af | 2022-06-09 00:56:46 -0700 | [diff] [blame] | 335 | State.Env.addToFlowCondition(State.Env.makeImplication( |
Googler | b1c6681 | 2023-06-09 10:20:46 -0700 | [diff] [blame] | 336 | State.Env.makeAnd(LHSNull, RHSNotNull), PointerNE)); |
Wei Yi Tee | 06f0696 | 2022-08-02 09:49:50 -0700 | [diff] [blame] | 337 | // notnull != nullptr |
Wei Yi Tee | 1cd62af | 2022-06-09 00:56:46 -0700 | [diff] [blame] | 338 | State.Env.addToFlowCondition(State.Env.makeImplication( |
Googler | b1c6681 | 2023-06-09 10:20:46 -0700 | [diff] [blame] | 339 | State.Env.makeAnd(LHSNotNull, RHSNull), PointerNE)); |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 342 | void transferFlowSensitiveNullCheckImplicitCastPtrToBool( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 343 | const Expr *CastExpr, const MatchFinder::MatchResult &, |
| 344 | TransferState<PointerNullabilityLattice> &State) { |
| 345 | auto *PointerVal = |
Wei Yi Tee | 8374c8f | 2022-08-11 01:18:41 -0700 | [diff] [blame] | 346 | getPointerValueFromExpr(CastExpr->IgnoreImplicit(), State.Env); |
| 347 | if (!PointerVal) return; |
| 348 | |
Googler | f164e03 | 2023-05-18 08:38:51 -0700 | [diff] [blame] | 349 | auto [PointerKnown, PointerNull] = getPointerNullState(*PointerVal); |
Martin Brænne | 0da5885 | 2023-05-23 06:43:57 -0700 | [diff] [blame] | 350 | State.Env.setValueStrict(*CastExpr, State.Env.makeNot(PointerNull)); |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 353 | void transferFlowSensitiveCallExpr( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 354 | const CallExpr *CallExpr, const MatchFinder::MatchResult &Result, |
| 355 | TransferState<PointerNullabilityLattice> &State) { |
Martin Brænne | c307b1f | 2023-04-20 07:16:35 -0700 | [diff] [blame] | 356 | // The dataflow framework itself does not create values for `CallExpr`s. |
| 357 | // However, we need these in some cases, so we produce them ourselves. |
Wei Yi Tee | c1e1d86 | 2022-08-19 14:11:28 -0700 | [diff] [blame] | 358 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 359 | dataflow::StorageLocation *Loc = nullptr; |
Martin Brænne | 0da5885 | 2023-05-23 06:43:57 -0700 | [diff] [blame] | 360 | if (CallExpr->isGLValue()) { |
| 361 | // The function returned a reference. Create a storage location for the |
| 362 | // expression so that if code creates a pointer from the reference, we will |
| 363 | // produce a `PointerValue`. |
| 364 | Loc = State.Env.getStorageLocationStrict(*CallExpr); |
| 365 | if (!Loc) { |
| 366 | // This is subtle: We call `createStorageLocation(QualType)`, not |
| 367 | // `createStorageLocation(const Expr &)`, so that we create a new |
| 368 | // storage location every time. |
| 369 | Loc = &State.Env.createStorageLocation(CallExpr->getType()); |
| 370 | State.Env.setStorageLocationStrict(*CallExpr, *Loc); |
| 371 | } |
| 372 | } |
| 373 | |
Martin Brænne | c307b1f | 2023-04-20 07:16:35 -0700 | [diff] [blame] | 374 | if (CallExpr->getType()->isAnyPointerType()) { |
| 375 | // Create a pointer so that we can attach nullability to it and have the |
| 376 | // nullability propagate with the pointer. |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 377 | auto *PointerVal = getPointerValueFromExpr(CallExpr, State.Env); |
Martin Brænne | c307b1f | 2023-04-20 07:16:35 -0700 | [diff] [blame] | 378 | if (!PointerVal) { |
| 379 | PointerVal = |
| 380 | cast<PointerValue>(State.Env.createValue(CallExpr->getType())); |
Martin Brænne | c307b1f | 2023-04-20 07:16:35 -0700 | [diff] [blame] | 381 | } |
| 382 | initPointerFromAnnotations(*PointerVal, CallExpr, State); |
Martin Brænne | 0da5885 | 2023-05-23 06:43:57 -0700 | [diff] [blame] | 383 | |
| 384 | if (Loc != nullptr) |
| 385 | State.Env.setValue(*Loc, *PointerVal); |
| 386 | else |
| 387 | // `Loc` is set iff `CallExpr` is a glvalue, so we know here that it must |
| 388 | // be a prvalue. |
| 389 | State.Env.setValueStrict(*CallExpr, *PointerVal); |
Wei Yi Tee | c1e1d86 | 2022-08-19 14:11:28 -0700 | [diff] [blame] | 390 | } |
Wei Yi Tee | c1e1d86 | 2022-08-19 14:11:28 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 393 | void transferNonFlowSensitiveDeclRefExpr( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 394 | const DeclRefExpr *DRE, const MatchFinder::MatchResult &MR, |
| 395 | TransferState<PointerNullabilityLattice> &State) { |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 396 | computeNullability(DRE, State, [&] { |
| 397 | return getNullabilityAnnotationsFromType(DRE->getType()); |
| 398 | }); |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 399 | } |
| 400 | |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 401 | void transferNonFlowSensitiveMemberExpr( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 402 | const MemberExpr *ME, const MatchFinder::MatchResult &MR, |
| 403 | TransferState<PointerNullabilityLattice> &State) { |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 404 | computeNullability(ME, State, [&]() { |
Googler | d443731 | 2023-01-17 15:10:29 -0800 | [diff] [blame] | 405 | auto BaseNullability = getNullabilityForChild(ME->getBase(), State); |
| 406 | QualType MemberType = ME->getType(); |
| 407 | // When a MemberExpr is a part of a member function call |
| 408 | // (a child of CXXMemberCallExpr), the MemberExpr models a |
| 409 | // partially-applied member function, which isn't a real C++ construct. |
| 410 | // The AST does not provide rich type information for such MemberExprs. |
| 411 | // Instead, the AST specifies a placeholder type, specifically |
| 412 | // BuiltinType::BoundMember. So we have to look at the type of the member |
| 413 | // function declaration. |
| 414 | if (ME->hasPlaceholderType(BuiltinType::BoundMember)) { |
| 415 | MemberType = ME->getMemberDecl()->getType(); |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 416 | } |
Googler | d443731 | 2023-01-17 15:10:29 -0800 | [diff] [blame] | 417 | return substituteNullabilityAnnotationsInClassTemplate( |
| 418 | MemberType, BaseNullability, ME->getBase()->getType()); |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 419 | }); |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Dani Ferreira Franco Moura | 826c8b3 | 2023-01-04 07:24:10 -0800 | [diff] [blame] | 422 | void transferNonFlowSensitiveMemberCallExpr( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 423 | const CXXMemberCallExpr *MCE, const MatchFinder::MatchResult &MR, |
| 424 | TransferState<PointerNullabilityLattice> &State) { |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 425 | computeNullability(MCE, State, [&]() { |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 426 | return ArrayRef(getNullabilityForChild(MCE->getCallee(), State)) |
Martin Brænne | c490306 | 2023-04-24 23:40:36 -0700 | [diff] [blame] | 427 | .take_front(countPointersInType(MCE)) |
| 428 | .vec(); |
Dani Ferreira Franco Moura | 826c8b3 | 2023-01-04 07:24:10 -0800 | [diff] [blame] | 429 | }); |
| 430 | } |
| 431 | |
Dani Ferreira Franco Moura | 933a69b | 2023-01-12 11:03:42 -0800 | [diff] [blame] | 432 | void transferNonFlowSensitiveCastExpr( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 433 | const CastExpr *CE, const MatchFinder::MatchResult &MR, |
| 434 | TransferState<PointerNullabilityLattice> &State) { |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 435 | computeNullability(CE, State, [&]() -> TypeNullability { |
Sam McCall | 2245db2 | 2023-04-17 06:50:25 -0700 | [diff] [blame] | 436 | // Most casts that can convert ~unrelated types drop nullability in general. |
| 437 | // As a special case, preserve nullability of outer pointer types. |
| 438 | // For example, int* p; (void*)p; is a BitCast, but preserves nullability. |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 439 | auto PreserveTopLevelPointers = [&](TypeNullability V) { |
Sam McCall | 2245db2 | 2023-04-17 06:50:25 -0700 | [diff] [blame] | 440 | auto ArgNullability = getNullabilityForChild(CE->getSubExpr(), State); |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 441 | const PointerType *ArgType = dyn_cast<PointerType>( |
Sam McCall | 2245db2 | 2023-04-17 06:50:25 -0700 | [diff] [blame] | 442 | CE->getSubExpr()->getType().getCanonicalType().getTypePtr()); |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 443 | const PointerType *CastType = |
Sam McCall | 2245db2 | 2023-04-17 06:50:25 -0700 | [diff] [blame] | 444 | dyn_cast<PointerType>(CE->getType().getCanonicalType().getTypePtr()); |
| 445 | for (int I = 0; ArgType && CastType; ++I) { |
| 446 | V[I] = ArgNullability[I]; |
| 447 | ArgType = dyn_cast<PointerType>(ArgType->getPointeeType().getTypePtr()); |
| 448 | CastType = |
| 449 | dyn_cast<PointerType>(CastType->getPointeeType().getTypePtr()); |
| 450 | } |
| 451 | return V; |
| 452 | }; |
| 453 | |
| 454 | switch (CE->getCastKind()) { |
| 455 | // Casts between unrelated types: we can't say anything about nullability. |
| 456 | case CK_LValueBitCast: |
| 457 | case CK_BitCast: |
| 458 | case CK_LValueToRValueBitCast: |
| 459 | return PreserveTopLevelPointers(unspecifiedNullability(CE)); |
| 460 | |
| 461 | // Casts between equivalent types. |
| 462 | case CK_LValueToRValue: |
| 463 | case CK_NoOp: |
| 464 | case CK_AtomicToNonAtomic: |
| 465 | case CK_NonAtomicToAtomic: |
| 466 | case CK_AddressSpaceConversion: |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 467 | return getNullabilityForChild(CE->getSubExpr(), State); |
Sam McCall | 2245db2 | 2023-04-17 06:50:25 -0700 | [diff] [blame] | 468 | |
| 469 | // Controlled conversions between types |
| 470 | // TODO: these should be doable somehow |
| 471 | case CK_BaseToDerived: |
| 472 | case CK_DerivedToBase: |
| 473 | case CK_UncheckedDerivedToBase: |
| 474 | return PreserveTopLevelPointers(unspecifiedNullability(CE)); |
| 475 | case CK_UserDefinedConversion: |
| 476 | case CK_ConstructorConversion: |
| 477 | return unspecifiedNullability(CE); |
| 478 | |
| 479 | case CK_Dynamic: { |
| 480 | auto Result = unspecifiedNullability(CE); |
| 481 | // A dynamic_cast to pointer is null if the runtime check fails. |
| 482 | if (isa<PointerType>(CE->getType().getCanonicalType())) |
| 483 | Result.front() = NullabilityKind::Nullable; |
| 484 | return Result; |
| 485 | } |
| 486 | |
| 487 | // Primitive values have no nullability. |
| 488 | case CK_ToVoid: |
| 489 | case CK_MemberPointerToBoolean: |
| 490 | case CK_PointerToBoolean: |
| 491 | case CK_PointerToIntegral: |
| 492 | case CK_IntegralCast: |
| 493 | case CK_IntegralToBoolean: |
| 494 | case CK_IntegralToFloating: |
| 495 | case CK_FloatingToFixedPoint: |
| 496 | case CK_FixedPointToFloating: |
| 497 | case CK_FixedPointCast: |
| 498 | case CK_FixedPointToIntegral: |
| 499 | case CK_IntegralToFixedPoint: |
| 500 | case CK_FixedPointToBoolean: |
| 501 | case CK_FloatingToIntegral: |
| 502 | case CK_FloatingToBoolean: |
| 503 | case CK_BooleanToSignedIntegral: |
| 504 | case CK_FloatingCast: |
| 505 | case CK_FloatingRealToComplex: |
| 506 | case CK_FloatingComplexToReal: |
| 507 | case CK_FloatingComplexToBoolean: |
| 508 | case CK_FloatingComplexCast: |
| 509 | case CK_FloatingComplexToIntegralComplex: |
| 510 | case CK_IntegralRealToComplex: |
| 511 | case CK_IntegralComplexToReal: |
| 512 | case CK_IntegralComplexToBoolean: |
| 513 | case CK_IntegralComplexCast: |
| 514 | case CK_IntegralComplexToFloatingComplex: |
| 515 | return {}; |
| 516 | |
| 517 | // This can definitely be null! |
| 518 | case CK_NullToPointer: { |
| 519 | auto Nullability = getNullabilityAnnotationsFromType(CE->getType()); |
Martin Brænne | 60e4c36 | 2023-06-21 02:44:41 -0700 | [diff] [blame] | 520 | // Despite the name `NullToPointer`, the destination type of the cast |
| 521 | // may be `nullptr_t` (which is, itself, not a pointer type). |
| 522 | if (!CE->getType()->isNullPtrType()) |
| 523 | Nullability.front() = NullabilityKind::Nullable; |
Sam McCall | 2245db2 | 2023-04-17 06:50:25 -0700 | [diff] [blame] | 524 | return Nullability; |
| 525 | } |
| 526 | |
| 527 | // Pointers out of thin air, who knows? |
| 528 | case CK_IntegralToPointer: |
| 529 | return unspecifiedNullability(CE); |
| 530 | |
| 531 | // Decayed objects are never null. |
| 532 | case CK_ArrayToPointerDecay: |
| 533 | case CK_FunctionToPointerDecay: |
Sam McCall | 2245db2 | 2023-04-17 06:50:25 -0700 | [diff] [blame] | 534 | return prepend(NullabilityKind::NonNull, |
| 535 | getNullabilityForChild(CE->getSubExpr(), State)); |
| 536 | |
Martin Brænne | 381e2b9 | 2023-06-26 01:02:48 -0700 | [diff] [blame] | 537 | // Despite its name, the result type of `BuiltinFnToFnPtr` is a function, |
| 538 | // not a function pointer, so nullability doesn't change. |
| 539 | case CK_BuiltinFnToFnPtr: |
| 540 | return getNullabilityForChild(CE->getSubExpr(), State); |
| 541 | |
Sam McCall | 2245db2 | 2023-04-17 06:50:25 -0700 | [diff] [blame] | 542 | // TODO: what is our model of member pointers? |
| 543 | case CK_BaseToDerivedMemberPointer: |
| 544 | case CK_DerivedToBaseMemberPointer: |
| 545 | case CK_NullToMemberPointer: |
| 546 | case CK_ReinterpretMemberPointer: |
| 547 | case CK_ToUnion: // and unions? |
| 548 | return unspecifiedNullability(CE); |
| 549 | |
| 550 | // TODO: Non-C/C++ constructs, do we care about these? |
| 551 | case CK_CPointerToObjCPointerCast: |
| 552 | case CK_ObjCObjectLValueCast: |
| 553 | case CK_MatrixCast: |
| 554 | case CK_VectorSplat: |
| 555 | case CK_BlockPointerToObjCPointerCast: |
| 556 | case CK_AnyPointerToBlockPointerCast: |
| 557 | case CK_ARCProduceObject: |
| 558 | case CK_ARCConsumeObject: |
| 559 | case CK_ARCReclaimReturnedObject: |
| 560 | case CK_ARCExtendBlockObject: |
| 561 | case CK_CopyAndAutoreleaseBlockObject: |
| 562 | case CK_ZeroToOCLOpaqueType: |
| 563 | case CK_IntToOCLSampler: |
| 564 | return unspecifiedNullability(CE); |
| 565 | |
| 566 | case CK_Dependent: |
| 567 | CHECK(false) << "Shouldn't see dependent casts here?"; |
| 568 | } |
Dani Ferreira Franco Moura | 933a69b | 2023-01-12 11:03:42 -0800 | [diff] [blame] | 569 | }); |
| 570 | } |
| 571 | |
Dani Ferreira Franco Moura | aa2211d | 2023-01-17 09:40:30 -0800 | [diff] [blame] | 572 | void transferNonFlowSensitiveMaterializeTemporaryExpr( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 573 | const MaterializeTemporaryExpr *MTE, const MatchFinder::MatchResult &MR, |
| 574 | TransferState<PointerNullabilityLattice> &State) { |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 575 | computeNullability(MTE, State, [&]() { |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 576 | return getNullabilityForChild(MTE->getSubExpr(), State); |
Dani Ferreira Franco Moura | aa2211d | 2023-01-17 09:40:30 -0800 | [diff] [blame] | 577 | }); |
| 578 | } |
| 579 | |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 580 | void transferNonFlowSensitiveCallExpr( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 581 | const CallExpr *CE, const MatchFinder::MatchResult &MR, |
| 582 | TransferState<PointerNullabilityLattice> &State) { |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 583 | // TODO: Check CallExpr arguments in the diagnoser against the nullability of |
| 584 | // parameters. |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 585 | computeNullability(CE, State, [&]() { |
Martin Brænne | c490306 | 2023-04-24 23:40:36 -0700 | [diff] [blame] | 586 | // TODO(mboehme): Instead of relying on Clang to propagate nullability sugar |
| 587 | // to the `CallExpr`'s type, we should extract nullability directly from the |
| 588 | // callee `Expr . |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 589 | return substituteNullabilityAnnotationsInFunctionTemplate(CE->getType(), |
| 590 | CE); |
| 591 | }); |
| 592 | } |
| 593 | |
Googler | 2bccf74 | 2023-01-18 03:53:14 -0800 | [diff] [blame] | 594 | void transferNonFlowSensitiveUnaryOperator( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 595 | const UnaryOperator *UO, const MatchFinder::MatchResult &MR, |
| 596 | TransferState<PointerNullabilityLattice> &State) { |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 597 | computeNullability(UO, State, [&]() -> TypeNullability { |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 598 | switch (UO->getOpcode()) { |
| 599 | case UO_AddrOf: |
| 600 | return prepend(NullabilityKind::NonNull, |
| 601 | getNullabilityForChild(UO->getSubExpr(), State)); |
| 602 | case UO_Deref: |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 603 | return ArrayRef(getNullabilityForChild(UO->getSubExpr(), State)) |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 604 | .drop_front() |
| 605 | .vec(); |
Googler | 2bccf74 | 2023-01-18 03:53:14 -0800 | [diff] [blame] | 606 | |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 607 | case UO_PostInc: |
| 608 | case UO_PostDec: |
| 609 | case UO_PreInc: |
| 610 | case UO_PreDec: |
| 611 | case UO_Plus: |
| 612 | case UO_Minus: |
| 613 | case UO_Not: |
| 614 | case UO_LNot: |
| 615 | case UO_Real: |
| 616 | case UO_Imag: |
| 617 | case UO_Extension: |
| 618 | return getNullabilityForChild(UO->getSubExpr(), State); |
Googler | 2bccf74 | 2023-01-18 03:53:14 -0800 | [diff] [blame] | 619 | |
Googler | 5ef1bdf | 2023-01-18 04:01:15 -0800 | [diff] [blame] | 620 | case UO_Coawait: |
| 621 | // TODO: work out what to do here! |
| 622 | return unspecifiedNullability(UO); |
| 623 | } |
| 624 | }); |
Googler | 2bccf74 | 2023-01-18 03:53:14 -0800 | [diff] [blame] | 625 | } |
| 626 | |
Martin Brænne | 66bc243 | 2023-04-18 23:48:49 -0700 | [diff] [blame] | 627 | void transferNonFlowSensitiveNewExpr( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 628 | const CXXNewExpr *NE, const MatchFinder::MatchResult &MR, |
| 629 | TransferState<PointerNullabilityLattice> &State) { |
Martin Brænne | 66bc243 | 2023-04-18 23:48:49 -0700 | [diff] [blame] | 630 | computeNullability(NE, State, [&]() { |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 631 | TypeNullability result = getNullabilityAnnotationsFromType(NE->getType()); |
Martin Brænne | 66bc243 | 2023-04-18 23:48:49 -0700 | [diff] [blame] | 632 | result.front() = NE->shouldNullCheckAllocation() ? NullabilityKind::Nullable |
| 633 | : NullabilityKind::NonNull; |
| 634 | return result; |
| 635 | }); |
| 636 | } |
| 637 | |
Sam McCall | f2b62b3 | 2023-05-02 06:45:40 -0700 | [diff] [blame] | 638 | void transferNonFlowSensitiveArraySubscriptExpr( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 639 | const ArraySubscriptExpr *ASE, const MatchFinder::MatchResult &MR, |
| 640 | TransferState<PointerNullabilityLattice> &State) { |
Sam McCall | f2b62b3 | 2023-05-02 06:45:40 -0700 | [diff] [blame] | 641 | computeNullability(ASE, State, [&]() { |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 642 | auto &BaseNullability = getNullabilityForChild(ASE->getBase(), State); |
Sam McCall | f2b62b3 | 2023-05-02 06:45:40 -0700 | [diff] [blame] | 643 | CHECK(ASE->getBase()->getType()->isAnyPointerType()); |
Sam McCall | d127f93 | 2023-05-02 07:15:27 -0700 | [diff] [blame] | 644 | return ArrayRef(BaseNullability).slice(1).vec(); |
Sam McCall | f2b62b3 | 2023-05-02 06:45:40 -0700 | [diff] [blame] | 645 | }); |
| 646 | } |
| 647 | |
Martin Brænne | 834d4b8 | 2023-05-15 07:07:05 -0700 | [diff] [blame] | 648 | void transferNonFlowSensitiveThisExpr( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 649 | const CXXThisExpr *TE, const MatchFinder::MatchResult &MR, |
| 650 | TransferState<PointerNullabilityLattice> &State) { |
Martin Brænne | 834d4b8 | 2023-05-15 07:07:05 -0700 | [diff] [blame] | 651 | computeNullability(TE, State, [&]() { |
| 652 | TypeNullability result = getNullabilityAnnotationsFromType(TE->getType()); |
| 653 | result.front() = NullabilityKind::NonNull; |
| 654 | return result; |
| 655 | }); |
| 656 | } |
| 657 | |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 658 | auto buildNonFlowSensitiveTransferer() { |
| 659 | return CFGMatchSwitchBuilder<TransferState<PointerNullabilityLattice>>() |
| 660 | .CaseOfCFGStmt<DeclRefExpr>(ast_matchers::declRefExpr(), |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 661 | transferNonFlowSensitiveDeclRefExpr) |
| 662 | .CaseOfCFGStmt<MemberExpr>(ast_matchers::memberExpr(), |
| 663 | transferNonFlowSensitiveMemberExpr) |
Dani Ferreira Franco Moura | 826c8b3 | 2023-01-04 07:24:10 -0800 | [diff] [blame] | 664 | .CaseOfCFGStmt<CXXMemberCallExpr>(ast_matchers::cxxMemberCallExpr(), |
| 665 | transferNonFlowSensitiveMemberCallExpr) |
Dani Ferreira Franco Moura | 933a69b | 2023-01-12 11:03:42 -0800 | [diff] [blame] | 666 | .CaseOfCFGStmt<CastExpr>(ast_matchers::castExpr(), |
| 667 | transferNonFlowSensitiveCastExpr) |
Dani Ferreira Franco Moura | aa2211d | 2023-01-17 09:40:30 -0800 | [diff] [blame] | 668 | .CaseOfCFGStmt<MaterializeTemporaryExpr>( |
| 669 | ast_matchers::materializeTemporaryExpr(), |
| 670 | transferNonFlowSensitiveMaterializeTemporaryExpr) |
Dani Ferreira Franco Moura | a29a2a0 | 2023-01-17 10:57:45 -0800 | [diff] [blame] | 671 | .CaseOfCFGStmt<CallExpr>(ast_matchers::callExpr(), |
| 672 | transferNonFlowSensitiveCallExpr) |
Googler | 2bccf74 | 2023-01-18 03:53:14 -0800 | [diff] [blame] | 673 | .CaseOfCFGStmt<UnaryOperator>(ast_matchers::unaryOperator(), |
| 674 | transferNonFlowSensitiveUnaryOperator) |
Martin Brænne | 66bc243 | 2023-04-18 23:48:49 -0700 | [diff] [blame] | 675 | .CaseOfCFGStmt<CXXNewExpr>(ast_matchers::cxxNewExpr(), |
| 676 | transferNonFlowSensitiveNewExpr) |
Sam McCall | f2b62b3 | 2023-05-02 06:45:40 -0700 | [diff] [blame] | 677 | .CaseOfCFGStmt<ArraySubscriptExpr>( |
| 678 | ast_matchers::arraySubscriptExpr(), |
| 679 | transferNonFlowSensitiveArraySubscriptExpr) |
Martin Brænne | 834d4b8 | 2023-05-15 07:07:05 -0700 | [diff] [blame] | 680 | .CaseOfCFGStmt<CXXThisExpr>(ast_matchers::cxxThisExpr(), |
| 681 | transferNonFlowSensitiveThisExpr) |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 682 | .Build(); |
| 683 | } |
| 684 | |
| 685 | auto buildFlowSensitiveTransferer() { |
Dani Ferreira Franco Moura | 3d56a22 | 2022-11-29 03:12:55 -0800 | [diff] [blame] | 686 | return CFGMatchSwitchBuilder<TransferState<PointerNullabilityLattice>>() |
Dani Ferreira Franco Moura | 309f2d7 | 2022-11-15 07:09:00 -0800 | [diff] [blame] | 687 | // Handles initialization of the null states of pointers. |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 688 | .CaseOfCFGStmt<Expr>(isAddrOf(), transferFlowSensitiveNotNullPointer) |
Martin Brænne | 834d4b8 | 2023-05-15 07:07:05 -0700 | [diff] [blame] | 689 | // TODO(mboehme): I believe we should be able to move handling of null |
| 690 | // pointers to the non-flow-sensitive part of the analysis. |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 691 | .CaseOfCFGStmt<Expr>(isNullPointerLiteral(), |
| 692 | transferFlowSensitiveNullPointer) |
| 693 | .CaseOfCFGStmt<CallExpr>(isCallExpr(), transferFlowSensitiveCallExpr) |
| 694 | .CaseOfCFGStmt<Expr>(isPointerExpr(), transferFlowSensitivePointer) |
Dani Ferreira Franco Moura | 309f2d7 | 2022-11-15 07:09:00 -0800 | [diff] [blame] | 695 | // Handles comparison between 2 pointers. |
Wei Yi Tee | 217eb5f | 2022-09-15 03:18:28 -0700 | [diff] [blame] | 696 | .CaseOfCFGStmt<BinaryOperator>(isPointerCheckBinOp(), |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 697 | transferFlowSensitiveNullCheckComparison) |
Dani Ferreira Franco Moura | 309f2d7 | 2022-11-15 07:09:00 -0800 | [diff] [blame] | 698 | // Handles checking of pointer as boolean. |
Wei Yi Tee | 217eb5f | 2022-09-15 03:18:28 -0700 | [diff] [blame] | 699 | .CaseOfCFGStmt<Expr>(isImplicitCastPointerToBool(), |
Dani Ferreira Franco Moura | 5d2aff4 | 2023-01-03 03:42:01 -0800 | [diff] [blame] | 700 | transferFlowSensitiveNullCheckImplicitCastPtrToBool) |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 701 | .Build(); |
| 702 | } |
| 703 | } // namespace |
| 704 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 705 | PointerNullabilityAnalysis::PointerNullabilityAnalysis(ASTContext &Context) |
Dani Ferreira Franco Moura | 3d56a22 | 2022-11-29 03:12:55 -0800 | [diff] [blame] | 706 | : DataflowAnalysis<PointerNullabilityAnalysis, PointerNullabilityLattice>( |
| 707 | Context), |
Dani Ferreira Franco Moura | 97f5c61 | 2022-12-17 13:28:24 -0800 | [diff] [blame] | 708 | NonFlowSensitiveTransferer(buildNonFlowSensitiveTransferer()), |
| 709 | FlowSensitiveTransferer(buildFlowSensitiveTransferer()) {} |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 710 | |
Sam McCall | 74bf864 | 2023-06-16 11:21:42 -0700 | [diff] [blame] | 711 | PointerTypeNullability PointerNullabilityAnalysis::assignNullabilityVariable( |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 712 | const ValueDecl *D, dataflow::Arena &A) { |
Sam McCall | 74bf864 | 2023-06-16 11:21:42 -0700 | [diff] [blame] | 713 | auto [It, Inserted] = NFS.DeclTopLevelNullability.try_emplace(D); |
| 714 | if (Inserted) { |
| 715 | It->second.Nonnull = &A.create<dataflow::AtomicBoolValue>(); |
| 716 | It->second.Nullable = &A.create<dataflow::AtomicBoolValue>(); |
| 717 | } |
| 718 | return It->second; |
| 719 | } |
| 720 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 721 | void PointerNullabilityAnalysis::transfer(const CFGElement &Elt, |
| 722 | PointerNullabilityLattice &Lattice, |
| 723 | Environment &Env) { |
Dani Ferreira Franco Moura | 3d56a22 | 2022-11-29 03:12:55 -0800 | [diff] [blame] | 724 | TransferState<PointerNullabilityLattice> State(Lattice, Env); |
Googler | 9949b46 | 2023-02-15 05:09:07 -0800 | [diff] [blame] | 725 | NonFlowSensitiveTransferer(Elt, getASTContext(), State); |
| 726 | FlowSensitiveTransferer(Elt, getASTContext(), State); |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 729 | BoolValue &mergeBoolValues(BoolValue &Bool1, const Environment &Env1, |
| 730 | BoolValue &Bool2, const Environment &Env2, |
| 731 | Environment &MergedEnv) { |
Wei Yi Tee | 721ee97 | 2022-08-11 01:14:54 -0700 | [diff] [blame] | 732 | if (&Bool1 == &Bool2) { |
| 733 | return Bool1; |
| 734 | } |
| 735 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 736 | auto &MergedBool = MergedEnv.makeAtomicBoolValue(); |
Wei Yi Tee | 721ee97 | 2022-08-11 01:14:54 -0700 | [diff] [blame] | 737 | |
| 738 | // If `Bool1` and `Bool2` is constrained to the same true / false value, |
| 739 | // `MergedBool` can be constrained similarly without needing to consider the |
| 740 | // path taken - this simplifies the flow condition tracked in `MergedEnv`. |
| 741 | // Otherwise, information about which path was taken is used to associate |
| 742 | // `MergedBool` with `Bool1` and `Bool2`. |
| 743 | if (Env1.flowConditionImplies(Bool1) && Env2.flowConditionImplies(Bool2)) { |
| 744 | MergedEnv.addToFlowCondition(MergedBool); |
| 745 | } else if (Env1.flowConditionImplies(Env1.makeNot(Bool1)) && |
| 746 | Env2.flowConditionImplies(Env2.makeNot(Bool2))) { |
| 747 | MergedEnv.addToFlowCondition(MergedEnv.makeNot(MergedBool)); |
| 748 | } else { |
| 749 | // TODO(b/233582219): Flow conditions are not necessarily mutually |
Dani Ferreira Franco Moura | 309f2d7 | 2022-11-15 07:09:00 -0800 | [diff] [blame] | 750 | // exclusive, a fix is in order: https://reviews.llvm.org/D130270. Update |
| 751 | // this section when the patch is commited. |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 752 | auto &FC1 = Env1.getFlowConditionToken(); |
| 753 | auto &FC2 = Env2.getFlowConditionToken(); |
Wei Yi Tee | 721ee97 | 2022-08-11 01:14:54 -0700 | [diff] [blame] | 754 | MergedEnv.addToFlowCondition(MergedEnv.makeOr( |
| 755 | MergedEnv.makeAnd(FC1, MergedEnv.makeIff(MergedBool, Bool1)), |
| 756 | MergedEnv.makeAnd(FC2, MergedEnv.makeIff(MergedBool, Bool2)))); |
| 757 | } |
| 758 | return MergedBool; |
| 759 | } |
| 760 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 761 | bool PointerNullabilityAnalysis::merge(QualType Type, const Value &Val1, |
| 762 | const Environment &Env1, |
| 763 | const Value &Val2, |
| 764 | const Environment &Env2, |
| 765 | Value &MergedVal, |
| 766 | Environment &MergedEnv) { |
Wei Yi Tee | 721ee97 | 2022-08-11 01:14:54 -0700 | [diff] [blame] | 767 | if (!Type->isAnyPointerType()) { |
| 768 | return false; |
| 769 | } |
| 770 | |
Martin Brænne | ed01de6 | 2023-06-13 05:45:21 -0700 | [diff] [blame] | 771 | if (!hasPointerNullState(cast<PointerValue>(Val1)) || |
| 772 | !hasPointerNullState(cast<PointerValue>(Val2))) { |
| 773 | return false; |
| 774 | } |
| 775 | |
Googler | f164e03 | 2023-05-18 08:38:51 -0700 | [diff] [blame] | 776 | auto [Known1, Null1] = getPointerNullState(cast<PointerValue>(Val1)); |
| 777 | auto [Known2, Null2] = getPointerNullState(cast<PointerValue>(Val2)); |
Wei Yi Tee | 721ee97 | 2022-08-11 01:14:54 -0700 | [diff] [blame] | 778 | |
Sam McCall | 7d9afee | 2023-06-27 01:43:24 -0700 | [diff] [blame] | 779 | auto &Known = mergeBoolValues(Known1, Env1, Known2, Env2, MergedEnv); |
| 780 | auto &Null = mergeBoolValues(Null1, Env1, Null2, Env2, MergedEnv); |
Wei Yi Tee | 721ee97 | 2022-08-11 01:14:54 -0700 | [diff] [blame] | 781 | |
Dani Ferreira Franco Moura | a064982 | 2022-11-11 07:55:05 -0800 | [diff] [blame] | 782 | initPointerNullState(cast<PointerValue>(MergedVal), MergedEnv, &Known, &Null); |
Wei Yi Tee | 721ee97 | 2022-08-11 01:14:54 -0700 | [diff] [blame] | 783 | |
| 784 | return true; |
Wei Yi Tee | 543af74 | 2022-06-01 06:52:24 -0700 | [diff] [blame] | 785 | } |
Sam McCall | 5fc2a80 | 2023-05-02 05:41:27 -0700 | [diff] [blame] | 786 | |
Sam McCall | 4f6be42 | 2023-06-27 02:51:22 -0700 | [diff] [blame] | 787 | } // namespace clang::tidy::nullability |