summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/diagnostics/no-store-func-path-notes.cpp19
-rw-r--r--clang/test/Analysis/diagnostics/no-store-func-path-notes.m35
2 files changed, 50 insertions, 4 deletions
diff --git a/clang/test/Analysis/diagnostics/no-store-func-path-notes.cpp b/clang/test/Analysis/diagnostics/no-store-func-path-notes.cpp
index b96dc4cf2a8..17ec96ae5b7 100644
--- a/clang/test/Analysis/diagnostics/no-store-func-path-notes.cpp
+++ b/clang/test/Analysis/diagnostics/no-store-func-path-notes.cpp
@@ -97,6 +97,14 @@ struct C {
int x;
int y;
C(int pX, int pY) : x(pX) {} // expected-note{{Returning without writing to 'this->y'}}
+
+ C(int pX, int pY, bool Flag) {
+ x = pX;
+ if (Flag) // expected-note{{Assuming 'Flag' is not equal to 0}}
+ // expected-note@-1{{Taking true branch}}
+ return; // expected-note{{Returning without writing to 'this->y'}}
+ y = pY;
+ }
};
int use_constructor() {
@@ -106,6 +114,15 @@ int use_constructor() {
// expected-warning@-1{{Undefined or garbage value returned to caller}}
}
+int coin();
+
+int use_other_constructor() {
+ C c(0, 0, coin()); // expected-note{{Calling constructor for 'C'}}
+ // expected-note@-1{{Returning from constructor for 'C'}}
+ return c.y; // expected-note{{Undefined or garbage value returned to caller}}
+ // expected-warning@-1{{Undefined or garbage value returned to caller}}
+}
+
struct D {
void initialize(int *);
};
@@ -122,8 +139,6 @@ int use_d_initializer(D* d) {
// expected-warning@-1{{Undefined or garbage value returned to caller}}
}
-int coin();
-
struct S2 {
int x;
};
diff --git a/clang/test/Analysis/diagnostics/no-store-func-path-notes.m b/clang/test/Analysis/diagnostics/no-store-func-path-notes.m
index 3ae97ef5649..51d1515e860 100644
--- a/clang/test/Analysis/diagnostics/no-store-func-path-notes.m
+++ b/clang/test/Analysis/diagnostics/no-store-func-path-notes.m
@@ -1,6 +1,10 @@
-// RUN: %clang_analyze_cc1 -x objective-c -analyzer-checker=core -analyzer-output=text -Wno-objc-root-class -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -x objective-c -analyzer-checker=core,nullability -analyzer-output=text -Wno-objc-root-class -fblocks -verify %s
-@interface I
+#include "../Inputs/system-header-simulator-for-nullability.h"
+
+extern int coin();
+
+@interface I : NSObject
- (int)initVar:(int *)var param:(int)param;
@end
@@ -44,3 +48,30 @@ int initFromBlock() {
}();
return z;
}
+
+extern void expectNonNull(NSString * _Nonnull a);
+
+@interface A : NSObject
+- (void) func;
+- (void) initAMaybe;
+@end
+
+@implementation A {
+ NSString * a;
+}
+
+- (void) initAMaybe {
+ if (coin()) // expected-note{{Assuming the condition is false}}
+ // expected-note@-1{{Taking false branch}}
+ a = @"string";
+} // expected-note{{Returning without writing to 'self->a'}}
+
+- (void) func {
+ a = nil; // expected-note{{nil object reference stored to 'a'}}
+ [self initAMaybe]; // expected-note{{Calling 'initAMaybe'}}
+ // expected-note@-1{{Returning from 'initAMaybe'}}
+ expectNonNull(a); // expected-warning{{nil passed to a callee that requires a non-null 1st parameter}}
+ // expected-note@-1{{nil passed to a callee that requires a non-null 1st parameter}}
+}
+
+@end
OpenPOWER on IntegriCloud