diff --git a/clang/include/clang/Analysis/FlowSensitive/Value.h b/clang/include/clang/Analysis/FlowSensitive/Value.h --- a/clang/include/clang/Analysis/FlowSensitive/Value.h +++ b/clang/include/clang/Analysis/FlowSensitive/Value.h @@ -177,7 +177,7 @@ return Val->getKind() == Kind::Reference; } - StorageLocation &getPointeeLoc() const { return PointeeLoc; } + StorageLocation &getReferencePointeeLoc() const { return PointeeLoc; } private: StorageLocation &PointeeLoc; @@ -193,7 +193,7 @@ return Val->getKind() == Kind::Pointer; } - StorageLocation &getPointeeLoc() const { return PointeeLoc; } + StorageLocation &getPointerPointeeLoc() const { return PointeeLoc; } private: StorageLocation &PointeeLoc; diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -53,11 +53,12 @@ static bool areEquivalentIndirectionValues(Value *Val1, Value *Val2) { if (auto *IndVal1 = dyn_cast(Val1)) { auto *IndVal2 = cast(Val2); - return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc(); + return &IndVal1->getReferencePointeeLoc() == + &IndVal2->getReferencePointeeLoc(); } if (auto *IndVal1 = dyn_cast(Val1)) { auto *IndVal2 = cast(Val2); - return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc(); + return &IndVal1->getPointerPointeeLoc() == &IndVal2->getPointerPointeeLoc(); } return false; } @@ -522,12 +523,12 @@ // References cannot be chained so we only need to skip past one level of // indirection. if (auto *Val = dyn_cast_or_null(getValue(Loc))) - return Val->getPointeeLoc(); + return Val->getReferencePointeeLoc(); return Loc; case SkipPast::ReferenceThenPointer: StorageLocation &LocPastRef = skip(Loc, SkipPast::Reference); if (auto *Val = dyn_cast_or_null(getValue(LocPastRef))) - return Val->getPointeeLoc(); + return Val->getPointerPointeeLoc(); return LocPastRef; } llvm_unreachable("bad SkipPast kind"); diff --git a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp --- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp +++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp @@ -236,7 +236,7 @@ // `Value` representing the optional (here, `OptionalVal`). if (auto *ValueProp = OptionalVal.getProperty("value")) { auto *ValueRef = clang::cast(ValueProp); - auto &ValueLoc = ValueRef->getPointeeLoc(); + auto &ValueLoc = ValueRef->getReferencePointeeLoc(); 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/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp --- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -266,7 +266,7 @@ auto &Loc = Env.createStorageLocation(*S); Env.setStorageLocation(*S, Loc); Env.setValue(Loc, Env.takeOwnership(std::make_unique( - SubExprVal->getPointeeLoc()))); + SubExprVal->getPointerPointeeLoc()))); break; } case UO_AddrOf: { diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -293,29 +293,29 @@ // [[p]] } )"; - runDataflow(Code, - [](llvm::ArrayRef< - std::pair>> - Results, - ASTContext &ASTCtx) { - ASSERT_THAT(Results, ElementsAre(Pair("p", _))); - const Environment &Env = Results[0].second.Env; + runDataflow( + Code, [](llvm::ArrayRef< + std::pair>> + 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(FooLoc)); + const StorageLocation *FooLoc = + Env.getStorageLocation(*FooDecl, SkipPast::None); + ASSERT_TRUE(isa_and_nonnull(FooLoc)); - const ReferenceValue *FooVal = - cast(Env.getValue(*FooLoc)); - const StorageLocation &FooPointeeLoc = FooVal->getPointeeLoc(); - EXPECT_TRUE(isa(&FooPointeeLoc)); + const ReferenceValue *FooVal = + cast(Env.getValue(*FooLoc)); + const StorageLocation &FooPointeeLoc = FooVal->getReferencePointeeLoc(); + EXPECT_TRUE(isa(&FooPointeeLoc)); - const Value *FooPointeeVal = Env.getValue(FooPointeeLoc); - EXPECT_TRUE(isa_and_nonnull(FooPointeeVal)); - }); + const Value *FooPointeeVal = Env.getValue(FooPointeeLoc); + EXPECT_TRUE(isa_and_nonnull(FooPointeeVal)); + }); } TEST_F(TransferTest, SelfReferentialReferenceVarDecl) { @@ -398,31 +398,33 @@ Env.getStorageLocation(*FooDecl, SkipPast::None)); const auto *FooVal = cast(Env.getValue(*FooLoc)); const auto *FooPointeeVal = - cast(Env.getValue(FooVal->getPointeeLoc())); + cast(Env.getValue(FooVal->getReferencePointeeLoc())); const auto *BarVal = cast(FooPointeeVal->getChild(*BarDecl)); const auto *BarPointeeVal = - cast(Env.getValue(BarVal->getPointeeLoc())); + cast(Env.getValue(BarVal->getReferencePointeeLoc())); const auto *FooRefVal = cast(BarPointeeVal->getChild(*FooRefDecl)); - const StorageLocation &FooRefPointeeLoc = FooRefVal->getPointeeLoc(); + const StorageLocation &FooRefPointeeLoc = + FooRefVal->getReferencePointeeLoc(); EXPECT_THAT(Env.getValue(FooRefPointeeLoc), IsNull()); const auto *FooPtrVal = cast(BarPointeeVal->getChild(*FooPtrDecl)); - const StorageLocation &FooPtrPointeeLoc = FooPtrVal->getPointeeLoc(); + const StorageLocation &FooPtrPointeeLoc = FooPtrVal->getPointerPointeeLoc(); EXPECT_THAT(Env.getValue(FooPtrPointeeLoc), IsNull()); const auto *BazRefVal = cast(BarPointeeVal->getChild(*BazRefDecl)); - const StorageLocation &BazRefPointeeLoc = BazRefVal->getPointeeLoc(); + const StorageLocation &BazRefPointeeLoc = + BazRefVal->getReferencePointeeLoc(); EXPECT_THAT(Env.getValue(BazRefPointeeLoc), NotNull()); const auto *BazPtrVal = cast(BarPointeeVal->getChild(*BazPtrDecl)); - const StorageLocation &BazPtrPointeeLoc = BazPtrVal->getPointeeLoc(); + const StorageLocation &BazPtrPointeeLoc = BazPtrVal->getPointerPointeeLoc(); EXPECT_THAT(Env.getValue(BazPtrPointeeLoc), NotNull()); }); } @@ -454,7 +456,7 @@ ASSERT_TRUE(isa_and_nonnull(FooLoc)); const PointerValue *FooVal = cast(Env.getValue(*FooLoc)); - const StorageLocation &FooPointeeLoc = FooVal->getPointeeLoc(); + const StorageLocation &FooPointeeLoc = FooVal->getPointerPointeeLoc(); EXPECT_TRUE(isa(&FooPointeeLoc)); const Value *FooPointeeVal = Env.getValue(FooPointeeLoc); @@ -555,31 +557,35 @@ Env.getStorageLocation(*FooDecl, SkipPast::None)); const auto *FooVal = cast(Env.getValue(*FooLoc)); const auto *FooPointeeVal = - cast(Env.getValue(FooVal->getPointeeLoc())); + cast(Env.getValue(FooVal->getPointerPointeeLoc())); const auto *BarVal = cast(FooPointeeVal->getChild(*BarDecl)); const auto *BarPointeeVal = - cast(Env.getValue(BarVal->getPointeeLoc())); + cast(Env.getValue(BarVal->getPointerPointeeLoc())); const auto *FooRefVal = cast(BarPointeeVal->getChild(*FooRefDecl)); - const StorageLocation &FooRefPointeeLoc = FooRefVal->getPointeeLoc(); + const StorageLocation &FooRefPointeeLoc = + FooRefVal->getReferencePointeeLoc(); EXPECT_THAT(Env.getValue(FooRefPointeeLoc), IsNull()); const auto *FooPtrVal = cast(BarPointeeVal->getChild(*FooPtrDecl)); - const StorageLocation &FooPtrPointeeLoc = FooPtrVal->getPointeeLoc(); + const StorageLocation &FooPtrPointeeLoc = + FooPtrVal->getPointerPointeeLoc(); EXPECT_THAT(Env.getValue(FooPtrPointeeLoc), IsNull()); const auto *BazRefVal = cast(BarPointeeVal->getChild(*BazRefDecl)); - const StorageLocation &BazRefPointeeLoc = BazRefVal->getPointeeLoc(); + const StorageLocation &BazRefPointeeLoc = + BazRefVal->getReferencePointeeLoc(); EXPECT_THAT(Env.getValue(BazRefPointeeLoc), NotNull()); const auto *BazPtrVal = cast(BarPointeeVal->getChild(*BazPtrDecl)); - const StorageLocation &BazPtrPointeeLoc = BazPtrVal->getPointeeLoc(); + const StorageLocation &BazPtrPointeeLoc = + BazPtrVal->getPointerPointeeLoc(); EXPECT_THAT(Env.getValue(BazPtrPointeeLoc), NotNull()); }); } @@ -799,7 +805,7 @@ const auto *BarVal = cast(Env.getValue(*BarDecl, SkipPast::None)); - EXPECT_EQ(Env.getValue(BarVal->getPointeeLoc()), FooVal); + EXPECT_EQ(Env.getValue(BarVal->getPointerPointeeLoc()), FooVal); const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz"); ASSERT_THAT(BazDecl, NotNull()); @@ -952,31 +958,31 @@ // [[p]] } )"; - runDataflow(Code, - [](llvm::ArrayRef< - std::pair>> - Results, - ASTContext &ASTCtx) { - ASSERT_THAT(Results, ElementsAre(Pair("p", _))); - const Environment &Env = Results[0].second.Env; + runDataflow( + Code, [](llvm::ArrayRef< + std::pair>> + 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(FooLoc)); + const StorageLocation *FooLoc = + Env.getStorageLocation(*FooDecl, SkipPast::None); + ASSERT_TRUE(isa_and_nonnull(FooLoc)); - const ReferenceValue *FooVal = - dyn_cast(Env.getValue(*FooLoc)); - ASSERT_THAT(FooVal, NotNull()); + const ReferenceValue *FooVal = + dyn_cast(Env.getValue(*FooLoc)); + ASSERT_THAT(FooVal, NotNull()); - const StorageLocation &FooPointeeLoc = FooVal->getPointeeLoc(); - EXPECT_TRUE(isa(&FooPointeeLoc)); + const StorageLocation &FooPointeeLoc = FooVal->getReferencePointeeLoc(); + EXPECT_TRUE(isa(&FooPointeeLoc)); - const Value *FooPointeeVal = Env.getValue(FooPointeeLoc); - EXPECT_TRUE(isa_and_nonnull(FooPointeeVal)); - }); + const Value *FooPointeeVal = Env.getValue(FooPointeeLoc); + EXPECT_TRUE(isa_and_nonnull(FooPointeeVal)); + }); } TEST_F(TransferTest, PointerParamDecl) { @@ -1004,7 +1010,7 @@ ASSERT_TRUE(isa_and_nonnull(FooLoc)); const PointerValue *FooVal = cast(Env.getValue(*FooLoc)); - const StorageLocation &FooPointeeLoc = FooVal->getPointeeLoc(); + const StorageLocation &FooPointeeLoc = FooVal->getPointerPointeeLoc(); EXPECT_TRUE(isa(&FooPointeeLoc)); const Value *FooPointeeVal = Env.getValue(FooPointeeLoc); @@ -1379,7 +1385,7 @@ const auto *FooVal = cast(Env.getValue(*FooLoc)); const auto *BarVal = cast(FooVal->getChild(*BarDecl)); const auto *BarPointeeVal = - cast(Env.getValue(BarVal->getPointeeLoc())); + cast(Env.getValue(BarVal->getReferencePointeeLoc())); const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz"); ASSERT_THAT(BazDecl, NotNull()); @@ -1752,7 +1758,8 @@ const auto *QuxVal = cast(Env.getValue(*QuxDecl, SkipPast::None)); - EXPECT_EQ(&QuxVal->getPointeeLoc(), &FooVal->getPointeeLoc()); + EXPECT_EQ(&QuxVal->getReferencePointeeLoc(), + &FooVal->getReferencePointeeLoc()); }); } @@ -2240,7 +2247,7 @@ Env.getStorageLocation(*FooDecl, SkipPast::None)); const auto *BarVal = cast(Env.getValue(*BarDecl, SkipPast::None)); - EXPECT_EQ(&BarVal->getPointeeLoc(), FooLoc); + EXPECT_EQ(&BarVal->getPointerPointeeLoc(), FooLoc); }); } @@ -2269,7 +2276,8 @@ cast(Env.getValue(*FooDecl, SkipPast::None)); const auto *BarVal = cast(Env.getValue(*BarDecl, SkipPast::None)); - EXPECT_EQ(&BarVal->getPointeeLoc(), &FooVal->getPointeeLoc()); + EXPECT_EQ(&BarVal->getPointerPointeeLoc(), + &FooVal->getPointerPointeeLoc()); }); } @@ -2299,7 +2307,8 @@ cast(Env.getValue(*FooDecl, SkipPast::None)); const auto *BarVal = cast(Env.getValue(*BarDecl, SkipPast::None)); - EXPECT_EQ(&BarVal->getPointeeLoc(), &FooVal->getPointeeLoc()); + EXPECT_EQ(&BarVal->getReferencePointeeLoc(), + &FooVal->getPointerPointeeLoc()); }); } @@ -2353,31 +2362,31 @@ /*[[p]]*/ } )"; - runDataflow(Code, - [](llvm::ArrayRef< - std::pair>> - Results, - ASTContext &ASTCtx) { - ASSERT_THAT(Results, ElementsAre(Pair("p", _))); - const Environment &Env = Results[0].second.Env; + runDataflow( + Code, [](llvm::ArrayRef< + std::pair>> + 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 ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); - ASSERT_THAT(BarDecl, NotNull()); + const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); + ASSERT_THAT(BarDecl, NotNull()); - const auto *FooVal = - cast(Env.getValue(*FooDecl, SkipPast::None)); - const auto *FooPointeeVal = - cast(Env.getValue(FooVal->getPointeeLoc())); + const auto *FooVal = + cast(Env.getValue(*FooDecl, SkipPast::None)); + const auto *FooPointeeVal = + cast(Env.getValue(FooVal->getPointerPointeeLoc())); - const auto *BarVal = dyn_cast_or_null( - Env.getValue(*BarDecl, SkipPast::None)); - ASSERT_THAT(BarVal, NotNull()); + const auto *BarVal = dyn_cast_or_null( + Env.getValue(*BarDecl, SkipPast::None)); + ASSERT_THAT(BarVal, NotNull()); - EXPECT_EQ(BarVal, FooPointeeVal); - }); + EXPECT_EQ(BarVal, FooPointeeVal); + }); } TEST_F(TransferTest, AggregateInitialization) { @@ -3331,7 +3340,7 @@ dyn_cast(InnerEnv.getValue(*LDecl, SkipPast::None)); ASSERT_THAT(LVal, NotNull()); - EXPECT_EQ(&LVal->getPointeeLoc(), + EXPECT_EQ(&LVal->getPointerPointeeLoc(), InnerEnv.getStorageLocation(*ValDecl, SkipPast::Reference)); // Outer. @@ -3341,7 +3350,7 @@ // The loop body may not have been executed, so we should not conclude // that `l` points to `val`. - EXPECT_NE(&LVal->getPointeeLoc(), + EXPECT_NE(&LVal->getPointerPointeeLoc(), OuterEnv.getStorageLocation(*ValDecl, SkipPast::Reference)); }); } diff --git a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp --- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp @@ -676,7 +676,7 @@ Env.getStorageLocation(*FooDecl, SkipPast::None)); const auto *BarVal = cast(Env.getValue(*BarDecl, SkipPast::None)); - EXPECT_EQ(&BarVal->getPointeeLoc(), FooLoc); + EXPECT_EQ(&BarVal->getPointerPointeeLoc(), FooLoc); }); }