Handle accessors that directly return a pointer member variable
This is to handle the common pattern where the return value of an accessor is tested to see if it is non-null and, if so, the accessor called again to dereference the pointer. For example (`get_const()` is annotated as nullable)
```
if (foo.get_const()) {
foo.get_const()->doThing(); // SAFE
}
```
Additionally, non-const member functions are treated as if they mutate the values of any non-static member variables of pointer type.
```
if (foo.get_const()) {
foo.nonconst_method();
foo.get_const()->doThing(); // UNSAFE
}
PiperOrigin-RevId: 574227988
Change-Id: Ie28fd056d576f0e41f01ffe7cbae198f60fe68e1
diff --git a/nullability/BUILD b/nullability/BUILD
index 7b06d42..4ca6a1c 100644
--- a/nullability/BUILD
+++ b/nullability/BUILD
@@ -24,6 +24,7 @@
hdrs = ["pointer_nullability_matchers.h"],
visibility = [
"//nullability/inference:__pkg__",
+ "//nullability/test:__pkg__",
],
deps = [
":type_nullability",
@@ -32,6 +33,19 @@
],
)
+cc_test(
+ name = "pointer_nullability_matchers_test",
+ srcs = ["pointer_nullability_matchers_test.cc"],
+ deps = [
+ ":pointer_nullability_matchers",
+ "@llvm-project//clang:ast_matchers",
+ "@llvm-project//clang:testing",
+ "@llvm-project//llvm:Support",
+ "@llvm-project//third-party/unittest:gtest",
+ "@llvm-project//third-party/unittest:gtest_main",
+ ],
+)
+
cc_library(
name = "pointer_nullability_analysis",
srcs = ["pointer_nullability_analysis.cc"],