summaryrefslogtreecommitdiff
path: root/test/Analysis/objc-for.m
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis/objc-for.m')
-rw-r--r--test/Analysis/objc-for.m25
1 files changed, 22 insertions, 3 deletions
diff --git a/test/Analysis/objc-for.m b/test/Analysis/objc-for.m
index 41709bee359e..f191e86cc4e4 100644
--- a/test/Analysis/objc-for.m
+++ b/test/Analysis/objc-for.m
@@ -1,6 +1,7 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.Loops,debug.ExprInspection -verify %s
void clang_analyzer_eval(int);
+void clang_analyzer_warnIfReached();
#define nil ((id)0)
@@ -20,11 +21,13 @@ typedef unsigned long NSUInteger;
@interface NSArray : NSObject <NSFastEnumeration>
- (NSUInteger)count;
- (NSEnumerator *)objectEnumerator;
++ (NSArray *)arrayWithObjects:(const id [])objects count:(NSUInteger)count;
@end
@interface NSDictionary : NSObject <NSFastEnumeration>
- (NSUInteger)count;
- (id)objectForKey:(id)key;
++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id /* <NSCopying> */ [])keys count:(NSUInteger)count;
@end
@interface NSDictionary (SomeCategory)
@@ -125,7 +128,7 @@ int collectionIsNotEmptyNSArray(NSArray *A) {
int count = [A count];
if (count > 0) {
int i;
- int j;
+ int j = 0;
for (NSString *a in A) {
i = 1;
j++;
@@ -138,7 +141,7 @@ int collectionIsNotEmptyNSArray(NSArray *A) {
void onlySuppressExitAfterZeroIterations(NSMutableDictionary *D) {
if (D.count > 0) {
int *x;
- int i;
+ int i = 0;
for (NSString *key in D) {
x = 0;
i++;
@@ -152,7 +155,7 @@ void onlySuppressExitAfterZeroIterations(NSMutableDictionary *D) {
void onlySuppressLoopExitAfterZeroIterations_WithContinue(NSMutableDictionary *D) {
if (D.count > 0) {
int *x;
- int i;
+ int i = 0;
for (NSString *key in D) {
x = 0;
i++;
@@ -324,3 +327,19 @@ void protocolMethods(NSMutableArray *array) {
for (id key in array)
clang_analyzer_eval(0); // expected-warning{{FALSE}}
}
+
+NSArray *globalArray;
+NSDictionary *globalDictionary;
+void boxedArrayEscape(NSMutableArray *array) {
+ if ([array count])
+ return;
+ globalArray = @[array];
+ for (id key in array)
+ clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+
+ if ([array count])
+ return;
+ globalDictionary = @{ @"array" : array };
+ for (id key in array)
+ clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}