Author: Martin Braenne Date: 2023-06-29T04:07:08Z New Revision: 74d8455ba6a19d9eeaa561fd0eccc8cbf5351a47
URL: https://github.com/llvm/llvm-project/commit/74d8455ba6a19d9eeaa561fd0eccc8cbf5351a47 DIFF: https://github.com/llvm/llvm-project/commit/74d8455ba6a19d9eeaa561fd0eccc8cbf5351a47.diff LOG: [clang][dataflow] Make `getThisPointeeStorageLocation()` return an `AggregateStorageLocation`. This avoids the need for casts at callsites. Depends On D153852 Reviewed By: sammccall, xazax.hun, gribozavr2 Differential Revision: https://reviews.llvm.org/D153854 Added: Modified: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp clang/unittests/Analysis/FlowSensitive/TransferTest.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h index 8da359880e3ce3..faeb5eb69cd838 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h @@ -330,7 +330,7 @@ class Environment { /// 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 @@ class Environment { 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 index f4867c4becea03..689f8abb51c8e0 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -309,7 +309,8 @@ Environment::Environment(DataflowAnalysisContext &DACtx, // FIXME: Initialize the ThisPointeeLoc of lambdas too. if (MethodDecl && !MethodDecl->isStatic()) { QualType ThisPointeeType = MethodDecl->getThisObjectType(); - ThisPointeeLoc = &createStorageLocation(ThisPointeeType); + ThisPointeeLoc = &cast<AggregateStorageLocation>( + createStorageLocation(ThisPointeeType)); if (Value *ThisPointeeVal = createValue(ThisPointeeType)) setValue(*ThisPointeeLoc, *ThisPointeeVal); } @@ -327,7 +328,8 @@ Environment Environment::pushCall(const CallExpr *Call) const { if (const auto *MethodCall = dyn_cast<CXXMemberCallExpr>(Call)) { if (const Expr *Arg = MethodCall->getImplicitObjectArgument()) { if (!isa<CXXThisExpr>(Arg)) - Env.ThisPointeeLoc = getStorageLocation(*Arg, SkipPast::Reference); + Env.ThisPointeeLoc = cast<AggregateStorageLocation>( + getStorageLocation(*Arg, SkipPast::Reference)); // Otherwise (when the argument is `this`), retain the current // environment's `ThisPointeeLoc`. } @@ -342,7 +344,8 @@ Environment Environment::pushCall(const CallExpr *Call) const { Environment Environment::pushCall(const CXXConstructExpr *Call) const { Environment Env(*this); - Env.ThisPointeeLoc = &Env.createStorageLocation(Call->getType()); + Env.ThisPointeeLoc = &cast<AggregateStorageLocation>( + Env.createStorageLocation(Call->getType())); if (Value *Val = Env.createValue(Call->getType())) Env.setValue(*Env.ThisPointeeLoc, *Val); @@ -685,7 +688,7 @@ StorageLocation *Environment::getStorageLocationStrict(const Expr &E) const { 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 index 99f18a07ed65c4..d2908725d79b3d 100644 --- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp +++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp @@ -366,8 +366,7 @@ builtinTransferInitializer(const CFGInitializer &Elt, assert(Init != nullptr); auto &Env = InputState.Env; - auto &ThisLoc = - *cast<AggregateStorageLocation>(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 index 356a87a93e13b5..5d2a82b581f3b1 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -1517,8 +1517,7 @@ TEST(TransferTest, StructThisMember) { ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = dyn_cast<AggregateStorageLocation>( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); @@ -1593,8 +1592,7 @@ TEST(TransferTest, ClassThisMember) { ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = - cast<AggregateStorageLocation>(Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); ASSERT_THAT(BarDecl, NotNull()); @@ -1664,8 +1662,7 @@ TEST(TransferTest, UnionThisMember) { ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = dyn_cast<AggregateStorageLocation>( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo"); @@ -1710,8 +1707,7 @@ TEST(TransferTest, StructThisInLambda) { ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p1"); - const auto *ThisLoc = dyn_cast<AggregateStorageLocation>( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); @@ -1749,8 +1745,7 @@ TEST(TransferTest, StructThisInLambda) { ASSERT_THAT(Results.keys(), UnorderedElementsAre("p2")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p2"); - const auto *ThisLoc = dyn_cast<AggregateStorageLocation>( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); @@ -1808,8 +1803,7 @@ TEST(TransferTest, ConstructorInitializer) { ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = dyn_cast<AggregateStorageLocation>( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo"); @@ -1842,8 +1836,7 @@ TEST(TransferTest, DefaultInitializer) { ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = dyn_cast<AggregateStorageLocation>( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo"); @@ -1876,8 +1869,7 @@ TEST(TransferTest, DefaultInitializerReference) { ASSERT_THAT(Results.keys(), UnorderedElementsAre("p")); const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); - const auto *ThisLoc = dyn_cast<AggregateStorageLocation>( - Env.getThisPointeeStorageLocation()); + const auto *ThisLoc = Env.getThisPointeeStorageLocation(); ASSERT_THAT(ThisLoc, NotNull()); const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits