diff options
author | martinboehme <mboehme@google.com> | 2024-06-04 08:32:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-04 08:32:29 +0200 |
commit | 68761a9e05693bd3986e46628e401c80a27e945d (patch) | |
tree | caabfa5ddb3b78f83baffad86e9bd80a5b0767ee /clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | |
parent | deab451e7a7f2dff42097049274637052c87eabd (diff) | |
download | llvm-68761a9e05693bd3986e46628e401c80a27e945d.zip llvm-68761a9e05693bd3986e46628e401c80a27e945d.tar.gz llvm-68761a9e05693bd3986e46628e401c80a27e945d.tar.bz2 |
[clang][nullability] Propagate storage location / value of `++`/`--` operators. (#94217)
To avoid generating unnecessary values, we don't create a new value but
instead
leave it to the specific analysis to do this if desired.
Diffstat (limited to 'clang/unittests/Analysis/FlowSensitive/TransferTest.cpp')
-rw-r--r-- | clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index 5c0582e..cdaee9b 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -3760,6 +3760,42 @@ TEST(TransferTest, AddrOfReference) { }); } +TEST(TransferTest, Preincrement) { + std::string Code = R"( + void target(int I) { + int &IRef = ++I; + // [[p]] + } + )"; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + + EXPECT_EQ(&getLocForDecl(ASTCtx, Env, "IRef"), + &getLocForDecl(ASTCtx, Env, "I")); + }); +} + +TEST(TransferTest, Postincrement) { + std::string Code = R"( + void target(int I) { + int OldVal = I++; + // [[p]] + } + )"; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + + EXPECT_EQ(&getValueForDecl(ASTCtx, Env, "OldVal"), + &getValueForDecl(ASTCtx, Env, "I")); + }); +} + TEST(TransferTest, CannotAnalyzeFunctionTemplate) { std::string Code = R"( template <typename T> |