[clang] 880f306 - [clang][dataflow] Add a test for a struct that is directly self-referential through a reference.

Martin Braenne via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 4 05:06:24 PDT 2023


Author: Martin Braenne
Date: 2023-07-04T12:06:13Z
New Revision: 880f306226fcb97d85d422480954eb8765ff31c7

URL: https://github.com/llvm/llvm-project/commit/880f306226fcb97d85d422480954eb8765ff31c7
DIFF: https://github.com/llvm/llvm-project/commit/880f306226fcb97d85d422480954eb8765ff31c7.diff

LOG: [clang][dataflow] Add a test for a struct that is directly self-referential through a reference.

The ongoing migration to strict handling of value
categories (see https://discourse.llvm.org/t/70086) will change the way we
handle fields of reference type, and I want to put a test in place that makes
sure we continue to handle this special case correctly.

Depends On D154420

Reviewed By: gribozavr2, xazax.hun

Differential Revision: https://reviews.llvm.org/D154421

Added: 
    

Modified: 
    clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index f7210d29d06cc9..2ccd3e82baadc9 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -656,6 +656,30 @@ TEST(TransferTest, SelfReferentialPointerVarDecl) {
       });
 }
 
+TEST(TransferTest, DirectlySelfReferentialReference) {
+  std::string Code = R"(
+    struct target {
+      target() {
+        (void)0;
+        // [[p]]
+      }
+      target &self = *this;
+    };
+  )";
+  runDataflow(
+      Code,
+      [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+         ASTContext &ASTCtx) {
+        const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+        const ValueDecl *SelfDecl = findValueDecl(ASTCtx, "self");
+
+        auto *ThisLoc = Env.getThisPointeeStorageLocation();
+        auto *RefVal =
+            cast<ReferenceValue>(Env.getValue(ThisLoc->getChild(*SelfDecl)));
+        ASSERT_EQ(&RefVal->getReferentLoc(), ThisLoc);
+      });
+}
+
 TEST(TransferTest, MultipleVarsDecl) {
   std::string Code = R"(
     void target() {


        


More information about the cfe-commits mailing list