diff options
author | Martin Braenne <mboehme@google.com> | 2023-08-01 13:23:37 +0000 |
---|---|---|
committer | Martin Braenne <mboehme@google.com> | 2023-08-01 20:29:40 +0000 |
commit | 9ecdbe3855a8048989a507ff8d470aee4d407589 (patch) | |
tree | c100e2306d4fabc9be9ec920ff3e0c3378d02cf9 /clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp | |
parent | f39c399d9d15efe8309d8aa3d0ecf62205e6c474 (diff) | |
download | llvm-9ecdbe3855a8048989a507ff8d470aee4d407589.zip llvm-9ecdbe3855a8048989a507ff8d470aee4d407589.tar.gz llvm-9ecdbe3855a8048989a507ff8d470aee4d407589.tar.bz2 |
[clang][dataflow] Rename `AggregateStorageLocation` to `RecordStorageLocation` and `StructValue` to `RecordValue`.
- Both of these constructs are used to represent structs, classes, and unions;
Clang uses the collective term "record" for these.
- The term "aggregate" in `AggregateStorageLocation` implies that, at some
point, the intention may have been to use it also for arrays, but it don't
think it's possible to use it for arrays. Records and arrays are very
different and therefore need to be modeled differently. Records have a fixed
set of named fields, which can have different type; arrays have a variable
number of elements, but they all have the same type.
- Futhermore, "aggregate" has a very specific meaning in C++
(https://en.cppreference.com/w/cpp/language/aggregate_initialization).
Aggregates of class type may not have any user-declared or inherited
constructors, no private or protected non-static data members, no virtual
member functions, and so on, but we use `AggregateStorageLocations` to model all objects of class type.
In addition, for consistency, we also rename the following:
- `getAggregateLoc()` (in `RecordValue`, formerly known as `StructValue`) to
simply `getLoc()`.
- `refreshStructValue()` to `refreshRecordValue()`
We keep the old names around as deprecated synonyms to enable clients to be migrated to the new names.
Reviewed By: ymandel, xazax.hun
Differential Revision: https://reviews.llvm.org/D156788
Diffstat (limited to 'clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp')
-rw-r--r-- | clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp index 1d6dfa9..961a06d 100644 --- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp +++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp @@ -256,9 +256,9 @@ void setHasValue(Value &OptionalVal, BoolValue &HasValueVal) { /// Creates a symbolic value for an `optional` value at an existing storage /// location. Uses `HasValueVal` as the symbolic value of the "has_value" /// property. -StructValue &createOptionalValue(AggregateStorageLocation &Loc, +RecordValue &createOptionalValue(RecordStorageLocation &Loc, BoolValue &HasValueVal, Environment &Env) { - auto &OptionalVal = Env.create<StructValue>(Loc); + auto &OptionalVal = Env.create<RecordValue>(Loc); Env.setValue(Loc, OptionalVal); setHasValue(OptionalVal, HasValueVal); return OptionalVal; @@ -335,7 +335,7 @@ StorageLocation *maybeInitializeOptionalValueMember(QualType Q, // the check, like another optional or a boolean that influences control // flow. if (ValueLoc.getType()->isRecordType()) { - refreshStructValue(cast<AggregateStorageLocation>(ValueLoc), Env); + refreshRecordValue(cast<RecordStorageLocation>(ValueLoc), Env); return &ValueLoc; } else { auto *ValueVal = Env.createValue(ValueLoc.getType()); @@ -356,7 +356,7 @@ StorageLocation *maybeInitializeOptionalValueMember(QualType Q, // example: // // void target(optional<int> oo, bool b) { - // // `oo` is associated with a `StructValue` here, which we will call + // // `oo` is associated with a `RecordValue` here, which we will call // // `OptionalVal`. // // // The `has_value` property is set on `OptionalVal` (but not the @@ -532,15 +532,13 @@ void transferCallReturningOptional(const CallExpr *E, if (State.Env.getValue(*E) != nullptr) return; - AggregateStorageLocation *Loc = nullptr; + RecordStorageLocation *Loc = nullptr; if (E->isPRValue()) { Loc = &State.Env.getResultObjectLocation(*E); } else { - Loc = cast_or_null<AggregateStorageLocation>( - State.Env.getStorageLocation(*E)); + Loc = cast_or_null<RecordStorageLocation>(State.Env.getStorageLocation(*E)); if (Loc == nullptr) { - Loc = - &cast<AggregateStorageLocation>(State.Env.createStorageLocation(*E)); + Loc = &cast<RecordStorageLocation>(State.Env.createStorageLocation(*E)); State.Env.setStorageLocation(*E, *Loc); } } @@ -550,7 +548,7 @@ void transferCallReturningOptional(const CallExpr *E, void constructOptionalValue(const Expr &E, Environment &Env, BoolValue &HasValueVal) { - AggregateStorageLocation &Loc = Env.getResultObjectLocation(E); + RecordStorageLocation &Loc = Env.getResultObjectLocation(E); Env.setValue(E, createOptionalValue(Loc, HasValueVal, Env)); } @@ -598,7 +596,7 @@ void transferAssignment(const CXXOperatorCallExpr *E, BoolValue &HasValueVal, LatticeTransferState &State) { assert(E->getNumArgs() > 0); - if (auto *Loc = cast<AggregateStorageLocation>( + if (auto *Loc = cast<RecordStorageLocation>( State.Env.getStorageLocation(*E->getArg(0)))) { createOptionalValue(*Loc, HasValueVal, State.Env); @@ -623,8 +621,8 @@ void transferNulloptAssignment(const CXXOperatorCallExpr *E, transferAssignment(E, State.Env.getBoolLiteralValue(false), State); } -void transferSwap(AggregateStorageLocation *Loc1, - AggregateStorageLocation *Loc2, Environment &Env) { +void transferSwap(RecordStorageLocation *Loc1, RecordStorageLocation *Loc2, + Environment &Env) { // We account for cases where one or both of the optionals are not modeled, // either lacking associated storage locations, or lacking values associated // to such storage locations. @@ -661,7 +659,7 @@ void transferSwapCall(const CXXMemberCallExpr *E, const MatchFinder::MatchResult &, LatticeTransferState &State) { assert(E->getNumArgs() == 1); - auto *OtherLoc = cast_or_null<AggregateStorageLocation>( + auto *OtherLoc = cast_or_null<RecordStorageLocation>( State.Env.getStorageLocation(*E->getArg(0))); transferSwap(getImplicitObjectLocation(*E, State.Env), OtherLoc, State.Env); } @@ -669,9 +667,9 @@ void transferSwapCall(const CXXMemberCallExpr *E, void transferStdSwapCall(const CallExpr *E, const MatchFinder::MatchResult &, LatticeTransferState &State) { assert(E->getNumArgs() == 2); - auto *Arg0Loc = cast_or_null<AggregateStorageLocation>( + auto *Arg0Loc = cast_or_null<RecordStorageLocation>( State.Env.getStorageLocation(*E->getArg(0))); - auto *Arg1Loc = cast_or_null<AggregateStorageLocation>( + auto *Arg1Loc = cast_or_null<RecordStorageLocation>( State.Env.getStorageLocation(*E->getArg(1))); transferSwap(Arg0Loc, Arg1Loc, State.Env); } @@ -848,7 +846,7 @@ auto buildTransferMatchSwitch() { isOptionalMemberCallWithNameMatcher(hasName("emplace")), [](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &, LatticeTransferState &State) { - if (AggregateStorageLocation *Loc = + if (RecordStorageLocation *Loc = getImplicitObjectLocation(*E, State.Env)) { createOptionalValue(*Loc, State.Env.getBoolLiteralValue(true), State.Env); @@ -860,7 +858,7 @@ auto buildTransferMatchSwitch() { isOptionalMemberCallWithNameMatcher(hasName("reset")), [](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &, LatticeTransferState &State) { - if (AggregateStorageLocation *Loc = + if (RecordStorageLocation *Loc = getImplicitObjectLocation(*E, State.Env)) { createOptionalValue(*Loc, State.Env.getBoolLiteralValue(false), State.Env); @@ -1032,7 +1030,7 @@ Value *UncheckedOptionalAccessModel::widen(QualType Type, Value &Prev, if (isa<TopBoolValue>(CurrentHasVal)) return &Current; } - return &createOptionalValue(cast<StructValue>(Current).getAggregateLoc(), + return &createOptionalValue(cast<RecordValue>(Current).getLoc(), CurrentEnv.makeTopBoolValue(), CurrentEnv); case ComparisonResult::Unknown: return nullptr; |