diff options
author | Martin Braenne <mboehme@google.com> | 2023-08-28 11:50:03 +0000 |
---|---|---|
committer | Martin Braenne <mboehme@google.com> | 2023-08-29 07:28:46 +0000 |
commit | 330d5bcbf61043b5ca2bf5a65bd4488718c85e6e (patch) | |
tree | 801d124652865eb801c87e4c14bfae34360df75a /clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp | |
parent | fe0e804a4ef4fdf0ae7b2654ad4ac8d1cfafec60 (diff) | |
download | llvm-330d5bcbf61043b5ca2bf5a65bd4488718c85e6e.zip llvm-330d5bcbf61043b5ca2bf5a65bd4488718c85e6e.tar.gz llvm-330d5bcbf61043b5ca2bf5a65bd4488718c85e6e.tar.bz2 |
[clang][dataflow] Don't associate prvalue expressions with storage locations.
Instead, map prvalue expressions directly to values in a newly introduced map `Environment::ExprToVal`.
This change introduces an additional member variable in `Environment` but is an overall win:
- It is more conceptually correctly, since prvalues don't have storage
locations.
- It eliminates complexity from
`Environment::setValue(const Expr &E, Value &Val)`.
- It reduces the amount of data stored in `Environment`: A prvalue now has a
single entry in `ExprToVal` instead of one in `ExprToLoc` and one in
`LocToVal`.
- Not allocating `StorageLocation`s for prvalues additionally reduces memory
usage.
This patch is the last step in the migration to strict handling of value categories (see https://discourse.llvm.org/t/70086 for details). The changes here are almost entirely internal to `Environment`.
The only externally observable change is that when associating a `RecordValue` with the location returned by `Environment::getResultObjectLocation()` for a given expression, callers additionally need to associate the `RecordValue` with the expression themselves.
Reviewed By: xazax.hun
Differential Revision: https://reviews.llvm.org/D158977
Diffstat (limited to 'clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp')
-rw-r--r-- | clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp index 961a06d..e40bd3d 100644 --- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp +++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp @@ -458,8 +458,9 @@ void transferArrowOpCall(const Expr *UnwrapExpr, const Expr *ObjectExpr, void transferMakeOptionalCall(const CallExpr *E, const MatchFinder::MatchResult &, LatticeTransferState &State) { - createOptionalValue(State.Env.getResultObjectLocation(*E), - State.Env.getBoolLiteralValue(true), State.Env); + State.Env.setValue( + *E, createOptionalValue(State.Env.getResultObjectLocation(*E), + State.Env.getBoolLiteralValue(true), State.Env)); } void transferOptionalHasValueCall(const CXXMemberCallExpr *CallExpr, @@ -543,7 +544,10 @@ void transferCallReturningOptional(const CallExpr *E, } } - createOptionalValue(*Loc, State.Env.makeAtomicBoolValue(), State.Env); + RecordValue &Val = + createOptionalValue(*Loc, State.Env.makeAtomicBoolValue(), State.Env); + if (E->isPRValue()) + State.Env.setValue(*E, Val); } void constructOptionalValue(const Expr &E, Environment &Env, |