r276696 - [Sema][ObjC] Compute the nullability of a conditional expression based
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 25 14:58:20 PDT 2016
Author: ahatanak
Date: Mon Jul 25 16:58:19 2016
New Revision: 276696
URL: http://llvm.org/viewvc/llvm-project?rev=276696&view=rev
Log:
[Sema][ObjC] Compute the nullability of a conditional expression based
on the nullabilities of its operands.
This commit is a follow-up to r276076 and enables
computeConditionalNullability to compute the merged nullability when
the operands are objective-c pointers.
rdar://problem/22074116
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/nullability.m
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=276696&r1=276695&r2=276696&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jul 25 16:58:19 2016
@@ -7016,7 +7016,7 @@ static void DiagnoseConditionalPrecedenc
static QualType computeConditionalNullability(QualType ResTy, bool IsBin,
QualType LHSTy, QualType RHSTy,
ASTContext &Ctx) {
- if (!ResTy->isPointerType())
+ if (!ResTy->isAnyPointerType())
return ResTy;
auto GetNullability = [&Ctx](QualType Ty) {
Modified: cfe/trunk/test/SemaObjC/nullability.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/nullability.m?rev=276696&r1=276695&r2=276696&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/nullability.m (original)
+++ cfe/trunk/test/SemaObjC/nullability.m Mon Jul 25 16:58:19 2016
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fblocks -Woverriding-method-mismatch -Wno-nullability-declspec %s -verify
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Woverriding-method-mismatch -Wno-nullability-declspec -Wnullable-to-nonnull-conversion %s -verify
__attribute__((objc_root_class))
@interface NSFoo
@@ -230,3 +230,29 @@ void testBlockLiterals() {
int *x = (^ _Nullable id(void) { return 0; })(); // expected-warning{{incompatible pointer types initializing 'int *' with an expression of type 'id _Nullable'}}
}
+
+// Check nullability of conditional expressions.
+void conditional_expr(int c) {
+ NSFoo * _Nonnull p;
+ NSFoo * _Nonnull nonnullP;
+ NSFoo * _Nullable nullableP;
+ NSFoo * _Null_unspecified unspecifiedP;
+ NSFoo *noneP;
+
+ p = c ? nonnullP : nonnullP;
+ p = c ? nonnullP : nullableP; // expected-warning{{implicit conversion from nullable pointer 'NSFoo * _Nullable' to non-nullable pointer type 'NSFoo * _Nonnull'}}
+ p = c ? nonnullP : unspecifiedP;
+ p = c ? nonnullP : noneP;
+ p = c ? nullableP : nonnullP; // expected-warning{{implicit conversion from nullable pointer 'NSFoo * _Nullable' to non-nullable pointer type 'NSFoo * _Nonnull'}}
+ p = c ? nullableP : nullableP; // expected-warning{{implicit conversion from nullable pointer 'NSFoo * _Nullable' to non-nullable pointer type 'NSFoo * _Nonnull'}}
+ p = c ? nullableP : unspecifiedP; // expected-warning{{implicit conversion from nullable pointer 'NSFoo * _Nullable' to non-nullable pointer type 'NSFoo * _Nonnull'}}
+ p = c ? nullableP : noneP; // expected-warning{{implicit conversion from nullable pointer 'NSFoo * _Nullable' to non-nullable pointer type 'NSFoo * _Nonnull'}}
+ p = c ? unspecifiedP : nonnullP;
+ p = c ? unspecifiedP : nullableP; // expected-warning{{implicit conversion from nullable pointer 'NSFoo * _Nullable' to non-nullable pointer type 'NSFoo * _Nonnull'}}
+ p = c ? unspecifiedP : unspecifiedP;
+ p = c ? unspecifiedP : noneP;
+ p = c ? noneP : nonnullP;
+ p = c ? noneP : nullableP; // expected-warning{{implicit conversion from nullable pointer 'NSFoo * _Nullable' to non-nullable pointer type 'NSFoo * _Nonnull'}}
+ p = c ? noneP : unspecifiedP;
+ p = c ? noneP : noneP;
+}
More information about the cfe-commits
mailing list