ahatanak added a comment.

I'm thinking about taking the following steps to compute the nullability of 
ternary operators.

The first step is to compute the "merged" nullability of the LHS and RHS.

For normal ternary operators (not the shorthand version):

- If both LHS and RHS have the same nullability (one of nonnull, nullable, 
null_unspecified, or none), pick that as the merged nullability.
- Otherwise, if either side is nullable, the merged nullability is nullable too.
- Otherwise, if either side is nonnull, pick the nullability of the other side. 
For example, if (LHS,RHS) == (nonnull, none), the merged nullability is none 
because we can't guarantee that the result is nonnull.
- Otherwise, the nullability is either null_unspecified or none. I think we can 
pick either one in this case.

For binary conditional operators like "p0 ?: p1":

- If the LHS (p0) is nonnull, the merged nullability is nonnull.
- Otherwise, the merged nullability is the nullability of the RHS (p1).

Once we have the merged nullability, the next step is to compare it with the 
result's nullability. If the nullability kinds differ, a new type that has the 
merged nullability is created.

Note that it looks like we might be able to simplify the steps described above 
if we take advantage of the fact that clang only warns when a nullable pointer 
is assigned/passed to a nonnull pointer (I don't think clang issues any 
warnings, for example, when a null_unspecified pointer is assigned to a nonnull 
pointer).


https://reviews.llvm.org/D22392



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to