aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
diff options
context:
space:
mode:
authormartinboehme <mboehme@google.com>2024-06-04 08:32:29 +0200
committerGitHub <noreply@github.com>2024-06-04 08:32:29 +0200
commit68761a9e05693bd3986e46628e401c80a27e945d (patch)
treecaabfa5ddb3b78f83baffad86e9bd80a5b0767ee /clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
parentdeab451e7a7f2dff42097049274637052c87eabd (diff)
downloadllvm-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.cpp36
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>