diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -330,7 +330,7 @@ /// Returns the storage location assigned to the `this` pointee in the /// environment or null if the `this` pointee has no assigned storage location /// in the environment. - StorageLocation *getThisPointeeStorageLocation() const; + AggregateStorageLocation *getThisPointeeStorageLocation() const; /// Returns the return value of the current function. This can be null if: /// - The function has a void return type @@ -600,7 +600,7 @@ StorageLocation *ReturnLoc = nullptr; // The storage location of the `this` pointee. Should only be null if the // function being analyzed is only a function and not a method. - StorageLocation *ThisPointeeLoc = nullptr; + AggregateStorageLocation *ThisPointeeLoc = nullptr; // Maps from program declarations and statements to storage locations that are // assigned to them. Unlike the maps in `DataflowAnalysisContext`, these 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 @@ -309,7 +309,8 @@ // FIXME: Initialize the ThisPointeeLoc of lambdas too. if (MethodDecl && !MethodDecl->isStatic()) { QualType ThisPointeeType = MethodDecl->getThisObjectType(); - ThisPointeeLoc = &createStorageLocation(ThisPointeeType); + ThisPointeeLoc = &cast( + createStorageLocation(ThisPointeeType)); if (Value *ThisPointeeVal = createValue(ThisPointeeType)) setValue(*ThisPointeeLoc, *ThisPointeeVal); } @@ -327,7 +328,8 @@ if (const auto *MethodCall = dyn_cast(Call)) { if (const Expr *Arg = MethodCall->getImplicitObjectArgument()) { if (!isa(Arg)) - Env.ThisPointeeLoc = getStorageLocation(*Arg, SkipPast::Reference); + Env.ThisPointeeLoc = cast( + getStorageLocation(*Arg, SkipPast::Reference)); // Otherwise (when the argument is `this`), retain the current // environment's `ThisPointeeLoc`. } @@ -342,7 +344,8 @@ Environment Environment::pushCall(const CXXConstructExpr *Call) const { Environment Env(*this); - Env.ThisPointeeLoc = &Env.createStorageLocation(Call->getType()); + Env.ThisPointeeLoc = &cast( + Env.createStorageLocation(Call->getType())); if (Value *Val = Env.createValue(Call->getType())) Env.setValue(*Env.ThisPointeeLoc, *Val); @@ -685,7 +688,7 @@ return Loc; } -StorageLocation *Environment::getThisPointeeStorageLocation() const { +AggregateStorageLocation *Environment::getThisPointeeStorageLocation() const { return ThisPointeeLoc; } diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp --- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp +++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp @@ -366,8 +366,7 @@ assert(Init != nullptr); auto &Env = InputState.Env; - auto &ThisLoc = - *cast(Env.getThisPointeeStorageLocation()); + auto &ThisLoc = *Env.getThisPointeeStorageLocation(); if (!Init->isAnyMemberInitializer()) // FIXME: Handle base initialization 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 @@ -1517,8 +1517,7 @@ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = dyn_cast( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); @@ -1593,8 +1592,7 @@ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = - cast(Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); ASSERT_THAT(BarDecl, NotNull()); @@ -1664,8 +1662,7 @@ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = dyn_cast( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo"); @@ -1710,8 +1707,7 @@ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p1"); - const auto *ThisLoc = dyn_cast( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); @@ -1749,8 +1745,7 @@ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p2")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p2"); - const auto *ThisLoc = dyn_cast( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); @@ -1808,8 +1803,7 @@ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = dyn_cast( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo"); @@ -1842,8 +1836,7 @@ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = dyn_cast( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo"); @@ -1876,8 +1869,7 @@ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = dyn_cast( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");