20 Commits

Author SHA1 Message Date
Florian Mayer
356ca4036d [FlowSensitive] [StatusOr] cache return values for all accessors
This is important for iterators that often return pairs containing
StatusOr.

Pull Request: https://github.com/llvm/llvm-project/pull/179807
2026-02-05 10:21:07 -08:00
Florian Mayer
483d9bb9e4 [FlowSensitive] [StatusOr] cache pointers for all const methods
This is important to support iterators, that often return pairs
containing StatusOr.

Pull Request: https://github.com/llvm/llvm-project/pull/179791
2026-02-05 10:21:03 -08:00
Florian Mayer
56fb92ae64
[NFC] [FlowSensitive] [StatusOr] expose statusType in header (#171719) 2025-12-10 22:50:00 +00:00
Florian Mayer
e603fac7cb
[FlowSensitive] [StatusOr] [15/15] Support references to Status(Or) ptrs
That hopefully concludes the initial upstreaming.

Reviewers: jvoung

Reviewed By: jvoung

Pull Request: https://github.com/llvm/llvm-project/pull/170951
2025-12-10 14:40:12 -08:00
Florian Mayer
ddc638c11d
[FlowSensitive] [StatusOr] [14/N] Support nested StatusOrs
Reviewers: jvoung

Reviewed By: jvoung

Pull Request: https://github.com/llvm/llvm-project/pull/170950
2025-12-10 14:32:25 -08:00
Florian Mayer
d34c71744a
[FlowSensitive] [StatusOr] [13/N] Add support for gtest ASSERTs
Reviewers: jvoung

Reviewed By: jvoung

Pull Request: https://github.com/llvm/llvm-project/pull/170947
2025-12-10 14:12:56 -08:00
Florian Mayer
f6971bf25d
[FlowSensitive] [StatusOr] [12/N] Add support for smart pointers (#170943) 2025-12-08 20:56:22 +00:00
Florian Mayer
bb79b35068
[FlowSensitive] [StatusOr] [11/N] Assume const accessor calls are stable (#170935)
This is not necessarily correct, but prevents us from flagging lots of
false positives because code usually abides by this.
2025-12-08 12:27:44 -08:00
Florian Mayer
c19e0b2c20
[StatusOr] [10/N] Add support for absl CHECK macros (#169749) 2025-12-04 21:15:13 +00:00
Florian Mayer
4ed494e728
[FlowSensitive] [StatusOr] [9/N] Make sure all StatusOr are initialized
This is important if the first use of a StatusOr (or Status) is in a
conditional statement, we need a stable value for `ok` from outside of
the conditional statement to make sure we don't use a different variable
in every branch.

Reviewers: jvoung, Xazax-hun

Reviewed By: jvoung

Pull Request: https://github.com/llvm/llvm-project/pull/163898
2025-10-27 09:29:24 -07:00
Florian Mayer
430d0edb52
[FlowSensitive] [StatusOr] [8/N] Support value ctor and assignment
Reviewers: jvoung, Xazax-hun

Reviewed By: jvoung

Pull Request: https://github.com/llvm/llvm-project/pull/163894
2025-10-27 09:27:19 -07:00
Florian Mayer
c745f745b1
[FlowSensitive] [StatusOr] [7/N] Support StatusOr::emplace
This always makes the StatusOr OK.

Reviewers: jvoung, Xazax-hun

Reviewed By: jvoung

Pull Request: https://github.com/llvm/llvm-project/pull/163876
2025-10-23 12:27:29 -07:00
Florian Mayer
83f751a001
[FlowSensitive] [StatusOr] [6/N] support pointer comparison (#164856) 2025-10-23 17:59:55 +00:00
Florian Mayer
764acd81de
[FlowSensitive] [StatusOr] [5/N] Support absl::OkStatus et al (#163872)
This allows comparison which these status codes
2025-10-22 15:06:45 -07:00
Florian Mayer
12f0e48c01
[FlowSensitive] [StatusOr] [4/N] Support comparisons (#163871) 2025-10-22 12:57:46 -07:00
Florian Mayer
419fbf906b
[FlowSensitive] [StatusOr] [3/N] Support absl::Status ops (#163868)
`absl::StatusOr::status` allows extraction of the status associated with
a StatusOr value. That can also be used to check whether the StatusOr
has a value or not.

This makes sure code like this is checked properly:

```cpp
int target(absl::StatusOr<int> SOR) {
  if (SOR.status().ok())
    return *SOR;
  return 0;
}
```
2025-10-21 13:50:08 -07:00
Florian Mayer
9c3ed5a389
[NFC] [FlowSensitive] [StatusOr] remove unused function (#164351) 2025-10-21 01:38:08 +00:00
Florian Mayer
0833b48760
Reapply "[FlowSensitive] [StatusOr] [2/N] Add minimal model" (#164040) (#164305)
This reverts commit eed8d3aa4aa6efe01fcf7bd56015b671f5f18e29.
2025-10-20 16:56:49 -07:00
Florian Mayer
eed8d3aa4a
Revert "[FlowSensitive] [StatusOr] [2/N] Add minimal model" (#164040)
Reverts llvm/llvm-project#162932

Failed Tests (1):
  Clang-Unit :: ./AllClangUnitTests/failed_to_discover_tests_from_gtest
2025-10-18 02:07:10 +00:00
Florian Mayer
fe029934eb
[FlowSensitive] [StatusOr] [2/N] Add minimal model (#162932)
This model implements a dataflow analysis for reporting instances of
unchecked use of absl::StatusOr values. It makes sure that every use
the value of a StatusOr object is dominated by a check that the
StatusOr object is ok.

This is an example of code that will be flagged by the analysis:

```cpp
int f(absl::StatusOr<int> SOR) {
  return SOR.value();
}
```

This is an example of code that will not be flagged by the analysis:

```cpp
int f(absl::StatusOr<int> SOR) {
  if (SOR.ok())
    return SOR.value();
  return 0;
}
```

This model has successfully been used by Google for some time now.

This is the initial commit that adds the simplest possible model, that
only models calls to `ok()` and checks for unsafe accesses. I will add
more fidelity to the model in follow up changes.

The test setup is notable in that it has an extra indirection. This is
because we have an internal model that extends the model we intend to
upstream, in order to model special constructs only found in our code
base. The parametrized test allows us (and anyone who chooses to do
this) to make sure our extensions do not break the base functionality.

RFC:
https://discourse.llvm.org/t/rfc-abseil-unchecked-statusor-use-check/87998
2025-10-17 16:52:44 -07:00