[clang][dataflow] Fix a bug in handling of `operator->` for optional checker.
authorMartin Braenne <mboehme@google.com>
Mon, 22 May 2023 06:17:55 +0000 (06:17 +0000)
committerMartin Braenne <mboehme@google.com>
Mon, 22 May 2023 06:51:15 +0000 (06:51 +0000)
commit3bc1ea5b0ac90e04e7b935a5d964613f8fbad4bf
tree631f0d9ffb0d5da779635dcb368570fefe9e05e8
parent96b22e1c378a93a26cd8fc8051bfc7b90f65b665
[clang][dataflow] Fix a bug in handling of `operator->` for optional checker.

Prior to this patch, `operator->` was being handled like `operator*`: It was
associating a `Value` of type `T` with the expression result (where `T` is the
template argument of the `optional<T>`). This is correct for `operator*`, which
returns a reference (of some flavor) to `T`, so that the result of the
`CXXOperatorCallExpr` is a glvalue of type `T`. However, `operator*` returns a
`T*`, so the result of the `CXXOperatorCallExpr` is a prvalue `T*`, which should
therefore be associated with `PointerValue` that in turn refers to a `T`.

I noticed this issue while working on the migration to strict handling of
value categories (see https://discourse.llvm.org/t/70086). The current behavior
also seems problematic more generally because it's plausible that the framework
may at some point introduce behavior that assumes an `Expr` of pointer type is
always associated with a `PointerValue`.

As it turns out, this patch fixes an existing FIXME in the test
`OptionalValueInitialization`.

Depends On D150657

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D150775
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp