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 @@ -656,6 +656,30 @@ }); } +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() {