[cfe-commits] r139506 - /cfe/trunk/test/Analysis/analyzeOneFunction.m

Anna Zaks ganna at apple.com
Mon Sep 12 10:48:08 PDT 2011


Author: zaks
Date: Mon Sep 12 12:48:08 2011
New Revision: 139506

URL: http://llvm.org/viewvc/llvm-project?rev=139506&view=rev
Log:
[analyzer] Test for -analyze-function on ObjectiveC to accompany r139439.

Added:
    cfe/trunk/test/Analysis/analyzeOneFunction.m

Added: cfe/trunk/test/Analysis/analyzeOneFunction.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzeOneFunction.m?rev=139506&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/analyzeOneFunction.m (added)
+++ cfe/trunk/test/Analysis/analyzeOneFunction.m Mon Sep 12 12:48:08 2011
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -analyze -analyze-function="myMethodWithY:withX:" -analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region -verify %s
+
+typedef signed char BOOL;
+typedef unsigned int NSUInteger;
+typedef struct _NSZone NSZone;
+ at class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+ at protocol NSObject  - (BOOL)isEqual:(id)object; @end
+ at protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end
+ at protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end
+ at protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone; @end
+ at interface NSObject <NSObject> {}
++(id)alloc;
+-(id)init;
+-(id)autorelease;
+-(id)copy;
+-(id)retain;
+ at end
+ at interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
+- (NSUInteger)length;
+-(id)initWithFormat:(NSString *)f,...;
+-(BOOL)isEqualToString:(NSString *)s;
++ (id)string;
+ at end
+
+ at interface Test1 : NSObject {
+  NSString *text;
+}
+-(id)myMethod;
+-(id)myMethodWithY:(int)Y withX:(int)X;
+
+ at property (nonatomic, assign) NSString *text;
+ at end
+
+ at implementation Test1
+
+ at synthesize text;
+
+-(id)myMethod {
+  Test1 *cell = [[[Test1 alloc] init] autorelease];
+
+  NSString *string1 = [[NSString alloc] initWithFormat:@"test %f", 0.0]; // No warning: this function is not analized.
+  cell.text = string1;
+
+  return cell;
+}
+
+-(id)myMethodWithY:(int)Y withX:(int)X {
+  Test1 *cell = [[[Test1 alloc] init] autorelease];
+
+  NSString *string1 = [[NSString alloc] initWithFormat:@"test %f %d", 0.0, X+Y]; // expected-warning {{Potential leak}}
+  cell.text = string1;
+
+  return cell;
+}
+
+ at end





More information about the cfe-commits mailing list