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,28 @@ }); } +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(); + ASSERT_EQ(&ThisLoc->getChild(*SelfDecl), ThisLoc); + }); +} + TEST(TransferTest, MultipleVarsDecl) { std::string Code = R"( void target() {