Check that return values comply with the nullability annotations (if any) on the function return type.
For example, it is unsafe to return a nullable value where the return type has been annotated to nonnull.
```
int * _Nonnull foo(int * _Nullable ptr_nullable) {
return ptr_nullable; // Unsafe
}
```
PiperOrigin-RevId: 470203776
diff --git a/nullability_verification/pointer_nullability_matchers.cc b/nullability_verification/pointer_nullability_matchers.cc
index 15e5f9f..6fa440d 100644
--- a/nullability_verification/pointer_nullability_matchers.cc
+++ b/nullability_verification/pointer_nullability_matchers.cc
@@ -21,12 +21,14 @@
using ast_matchers::hasCastKind;
using ast_matchers::hasOperands;
using ast_matchers::hasOperatorName;
+using ast_matchers::hasReturnValue;
using ast_matchers::hasType;
using ast_matchers::hasUnaryOperand;
using ast_matchers::implicitCastExpr;
using ast_matchers::isAnyPointer;
using ast_matchers::isArrow;
using ast_matchers::memberExpr;
+using ast_matchers::returnStmt;
using ast_matchers::unaryOperator;
using ast_matchers::internal::Matcher;
@@ -55,6 +57,9 @@
Matcher<Stmt> isPointerArrow() { return memberExpr(isArrow()); }
Matcher<Stmt> isCXXThisExpr() { return cxxThisExpr(); }
Matcher<Stmt> isCallExpr() { return callExpr(); }
+Matcher<Stmt> isPointerReturn() {
+ return returnStmt(hasReturnValue(hasType(isAnyPointer())));
+}
} // namespace nullability
} // namespace tidy