diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index f7210d29d06cc..2ccd3e82baadc 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> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + const ValueDecl *SelfDecl = findValueDecl(ASTCtx, "self"); + + auto *ThisLoc = Env.getThisPointeeStorageLocation(); + auto *RefVal = + cast(Env.getValue(ThisLoc->getChild(*SelfDecl))); + ASSERT_EQ(&RefVal->getReferentLoc(), ThisLoc); + }); +} + TEST(TransferTest, MultipleVarsDecl) { std::string Code = R"( void target() {