[nullability] Add repro for false positive caused by inconsistent loop state.
PiperOrigin-RevId: 572128694
Change-Id: Id82722af64342c72fd35e3b9f01fcc6c929a296e
diff --git a/nullability/test/convergence.cc b/nullability/test/convergence.cc
index 6aeb2ea..8c3be15 100644
--- a/nullability/test/convergence.cc
+++ b/nullability/test/convergence.cc
@@ -276,5 +276,28 @@
)cc"));
}
+// Repro for a false positive caused by an inconsistent representation of state
+// in a loop.
+TEST(PointerNullabilityTest, InconsistentLoopStateRepro) {
+ EXPECT_TRUE(checkDiagnostics(R"cc(
+ int* _Nullable GetNullable();
+ bool cond();
+
+ void target(int* b, int* e) {
+ // This loop is necessary for the false positive to occur.
+ for (; b != e; ++b)
+ ;
+
+ int* ptr = GetNullable();
+ if (ptr != nullptr) {
+ while (cond()) {
+ // TODO: False positive. This dereference is safe.
+ (void)*ptr; // [[unsafe]]
+ }
+ }
+ }
+ )cc"));
+}
+
} // namespace
} // namespace clang::tidy::nullability