Skip to content

Commit

Permalink
[clang][dataflow] Add a test for a struct that is directly self-refer…
Browse files Browse the repository at this point in the history
…ential 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
  • Loading branch information
martinboehme committed Jul 4, 2023
1 parent 1e7329c commit 880f306
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 880f306

Please sign in to comment.