#
8361877b |
| 29-Jun-2022 |
Sam Estep <sam@samestep.com> |
Revert "[clang][dataflow] Use NoopLattice in optional model"
This reverts commit 335c05f5d19fecd5c0972ac801e58248d772a78e.
|
#
335c05f5 |
| 29-Jun-2022 |
Sam Estep <sam@samestep.com> |
[clang][dataflow] Use NoopLattice in optional model
Followup to D128352. This patch pulls the `NoopLattice` class out from the `NoopAnalysis.h` test file into its own `NoopLattice.h` source file, an
[clang][dataflow] Use NoopLattice in optional model
Followup to D128352. This patch pulls the `NoopLattice` class out from the `NoopAnalysis.h` test file into its own `NoopLattice.h` source file, and uses it to replace usage of `SourceLocationsLattice` in `UncheckedOptionalAccessModel`.
Reviewed By: ymandel, sgatev, gribozavr2, xazax.hun
Differential Revision: https://reviews.llvm.org/D128356
show more ...
|
#
58fe7f96 |
| 29-Jun-2022 |
Sam Estep <sam@samestep.com> |
[clang][dataflow] Add API to separate analysis from diagnosis
This patch adds an optional `PostVisitStmt` parameter to the `runTypeErasedDataflowAnalysis` function, which does one more pass over all
[clang][dataflow] Add API to separate analysis from diagnosis
This patch adds an optional `PostVisitStmt` parameter to the `runTypeErasedDataflowAnalysis` function, which does one more pass over all statements in the CFG after a fixpoint is reached. It then defines a `diagnose` method for the optional model in a new `UncheckedOptionalAccessDiagnosis` class, but only integrates that into the tests and not the actual optional check for `clang-tidy`. That will be done in a followup patch.
The primary motivation is to separate the implementation of the unchecked optional access check into two parts, to allow for further refactoring of just the model part later, while leaving the checking part alone. Currently there is duplication between the `transferUnwrapCall` and `diagnoseUnwrapCall` functions, but that will be dealt with in the followup.
Because diagnostics are now all gathered into one collection rather than being populated at each program point like when computing a fixpoint, this patch removes the usage of `Pair` and `UnorderedElementsAre` from the optional model tests, and instead modifies all their expectations to simply check the stringified set of diagnostics against a single string, either `"safe"` or some concatenation of `"unsafe: input.cc:y:x"`. This is not ideal as it loses any connection to the `/*[[check]]*/` annotations in the source strings, but it does still retain the source locations from the diagnostic strings themselves.
Reviewed By: sgatev, gribozavr2, xazax.hun
Differential Revision: https://reviews.llvm.org/D127898
show more ...
|
Revision tags: llvmorg-14.0.6 |
|
#
06decd0b |
| 19-Jun-2022 |
Kazu Hirata <kazu@google.com> |
[clang] Use value_or instead of getValueOr (NFC)
|
Revision tags: llvmorg-14.0.5, llvmorg-14.0.4 |
|
#
8fcdd625 |
| 18-May-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Add support for correlated branches to optional model
Add support for correlated branches to the std::optional dataflow model.
Differential Revision: https://reviews.llvm.org/D125
[clang][dataflow] Add support for correlated branches to optional model
Add support for correlated branches to the std::optional dataflow model.
Differential Revision: https://reviews.llvm.org/D125931
Reviewed-by: ymandel, xazax.hun
show more ...
|
#
97d69cda |
| 14-Jun-2022 |
Wei Yi Tee <wyt@google.com> |
[clang][dataflow] Rename `getPointeeLoc` to `getReferentLoc` for ReferenceValue.
We distinguish between the referent location for `ReferenceValue` and pointee location for `PointerValue`. The former
[clang][dataflow] Rename `getPointeeLoc` to `getReferentLoc` for ReferenceValue.
We distinguish between the referent location for `ReferenceValue` and pointee location for `PointerValue`. The former must be non-empty but the latter may be empty in the case of a `nullptr`
Reviewed By: gribozavr2, sgatev
Differential Revision: https://reviews.llvm.org/D127745
show more ...
|
#
a9ad689e |
| 10-Jun-2022 |
Sam Estep <sam@samestep.com> |
[clang][dataflow] Don't `assert` full LHS coverage in `optional` model
Followup to D127434.
Reviewed By: ymandel, sgatev
Differential Revision: https://reviews.llvm.org/D127502
|
#
cd0d5261 |
| 10-Jun-2022 |
Sam Estep <sam@samestep.com> |
[clang][dataflow] In `optional` model, match call return via hasType
Currently the unchecked-optional-access model fails on this example:
#include <memory> #include <optional>
void foo
[clang][dataflow] In `optional` model, match call return via hasType
Currently the unchecked-optional-access model fails on this example:
#include <memory> #include <optional>
void foo() { std::unique_ptr<std::optional<float>> x; *x = std::nullopt; }
You can verify the failure by saving the file as `foo.cpp` and running this command:
clang-tidy -checks='-*,bugprone-unchecked-optional-access' foo.cpp -- -std=c++17
The failing `assert` is in the `transferAssignment` function of the `UncheckedOptionalAccessModel.cpp` file:
assert(OptionalLoc != nullptr);
The symptom can be treated by replacing that `assert` with an early `return`:
if (OptionalLoc == nullptr) return;
That would be better anyway since we cannot expect to always cover all possible LHS expressions, but it is out of scope for this patch and left as a followup.
Note that the failure did not occur on this very similar example:
#include <optional>
template <typename T> struct smart_ptr { T& operator*() &; T* operator->(); };
void foo() { smart_ptr<std::optional<float>> x; *x = std::nullopt; }
The difference is caused by the `isCallReturningOptional` matcher, which was previously checking the `functionDecl` of the `callee`. This patch changes it to instead use `hasType` directly on the call expression, fixing the failure for the `std::unique_ptr` example above.
Reviewed By: sgatev
Differential Revision: https://reviews.llvm.org/D127434
show more ...
|
#
dd38caf3 |
| 03-May-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang][dataflow] Track `optional` contents in `optional` model.
This patch adds partial support for tracking (i.e. modeling) the contents of an optional value. Specifically, it supports tracking th
[clang][dataflow] Track `optional` contents in `optional` model.
This patch adds partial support for tracking (i.e. modeling) the contents of an optional value. Specifically, it supports tracking the value after it is accessed. We leave tracking constructed/assigned contents to a future patch.
Differential Revision: https://reviews.llvm.org/D124932
show more ...
|
#
49ed5bf5 |
| 08-Jun-2022 |
Wei Yi Tee <wyt@google.com> |
[clang][dataflow] Enable use of synthetic properties on all Value instances.
This patch moves the implementation of synthetic properties from the StructValue class into the Value base class so that
[clang][dataflow] Enable use of synthetic properties on all Value instances.
This patch moves the implementation of synthetic properties from the StructValue class into the Value base class so that it can be used across all Value instances.
Reviewed By: gribozavr2, ymandel, sgatev, xazax.hun
Differential Revision: https://reviews.llvm.org/D127196
show more ...
|
#
6adfc64e |
| 03-Jun-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang][dataflow] Modify `optional` model to handle type aliases.
Previously, type aliases were not handled (and resulted in an assertion firing). This patch generalizes the model to consider aliase
[clang][dataflow] Modify `optional` model to handle type aliases.
Previously, type aliases were not handled (and resulted in an assertion firing). This patch generalizes the model to consider aliases everywhere (a previous patch already considered aliases for optional-returning functions).
Differential Revision: https://reviews.llvm.org/D126972
show more ...
|
#
65e710c3 |
| 01-Jun-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Model calls returning optionals
Model calls returning optionals
Differential Revision: https://reviews.llvm.org/D126759
Reviewed-by: ymandel, xazax.hun
|
Revision tags: llvmorg-14.0.3, llvmorg-14.0.2, llvmorg-14.0.1, llvmorg-14.0.0, llvmorg-14.0.0-rc4, llvmorg-14.0.0-rc3 |
|
#
7e63a0d4 |
| 06-Mar-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang-tidy] New check for safe usage of `std::optional` and like types.
This check verifies the safety of access to `std::optional` and related types (including `absl::optional`). It is based on a
[clang-tidy] New check for safe usage of `std::optional` and like types.
This check verifies the safety of access to `std::optional` and related types (including `absl::optional`). It is based on a corresponding Clang Dataflow Analysis, which does most of the work. This check merely runs it and converts its findings into diagnostics.
Differential Revision: https://reviews.llvm.org/D121120
show more ...
|
#
7f076004 |
| 21-Mar-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang][dataflow] Add support for `value_or` in a comparison.
This patch adds limited modeling of the `value_or` method. Specifically, when used in a particular idiom in a comparison to implicitly c
[clang][dataflow] Add support for `value_or` in a comparison.
This patch adds limited modeling of the `value_or` method. Specifically, when used in a particular idiom in a comparison to implicitly check whether the optional holds a value.
Differential Revision: https://reviews.llvm.org/D122231
show more ...
|
#
a184a0d8 |
| 21-Mar-2022 |
Yitzhak Mandelbaum <yitzhakm@google.com> |
[clang][dataflow] Add support for disabling warnings on smart pointers.
This patch provides the user with the ability to disable all checked of accesses to optionals that are the pointees of smart p
[clang][dataflow] Add support for disabling warnings on smart pointers.
This patch provides the user with the ability to disable all checked of accesses to optionals that are the pointees of smart pointers. Since smart pointers are not modeled (yet), the system cannot distinguish safe from unsafe accesses to optionals through smart pointers. This results in false positives whenever optionals are used through smart pointers. The patch gives the user the choice of ignoring all positivess in these cases.
Differential Revision: https://reviews.llvm.org/D122143
show more ...
|
#
2ddd57ae |
| 21-Mar-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Model the behavior of optional and std swap
Differential Revision: https://reviews.llvm.org/D122129
Reviewed-by: ymandel, xazax.hun
|
#
b000b770 |
| 16-Mar-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Model the behavior of non-standard optional assignment
Model nullopt, value, and conversion assignment operators.
Reviewed-by: xazax.hun
Differential Revision: https://reviews.ll
[clang][dataflow] Model the behavior of non-standard optional assignment
Model nullopt, value, and conversion assignment operators.
Reviewed-by: xazax.hun
Differential Revision: https://reviews.llvm.org/D121863
show more ...
|
#
092a530c |
| 14-Mar-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Model the behavior of non-standard optional constructors
Model nullopt, inplace, value, and conversion constructors.
Reviewed-by: ymandel, xazax.hun, gribozavr2
Differential Revi
[clang][dataflow] Model the behavior of non-standard optional constructors
Model nullopt, inplace, value, and conversion constructors.
Reviewed-by: ymandel, xazax.hun, gribozavr2
Differential Revision: https://reviews.llvm.org/D121602
show more ...
|
#
9e0fc676 |
| 10-Mar-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Model the behavior of various optional members
Model `make_optional`, optional's default constructor, `emplace`, `reset`, and `operator bool` members.
Reviewed-by: xazax.hun
Diff
[clang][dataflow] Model the behavior of various optional members
Model `make_optional`, optional's default constructor, `emplace`, `reset`, and `operator bool` members.
Reviewed-by: xazax.hun
Differential Revision: https://reviews.llvm.org/D121378
show more ...
|
#
af98b0af |
| 10-Mar-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Add analysis that detects unsafe accesses to optionals
This commit reverts e0cc28dfdc67105974924cce42bb8c85bd44925a and moves UncheckedOptionalAccessModelTest.cpp into clang/unitte
[clang][dataflow] Add analysis that detects unsafe accesses to optionals
This commit reverts e0cc28dfdc67105974924cce42bb8c85bd44925a and moves UncheckedOptionalAccessModelTest.cpp into clang/unittests/Analysis/FlowSensitive, to avoid build failures. The test will be moved back into a Models subdir in a follow up patch that will address the build configuration issues.
Original description:
Adds a dataflow analysis that detects unsafe accesses to values of type `std::optional`, `absl::optional`, or `base::Optional`.
Reviewed-by: ymandel, xazax.hun
Differential Revision: https://reviews.llvm.org/D121197
show more ...
|
#
ce205cff |
| 08-Mar-2022 |
Stanislav Gatev <sgatev@google.com> |
[clang][dataflow] Add analysis that detects unsafe accesses to optionals
Adds a dataflow analysis that detects unsafe accesses to values of type `std::optional`, `absl::optional`, or `base::Optional
[clang][dataflow] Add analysis that detects unsafe accesses to optionals
Adds a dataflow analysis that detects unsafe accesses to values of type `std::optional`, `absl::optional`, or `base::Optional`.
Reviewed-by: ymandel, xazax.hun
Differential Revision: https://reviews.llvm.org/D121197
show more ...
|