summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@apple.com>2018-07-26 17:51:13 +0000
committerAkira Hatanaka <ahatanaka@apple.com>2018-07-26 17:51:13 +0000
commit66d405d31f5cb778902315fbefd6421fa85aa6d1 (patch)
tree7eb985144e2f403899d70302d3dc96ad5b1e8252 /clang
parent2e4106b73da2bd2845f9676e79ea43d4d3540813 (diff)
downloadbcm5719-llvm-66d405d31f5cb778902315fbefd6421fa85aa6d1.tar.gz
bcm5719-llvm-66d405d31f5cb778902315fbefd6421fa85aa6d1.zip
[Sema][ObjC] Do not propagate the nullability specifier on the receiver
to the result type of a message send if the result type cannot have a nullability specifier. Previously, clang would print the following message when the code in nullability.m was compiled: "incompatible integer to pointer conversion initializing 'int *' with an expression of type 'int _Nullable'" This is wrong as 'int' isn't supposed to have any nullability specifiers. rdar://problem/40830514 llvm-svn: 338048
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp5
-rw-r--r--clang/test/SemaObjC/nullability.m11
2 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index bf9d081bb95..bf0ffeba06b 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -1357,6 +1357,11 @@ QualType Sema::getMessageSendResultType(QualType ReceiverType,
if (isClassMessage)
return resultType;
+ // There is nothing left to do if the result type cannot have a nullability
+ // specifier.
+ if (!resultType->canHaveNullability())
+ return resultType;
+
// Map the nullability of the result into a table index.
unsigned receiverNullabilityIdx = 0;
if (auto nullability = ReceiverType->getNullability(Context))
diff --git a/clang/test/SemaObjC/nullability.m b/clang/test/SemaObjC/nullability.m
index cbfe132d143..93f4d1d4994 100644
--- a/clang/test/SemaObjC/nullability.m
+++ b/clang/test/SemaObjC/nullability.m
@@ -279,3 +279,14 @@ void test(ArraysInMethods *obj) {
[obj simpleSugar:0]; // expected-warning {{null passed to a callee that requires a non-null argument}}
[obj sugarWithTypedef:0]; // expected-warning {{null passed to a callee that requires a non-null argument}}
}
+
+// Check that we don't propagate the nullability specifier on the receiver to
+// the result type of a message send if the result type cannot have a
+// nullability specifier.
+@interface C0
+-(int) count;
+@end
+
+void testMessageSendResultType(C0 * _Nullable c0) {
+ int *p = [c0 count]; // expected-warning {{incompatible integer to pointer conversion initializing 'int *' with an expression of type 'int'}}
+}
OpenPOWER on IntegriCloud