[PATCH] D121197: [clang][dataflow] Add analysis that detects unsafe accesses to optionals

Stanislav Gatev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 9 01:05:37 PST 2022


sgatev added inline comments.


================
Comment at: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:115
+      // optional::has_value
+      .CaseOf(isOptionalMemberCallWithName("has_value"),
+              transferOptionalHasValueCall)
----------------
xazax.hun wrote:
> One very important omission seems to be `optional::operator bool`. This is a widely used method and I'd love to see it supported.
> 
> Also would love to see FIXMEs for some of the most more frequently used functions/methods:
> * make_optional makes a non-empty optional
> * swap (free function and method)
> * value_or returning its argument when the optional is known to be empty
> * Model the value semantics:  Copy ctor, assignment operator
> * Model the move semantics
> * Default constructed optional is empty
> * Invalidation: passing optional by non-const reference/pointer can invalidate its state
> 
> 
Most of these will be implemented in follow up patches soon and you can already find the list in the FIXME in UncheckedOptionalAccessModelTest.cpp. I added to it invalidation so that it covers all features you mentioned here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121197/new/

https://reviews.llvm.org/D121197



More information about the cfe-commits mailing list