summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2016-12-15 22:55:15 +0000
committerAnna Zaks <ganna@apple.com>2016-12-15 22:55:15 +0000
commit6d4e76b988080060fc6b1fe0fbb1194ea6bf5e76 (patch)
tree2bf4b34055143f0dbb1e70545386c3d3dc3b0cb8 /clang/test
parent40c74c6d2233f7c228365740f683c4d16c0693c6 (diff)
downloadbcm5719-llvm-6d4e76b988080060fc6b1fe0fbb1194ea6bf5e76.tar.gz
bcm5719-llvm-6d4e76b988080060fc6b1fe0fbb1194ea6bf5e76.zip
[analyzer] Refine the diagnostics in the nullability checker to differentiate between nil and null
This is a big deal for ObjC, where nullability annotations are extensively used. I've also changed "Null" -> "null" and removed "is" as this is the pattern that Sema is using. Differential Revision: https://reviews.llvm.org/D27600 llvm-svn: 289885
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/nullability-no-arc.mm12
-rw-r--r--clang/test/Analysis/nullability.mm6
-rw-r--r--clang/test/Analysis/nullability_nullonly.mm18
3 files changed, 18 insertions, 18 deletions
diff --git a/clang/test/Analysis/nullability-no-arc.mm b/clang/test/Analysis/nullability-no-arc.mm
index 37d29b7457a..e872266d277 100644
--- a/clang/test/Analysis/nullability-no-arc.mm
+++ b/clang/test/Analysis/nullability-no-arc.mm
@@ -17,20 +17,20 @@ NSObject<NSObject>
@interface TestObject : NSObject
@end
-TestObject * _Nonnull returnsNilObjCInstanceIndirectly() {
- TestObject *local = 0;
- return local; // expected-warning {{Null is returned from a function that is expected to return a non-null value}}
+TestObject *_Nonnull returnsNilObjCInstanceIndirectly() {
+ TestObject *local = nil;
+ return local; // expected-warning {{nil returned from a function that is expected to return a non-null value}}
}
TestObject * _Nonnull returnsNilObjCInstanceIndirectlyWithSupressingCast() {
- TestObject *local = 0;
+ TestObject *local = nil;
return (TestObject * _Nonnull)local; // no-warning
}
TestObject * _Nonnull returnsNilObjCInstanceDirectly() {
// The first warning is from Sema. The second is from the static analyzer.
return nil; // expected-warning {{null returned from function that requires a non-null return value}}
- // expected-warning@-1 {{Null is returned from a function that is expected to return a non-null value}}
+ // expected-warning@-1 {{nil returned from a function that is expected to return a non-null value}}
}
TestObject * _Nonnull returnsNilObjCInstanceDirectlyWithSuppressingCast() {
@@ -43,7 +43,7 @@ void testObjCNonARCNoInitialization(TestObject * _Nonnull p) {
}
void testObjCNonARCExplicitZeroInitialization() {
- TestObject * _Nonnull explicitlyZeroInitialized = nil; // expected-warning {{Null is assigned to a pointer which is expected to have non-null value}}
+ TestObject * _Nonnull explicitlyZeroInitialized = nil; // expected-warning {{nil assigned to a pointer which is expected to have non-null value}}
}
@interface ClassWithInitializers : NSObject
diff --git a/clang/test/Analysis/nullability.mm b/clang/test/Analysis/nullability.mm
index ac2a839f40f..e4f13c6162c 100644
--- a/clang/test/Analysis/nullability.mm
+++ b/clang/test/Analysis/nullability.mm
@@ -75,7 +75,7 @@ void testBasicRules() {
}
Dummy a;
Dummy *_Nonnull nonnull = &a;
- nonnull = q; // expected-warning {{Null is assigned to a pointer which is expected to have non-null value}}
+ nonnull = q; // expected-warning {{Null assigned to a pointer which is expected to have non-null value}}
q = &a;
takesNullable(q);
takesNonnull(q);
@@ -107,7 +107,7 @@ Dummy *_Nonnull testNullableReturn(Dummy *_Nullable a) {
Dummy *_Nonnull testNullReturn() {
Dummy *p = 0;
- return p; // expected-warning {{Null is returned from a function that is expected to return a non-null value}}
+ return p; // expected-warning {{Null returned from a function that is expected to return a non-null value}}
}
void testObjCMessageResultNullability() {
@@ -229,7 +229,7 @@ void testConditionalNilPassToNonnull(Dummy *p) {
Dummy * _Nonnull testIndirectCastNilToNonnullAndReturn() {
Dummy *p = (Dummy * _Nonnull)0;
// FIXME: Ideally the cast above would suppress this warning.
- return p; // expected-warning {{Null is returned from a function that is expected to return a non-null value}}
+ return p; // expected-warning {{Null returned from a function that is expected to return a non-null value}}
}
void testInvalidPropagation() {
diff --git a/clang/test/Analysis/nullability_nullonly.mm b/clang/test/Analysis/nullability_nullonly.mm
index 9671877719f..359841d97a6 100644
--- a/clang/test/Analysis/nullability_nullonly.mm
+++ b/clang/test/Analysis/nullability_nullonly.mm
@@ -24,7 +24,7 @@ void testBasicRules() {
Dummy *_Nonnull testNullReturn() {
Dummy *p = 0;
- return p; // expected-warning {{Null is returned from a function that is expected to return a non-null value}}
+ return p; // expected-warning {{Null returned from a function that is expected to return a non-null value}}
}
void onlyReportFirstPreconditionViolationOnPath() {
@@ -100,24 +100,24 @@ void testObjCARCImplicitZeroInitialization() {
}
void testObjCARCExplicitZeroInitialization() {
- TestObject * _Nonnull explicitlyZeroInitialized = nil; // expected-warning {{Null is assigned to a pointer which is expected to have non-null value}}
+ TestObject * _Nonnull explicitlyZeroInitialized = nil; // expected-warning {{nil assigned to a pointer which is expected to have non-null value}}
}
// Under ARC, returned expressions of ObjC objects types are are implicitly
// cast to _Nonnull when the functions return type is _Nonnull, so make
// sure this doesn't implicit cast doesn't suppress a legitimate warning.
TestObject * _Nonnull returnsNilObjCInstanceIndirectly() {
- TestObject *local = 0;
- return local; // expected-warning {{Null is returned from a function that is expected to return a non-null value}}
+ TestObject *local = nil;
+ return local; // expected-warning {{nil returned from a function that is expected to return a non-null value}}
}
TestObject * _Nonnull returnsNilObjCInstanceIndirectlyWithSupressingCast() {
- TestObject *local = 0;
+ TestObject *local = nil;
return (TestObject * _Nonnull)local; // no-warning
}
TestObject * _Nonnull returnsNilObjCInstanceDirectly() {
- return nil; // expected-warning {{Null is returned from a function that is expected to return a non-null value}}
+ return nil; // expected-warning {{nil returned from a function that is expected to return a non-null value}}
}
TestObject * _Nonnull returnsNilObjCInstanceDirectlyWithSuppressingCast() {
@@ -130,7 +130,7 @@ TestObject * _Nonnull returnsNilObjCInstanceDirectlyWithSuppressingCast() {
@implementation SomeClass (MethodReturn)
- (SomeClass * _Nonnull)testReturnsNilInNonnull {
SomeClass *local = nil;
- return local; // expected-warning {{Null is returned from a method that is expected to return a non-null value}}
+ return local; // expected-warning {{nil returned from a method that is expected to return a non-null value}}
}
- (SomeClass * _Nonnull)testReturnsCastSuppressedNilInNonnull {
@@ -154,7 +154,7 @@ void callFunctionInSystemHeader() {
NSSystemFunctionTakingNonnull(s);
#if !NOSYSTEMHEADERS
- // expected-warning@-2{{Null passed to a callee that requires a non-null 1st parameter}}
+ // expected-warning@-2{{nil passed to a callee that requires a non-null 1st parameter}}
#endif
}
@@ -165,6 +165,6 @@ void callMethodInSystemHeader() {
NSSystemClass *sc = [[NSSystemClass alloc] init];
[sc takesNonnull:s];
#if !NOSYSTEMHEADERS
- // expected-warning@-2{{Null passed to a callee that requires a non-null 1st parameter}}
+ // expected-warning@-2{{nil passed to a callee that requires a non-null 1st parameter}}
#endif
}
OpenPOWER on IntegriCloud