Currently clang issues a warning when the following code using a shorthand form of the conditional operator is compiled:
$ cat test1.c
void foo() { int * _Nullable p0; int * _Nonnull p1; int * _Nonnull p2 = p0 ?: p1; }
test.c:4:23: warning: implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer
type 'int * _Nonnull' [-Wnullable-to-nonnull-conversion] int * _Nonnull p2 = p0 ?: p1;
This happens because sema uses the type of the first operand (p0's type, which is "int * _Nullable") for the type of the binary condition expression and then complains because a nullable pointer is being assigned to a nonnull pointer. The warning is not valid since the expression "p0 ?: p1" cannot be null if p1 is nonnull.
This patch fixes the bug by propagating the nullability of the last operand to the binary conditional expression.
This name could be improved. You're not really 'modifying' nullability here; in the general case, you're computing the appropriate nullability given the LHS, RHS, and applying that to the result type.