Return reference instead of pointer.
We can't use a reference within the function for this pattern of repeated reassignment, but no need to return a potentially null value.
PiperOrigin-RevId: 575951413
Change-Id: I9c9b0d69781883feffb045843d3b6a1b6a556303
diff --git a/nullability/inference/collect_evidence.cc b/nullability/inference/collect_evidence.cc
index 57a97f1..d210e7f 100644
--- a/nullability/inference/collect_evidence.cc
+++ b/nullability/inference/collect_evidence.cc
@@ -172,7 +172,7 @@
// constraint representing these slots having a) the nullability inferred from
// the previous round for this slot or b) Unknown nullability if no inference
// was made in the previous round or there was no previous round.
-const Formula *getInferableSlotsAsInferredOrUnknownConstraint(
+const Formula &getInferableSlotsAsInferredOrUnknownConstraint(
std::vector<std::pair<PointerTypeNullability, Slot>> &InferableSlots,
const PreviousInferences &PreviousInferences, USRCache &USRCache,
dataflow::Arena &A, const Decl &CurrentFunc) {
@@ -188,7 +188,7 @@
: A.makeNot(Nullability.isNonnull(A));
Constraint = &A.makeAnd(*Constraint, A.makeAnd(Nullable, Nonnull));
}
- return Constraint;
+ return *Constraint;
}
void collectEvidenceFromParamAnnotation(
@@ -207,7 +207,7 @@
void collectEvidenceFromCallExpr(
std::vector<std::pair<PointerTypeNullability, Slot>> &InferableCallerSlots,
- const Formula *InferableSlotsConstraint, const CFGElement &Element,
+ const Formula &InferableSlotsConstraint, const CFGElement &Element,
const dataflow::Environment &Env,
llvm::function_ref<EvidenceEmitter> Emit) {
// Is this CFGElement a call to a function?
@@ -257,7 +257,7 @@
// Unknown, to reflect the current annotations and not all possible
// annotations for them.
NullabilityKind ArgNullability =
- getNullability(*PV, Env, InferableSlotsConstraint);
+ getNullability(*PV, Env, &InferableSlotsConstraint);
Evidence::Kind ArgEvidenceKind;
switch (ArgNullability) {
case NullabilityKind::Nullable:
@@ -275,7 +275,7 @@
void collectEvidenceFromReturn(
std::vector<std::pair<PointerTypeNullability, Slot>> &InferableSlots,
- const Formula *InferableSlotsConstraint, const CFGElement &Element,
+ const Formula &InferableSlotsConstraint, const CFGElement &Element,
const dataflow::Environment &Env,
llvm::function_ref<EvidenceEmitter> Emit) {
// Is this CFGElement a return statement?
@@ -291,7 +291,7 @@
if (!isInferenceTarget(*Env.getCurrentFunc())) return;
NullabilityKind ReturnNullability =
- getNullability(ReturnExpr, Env, InferableSlotsConstraint);
+ getNullability(ReturnExpr, Env, &InferableSlotsConstraint);
Evidence::Kind ReturnEvidenceKind;
switch (ReturnNullability) {
case NullabilityKind::Nullable:
@@ -309,7 +309,7 @@
void collectEvidenceFromElement(
std::vector<std::pair<PointerTypeNullability, Slot>> InferableSlots,
- const Formula *InferableSlotsConstraint, const CFGElement &Element,
+ const Formula &InferableSlotsConstraint, const CFGElement &Element,
const Environment &Env, llvm::function_ref<EvidenceEmitter> Emit) {
collectEvidenceFromDereference(InferableSlots, Element, Env, Emit);
collectEvidenceFromCallExpr(InferableSlots, InferableSlotsConstraint, Element,
@@ -363,7 +363,7 @@
paramSlot(I)));
}
}
- const auto *InferableSlotsConstraint =
+ const auto &InferableSlotsConstraint =
getInferableSlotsAsInferredOrUnknownConstraint(
InferableSlots, PreviousInferences, USRCache, AnalysisContext.arena(),
Decl);