Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 0e8d4a6d 21-Dec-2022 Yitzhak Mandelbaum <yitzhakm@google.com>

[clang][dataflow] Simplify handling of nullopt-optionals.

Previously, in the case of an optional constructed from `nullopt`, we relied on
the value constructed for the `nullopt`. This complicates th

[clang][dataflow] Simplify handling of nullopt-optionals.

Previously, in the case of an optional constructed from `nullopt`, we relied on
the value constructed for the `nullopt`. This complicates the implementation and
exposes it to bugs (indeed, one such was found), yet doesn't improve the
engine. Instead, this patch constructs a fresh optional representation, rather
than relying on the underlying nullopt representation.

Differential Revision: https://reviews.llvm.org/D140506

show more ...


# 5d22d1f5 14-Dec-2022 Yitzhak Mandelbaum <yitzhakm@google.com>

[clang][dataflow] Improve optional model's support for ignoring smart pointers.

The optional model has an option to ignore optionals accessed through smart
pointer types (other than optional itself)

[clang][dataflow] Improve optional model's support for ignoring smart pointers.

The optional model has an option to ignore optionals accessed through smart
pointer types (other than optional itself). This patch improves this feature in
two ways:

1. We extend support to optionals accessed directly through the smart pointer,
like `ptr->value()`. Previously, support was limited to cases that went through
an intermediate field.

2. We clean up the implementation by removing the option from the analysis,
leaving it only in the diagnostic phase (where it is relevant).

3. Adjusts a test which was misleading in what it was testing.

Differential Revision: https://reviews.llvm.org/D140020

show more ...


# 82d50fef 13-Dec-2022 Dani Ferreira Franco Moura <danimoura@google.com>

[clang][dataflow] Change the diagnoser API to receive a correctly typed lattice element

Previously, the diagnoser could only receive the Environment at a given program point. Now, it receives the co

[clang][dataflow] Change the diagnoser API to receive a correctly typed lattice element

Previously, the diagnoser could only receive the Environment at a given program point. Now, it receives the complete dataflow state: the environment and lattice element.

This change does not contain any tests because we modify the checkDataflow function to rely on the newly introduced lattice element in PostVisitCFG, and existing tests that verify lattice elements depend on this overload of checkDataflow.

Reviewed By: gribozavr2, ymandel

Differential Revision: https://reviews.llvm.org/D139868

show more ...


# ef463545 07-Dec-2022 Yitzhak Mandelbaum <yitzhakm@google.com>

[clang][dataflow] Add support for structured bindings of tuple-like types.

This patch adds interpretation of binding declarations resulting from a
structured binding (`DecompositionDecl`) to a tuple

[clang][dataflow] Add support for structured bindings of tuple-like types.

This patch adds interpretation of binding declarations resulting from a
structured binding (`DecompositionDecl`) to a tuple-like type. Currently, the
framework only supports binding to a struct.

Fixes issue #57252.

Differential Revision: https://reviews.llvm.org/D139544

show more ...


# 390029be 05-Dec-2022 Yitzhak Mandelbaum <yitzhakm@google.com>

[clang][dataflow] Support (in)equality operators in `optional` model.

This patch adds interpretation of the overloaded equality and inequality
operators available for the optional types.

Fixes issu

[clang][dataflow] Support (in)equality operators in `optional` model.

This patch adds interpretation of the overloaded equality and inequality
operators available for the optional types.

Fixes issue #57253.

Differential Revision: https://reviews.llvm.org/D139360

show more ...


Revision tags: llvmorg-15.0.6, llvmorg-15.0.5, llvmorg-15.0.4, llvmorg-15.0.3, working, llvmorg-15.0.2, llvmorg-15.0.1
# 7538b360 19-Sep-2022 Wei Yi Tee <wyt@google.com>

[clang][dataflow] Replace usage of deprecated functions with the optional check

- Update `transfer` and `diagnose` to take `const CFGElement *` as input in `Analysis/FlowSensitive/Models/UncheckedOp

[clang][dataflow] Replace usage of deprecated functions with the optional check

- Update `transfer` and `diagnose` to take `const CFGElement *` as input in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`.
- Update `clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp` accordingly.
- Rename `runDataflowAnalysisOnCFG` to `runDataflowAnalysis` and remove the deprecated `runDataflowAnalysis` (this was only used by the now updated optional check).

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D133930

show more ...


# a4f8e3d2 16-Sep-2022 Wei Yi Tee <wyt@google.com>

Revert "[clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`."

This reverts commit 41f235d

Revert "[clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`."

This reverts commit 41f235d26887946f472d71a8417507c35d5f9074.

Details at https://lab.llvm.org/buildbot#builders/139/builds/28171.
Breakage due to API change.

show more ...


# 41f235d2 16-Sep-2022 Wei Yi Tee <wyt@google.com>

[clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`.

Reviewed By: gribozavr2, sgatev

Dif

[clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D133930

show more ...


Revision tags: llvmorg-15.0.0
# db898d43 01-Sep-2022 Wei Yi Tee <wyt@google.com>

[clang][dataflow] Refactor `TestingSupport.h`

- Add `AnalysisInputs` struct as the parameters for `checkDataflow`, and renamed `AnalysisData` struct to `AnalysisOutputs` which contains the data stru

[clang][dataflow] Refactor `TestingSupport.h`

- Add `AnalysisInputs` struct as the parameters for `checkDataflow`, and renamed `AnalysisData` struct to `AnalysisOutputs` which contains the data structures generated from a dataflow analysis run.

- Remove compulsory binding from statement to annotations. Instead, `checkDataflow` in the most general form takes a `VerifyResults` callback which takes as input an `AnalysisOutputs` struct. This struct contains the data structures generated by the analysis that can then be tested. We then introduce two overloads/wrappers of `checkDataflow` for different mechanisms of testing - one which exposes annotation line numbers and is not restricted to statements, and the other which exposes states computed after annotated statements. In the future, we should look at retrieving the analysis states for constructs other than statements.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D132147

show more ...


Revision tags: llvmorg-15.0.0-rc3, llvmorg-15.0.0-rc2
# c44c7184 02-Aug-2022 Stanislav Gatev <sgatev@google.com>

[clang][dataflow] Make the type of the post visit callback consistent

Make the types of the post visit callbacks in `transferBlock` and
`runTypeErasedDataflowAnalysis` consistent.

Differential Revi

[clang][dataflow] Make the type of the post visit callback consistent

Make the types of the post visit callbacks in `transferBlock` and
`runTypeErasedDataflowAnalysis` consistent.

Differential Revision: https://reviews.llvm.org/D131014

Reviewed-by: ymandel, xazax.hun, gribozavr2

show more ...


Revision tags: llvmorg-15.0.0-rc1, llvmorg-16-init
# 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, 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 ...


# 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 ...


# 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
# 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 ...


Revision tags: llvmorg-14.0.0, llvmorg-14.0.0-rc4, llvmorg-14.0.0-rc3
# 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 ...


12