[clang] 97d69cd - [clang][dataflow] Rename `getPointeeLoc` to `getReferentLoc` for ReferenceValue.
Dmitri Gribenko via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 14 15:53:37 PDT 2022
Author: Wei Yi Tee
Date: 2022-06-15T00:53:30+02:00
New Revision: 97d69cdaf324ec520b3f7685ef05f8e207a7bd3b
URL: https://github.com/llvm/llvm-project/commit/97d69cdaf324ec520b3f7685ef05f8e207a7bd3b
DIFF: https://github.com/llvm/llvm-project/commit/97d69cdaf324ec520b3f7685ef05f8e207a7bd3b.diff
LOG: [clang][dataflow] Rename `getPointeeLoc` to `getReferentLoc` for ReferenceValue.
We distinguish between the referent location for `ReferenceValue` and pointee location for `PointerValue`. The former must be non-empty but the latter may be empty in the case of a `nullptr`
Reviewed By: gribozavr2, sgatev
Differential Revision: https://reviews.llvm.org/D127745
Added:
Modified:
clang/include/clang/Analysis/FlowSensitive/Value.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Analysis/FlowSensitive/Value.h b/clang/include/clang/Analysis/FlowSensitive/Value.h
index 3ac4b8c60996b..9c93456346b23 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Value.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Value.h
@@ -170,17 +170,17 @@ class IntegerValue : public Value {
/// in C.
class ReferenceValue final : public Value {
public:
- explicit ReferenceValue(StorageLocation &PointeeLoc)
- : Value(Kind::Reference), PointeeLoc(PointeeLoc) {}
+ explicit ReferenceValue(StorageLocation &ReferentLoc)
+ : Value(Kind::Reference), ReferentLoc(ReferentLoc) {}
static bool classof(const Value *Val) {
return Val->getKind() == Kind::Reference;
}
- StorageLocation &getPointeeLoc() const { return PointeeLoc; }
+ StorageLocation &getReferentLoc() const { return ReferentLoc; }
private:
- StorageLocation &PointeeLoc;
+ StorageLocation &ReferentLoc;
};
/// Models a symbolic pointer. Specifically, any value of type `T*`.
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 033ef6afbeb2f..370b420b80755 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -53,7 +53,7 @@ llvm::DenseMap<K, V> intersectDenseMaps(const llvm::DenseMap<K, V> &Map1,
static bool areEquivalentIndirectionValues(Value *Val1, Value *Val2) {
if (auto *IndVal1 = dyn_cast<ReferenceValue>(Val1)) {
auto *IndVal2 = cast<ReferenceValue>(Val2);
- return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc();
+ return &IndVal1->getReferentLoc() == &IndVal2->getReferentLoc();
}
if (auto *IndVal1 = dyn_cast<PointerValue>(Val1)) {
auto *IndVal2 = cast<PointerValue>(Val2);
@@ -522,7 +522,7 @@ StorageLocation &Environment::skip(StorageLocation &Loc, SkipPast SP) const {
// References cannot be chained so we only need to skip past one level of
// indirection.
if (auto *Val = dyn_cast_or_null<ReferenceValue>(getValue(Loc)))
- return Val->getPointeeLoc();
+ return Val->getReferentLoc();
return Loc;
case SkipPast::ReferenceThenPointer:
StorageLocation &LocPastRef = skip(Loc, SkipPast::Reference);
diff --git a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index f837fe31c6cd8..23a9d964b5b15 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -236,7 +236,7 @@ StorageLocation *maybeInitializeOptionalValueMember(QualType Q,
// `Value` representing the optional (here, `OptionalVal`).
if (auto *ValueProp = OptionalVal.getProperty("value")) {
auto *ValueRef = clang::cast<ReferenceValue>(ValueProp);
- auto &ValueLoc = ValueRef->getPointeeLoc();
+ auto &ValueLoc = ValueRef->getReferentLoc();
if (Env.getValue(ValueLoc) == nullptr) {
// The property was previously set, but the value has been lost. This can
// happen, for example, because of an environment merge (where the two
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 5780968d81591..e3c97367b17ca 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -293,29 +293,29 @@ TEST_F(TransferTest, ReferenceVarDecl) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ runDataflow(
+ Code, [](llvm::ArrayRef<
+ std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
+ Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+ const Environment &Env = Results[0].second.Env;
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
- const StorageLocation *FooLoc =
- Env.getStorageLocation(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
+ const StorageLocation *FooLoc =
+ Env.getStorageLocation(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
- const ReferenceValue *FooVal =
- cast<ReferenceValue>(Env.getValue(*FooLoc));
- const StorageLocation &FooPointeeLoc = FooVal->getPointeeLoc();
- EXPECT_TRUE(isa<AggregateStorageLocation>(&FooPointeeLoc));
+ const ReferenceValue *FooVal =
+ cast<ReferenceValue>(Env.getValue(*FooLoc));
+ const StorageLocation &FooReferentLoc = FooVal->getReferentLoc();
+ EXPECT_TRUE(isa<AggregateStorageLocation>(&FooReferentLoc));
- const Value *FooPointeeVal = Env.getValue(FooPointeeLoc);
- EXPECT_TRUE(isa_and_nonnull<StructValue>(FooPointeeVal));
- });
+ const Value *FooReferentVal = Env.getValue(FooReferentLoc);
+ EXPECT_TRUE(isa_and_nonnull<StructValue>(FooReferentVal));
+ });
}
TEST_F(TransferTest, SelfReferentialReferenceVarDecl) {
@@ -397,31 +397,31 @@ TEST_F(TransferTest, SelfReferentialReferenceVarDecl) {
const auto *FooLoc = cast<ScalarStorageLocation>(
Env.getStorageLocation(*FooDecl, SkipPast::None));
const auto *FooVal = cast<ReferenceValue>(Env.getValue(*FooLoc));
- const auto *FooPointeeVal =
- cast<StructValue>(Env.getValue(FooVal->getPointeeLoc()));
+ const auto *FooReferentVal =
+ cast<StructValue>(Env.getValue(FooVal->getReferentLoc()));
const auto *BarVal =
- cast<ReferenceValue>(FooPointeeVal->getChild(*BarDecl));
- const auto *BarPointeeVal =
- cast<StructValue>(Env.getValue(BarVal->getPointeeLoc()));
+ cast<ReferenceValue>(FooReferentVal->getChild(*BarDecl));
+ const auto *BarReferentVal =
+ cast<StructValue>(Env.getValue(BarVal->getReferentLoc()));
const auto *FooRefVal =
- cast<ReferenceValue>(BarPointeeVal->getChild(*FooRefDecl));
- const StorageLocation &FooRefPointeeLoc = FooRefVal->getPointeeLoc();
- EXPECT_THAT(Env.getValue(FooRefPointeeLoc), IsNull());
+ cast<ReferenceValue>(BarReferentVal->getChild(*FooRefDecl));
+ const StorageLocation &FooReferentLoc = FooRefVal->getReferentLoc();
+ EXPECT_THAT(Env.getValue(FooReferentLoc), IsNull());
const auto *FooPtrVal =
- cast<PointerValue>(BarPointeeVal->getChild(*FooPtrDecl));
+ cast<PointerValue>(BarReferentVal->getChild(*FooPtrDecl));
const StorageLocation &FooPtrPointeeLoc = FooPtrVal->getPointeeLoc();
EXPECT_THAT(Env.getValue(FooPtrPointeeLoc), IsNull());
const auto *BazRefVal =
- cast<ReferenceValue>(BarPointeeVal->getChild(*BazRefDecl));
- const StorageLocation &BazRefPointeeLoc = BazRefVal->getPointeeLoc();
- EXPECT_THAT(Env.getValue(BazRefPointeeLoc), NotNull());
+ cast<ReferenceValue>(BarReferentVal->getChild(*BazRefDecl));
+ const StorageLocation &BazReferentLoc = BazRefVal->getReferentLoc();
+ EXPECT_THAT(Env.getValue(BazReferentLoc), NotNull());
const auto *BazPtrVal =
- cast<PointerValue>(BarPointeeVal->getChild(*BazPtrDecl));
+ cast<PointerValue>(BarReferentVal->getChild(*BazPtrDecl));
const StorageLocation &BazPtrPointeeLoc = BazPtrVal->getPointeeLoc();
EXPECT_THAT(Env.getValue(BazPtrPointeeLoc), NotNull());
});
@@ -564,8 +564,8 @@ TEST_F(TransferTest, SelfReferentialPointerVarDecl) {
const auto *FooRefVal =
cast<ReferenceValue>(BarPointeeVal->getChild(*FooRefDecl));
- const StorageLocation &FooRefPointeeLoc = FooRefVal->getPointeeLoc();
- EXPECT_THAT(Env.getValue(FooRefPointeeLoc), IsNull());
+ const StorageLocation &FooReferentLoc = FooRefVal->getReferentLoc();
+ EXPECT_THAT(Env.getValue(FooReferentLoc), IsNull());
const auto *FooPtrVal =
cast<PointerValue>(BarPointeeVal->getChild(*FooPtrDecl));
@@ -574,8 +574,8 @@ TEST_F(TransferTest, SelfReferentialPointerVarDecl) {
const auto *BazRefVal =
cast<ReferenceValue>(BarPointeeVal->getChild(*BazRefDecl));
- const StorageLocation &BazRefPointeeLoc = BazRefVal->getPointeeLoc();
- EXPECT_THAT(Env.getValue(BazRefPointeeLoc), NotNull());
+ const StorageLocation &BazReferentLoc = BazRefVal->getReferentLoc();
+ EXPECT_THAT(Env.getValue(BazReferentLoc), NotNull());
const auto *BazPtrVal =
cast<PointerValue>(BarPointeeVal->getChild(*BazPtrDecl));
@@ -952,31 +952,31 @@ TEST_F(TransferTest, ReferenceParamDecl) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ runDataflow(
+ Code, [](llvm::ArrayRef<
+ std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
+ Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+ const Environment &Env = Results[0].second.Env;
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
- const StorageLocation *FooLoc =
- Env.getStorageLocation(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
+ const StorageLocation *FooLoc =
+ Env.getStorageLocation(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
- const ReferenceValue *FooVal =
- dyn_cast<ReferenceValue>(Env.getValue(*FooLoc));
- ASSERT_THAT(FooVal, NotNull());
+ const ReferenceValue *FooVal =
+ dyn_cast<ReferenceValue>(Env.getValue(*FooLoc));
+ ASSERT_THAT(FooVal, NotNull());
- const StorageLocation &FooPointeeLoc = FooVal->getPointeeLoc();
- EXPECT_TRUE(isa<AggregateStorageLocation>(&FooPointeeLoc));
+ const StorageLocation &FooReferentLoc = FooVal->getReferentLoc();
+ EXPECT_TRUE(isa<AggregateStorageLocation>(&FooReferentLoc));
- const Value *FooPointeeVal = Env.getValue(FooPointeeLoc);
- EXPECT_TRUE(isa_and_nonnull<StructValue>(FooPointeeVal));
- });
+ const Value *FooReferentVal = Env.getValue(FooReferentLoc);
+ EXPECT_TRUE(isa_and_nonnull<StructValue>(FooReferentVal));
+ });
}
TEST_F(TransferTest, PointerParamDecl) {
@@ -1378,13 +1378,13 @@ TEST_F(TransferTest, ReferenceMember) {
Env.getStorageLocation(*FooDecl, SkipPast::None));
const auto *FooVal = cast<StructValue>(Env.getValue(*FooLoc));
const auto *BarVal = cast<ReferenceValue>(FooVal->getChild(*BarDecl));
- const auto *BarPointeeVal =
- cast<IntegerValue>(Env.getValue(BarVal->getPointeeLoc()));
+ const auto *BarReferentVal =
+ cast<IntegerValue>(Env.getValue(BarVal->getReferentLoc()));
const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
ASSERT_THAT(BazDecl, NotNull());
- EXPECT_EQ(Env.getValue(*BazDecl, SkipPast::None), BarPointeeVal);
+ EXPECT_EQ(Env.getValue(*BazDecl, SkipPast::None), BarReferentVal);
});
}
@@ -1752,7 +1752,7 @@ TEST_F(TransferTest, DefaultInitializerReference) {
const auto *QuxVal =
cast<ReferenceValue>(Env.getValue(*QuxDecl, SkipPast::None));
- EXPECT_EQ(&QuxVal->getPointeeLoc(), &FooVal->getPointeeLoc());
+ EXPECT_EQ(&QuxVal->getReferentLoc(), &FooVal->getReferentLoc());
});
}
@@ -2299,7 +2299,7 @@ TEST_F(TransferTest, DerefDependentPtr) {
cast<PointerValue>(Env.getValue(*FooDecl, SkipPast::None));
const auto *BarVal =
cast<ReferenceValue>(Env.getValue(*BarDecl, SkipPast::None));
- EXPECT_EQ(&BarVal->getPointeeLoc(), &FooVal->getPointeeLoc());
+ EXPECT_EQ(&BarVal->getReferentLoc(), &FooVal->getPointeeLoc());
});
}
More information about the cfe-commits
mailing list