Split functions relating to type-nullability out of pointer_nullability.h
The former has been kind of an "everything that needs to be shared" grab-bag,
and it's growing...
The functionality here today splits neatly into two groups, one that interacts
with the Value world and one that interacts with the Type world, with analysis
depending on both.
The exception is getNullabilityForChild, which fits naturally into analysis.
It was moved here with the plan of being shared with diagnosis. but hasn't been.
It doesn't seem suitable to sharein its current form - it causes other layering
problems too, and its preconditions/API are defined in terms of analysis.
So I've moved this back into analysis for now.
Wrote a few words about the type-nullability model.
I'd like to follow up by renaming a few functions, adding a TypeNullability
alias, adding more tests, but trying to keep the scope for discussion smaller.
PiperOrigin-RevId: 528755134
diff --git a/nullability/pointer_nullability_analysis.cc b/nullability/pointer_nullability_analysis.cc
index 7ab5c82..bacba41 100644
--- a/nullability/pointer_nullability_analysis.cc
+++ b/nullability/pointer_nullability_analysis.cc
@@ -12,6 +12,7 @@
#include "nullability/pointer_nullability.h"
#include "nullability/pointer_nullability_lattice.h"
#include "nullability/pointer_nullability_matchers.h"
+#include "nullability/type_nullability.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTDumper.h"
#include "clang/AST/Expr.h"
@@ -76,6 +77,23 @@
});
}
+// Returns the computed nullability for a subexpr of the current expression.
+// This is always available as we compute bottom-up.
+ArrayRef<NullabilityKind> getNullabilityForChild(
+ const Expr* E, TransferState<PointerNullabilityLattice>& State) {
+ return State.Lattice.insertExprNullabilityIfAbsent(E, [&] {
+ // Since we process child nodes before parents, we should already have
+ // computed the child nullability. However, this is not true in all test
+ // cases. So, we return unspecified nullability annotations.
+ // TODO: fix this issue, and CHECK() instead.
+ llvm::dbgs() << "=== Missing child nullability: ===\n";
+ dump(E, llvm::dbgs());
+ llvm::dbgs() << "==================================\n";
+
+ return unspecifiedNullability(E);
+ });
+}
+
/// Compute the nullability annotation of type `T`, which contains types
/// originally written as a class template type parameter.
///
@@ -692,6 +710,7 @@
return true;
}
+
} // namespace nullability
} // namespace tidy
} // namespace clang