From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/Analysis/uninit-msg-expr.m | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 clang/test/Analysis/uninit-msg-expr.m (limited to 'clang/test/Analysis/uninit-msg-expr.m') diff --git a/clang/test/Analysis/uninit-msg-expr.m b/clang/test/Analysis/uninit-msg-expr.m new file mode 100644 index 0000000..19fdf61 --- /dev/null +++ b/clang/test/Analysis/uninit-msg-expr.m @@ -0,0 +1,56 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-store=region -verify %s + +//===----------------------------------------------------------------------===// +// The following code is reduced using delta-debugging from +// Foundation.h (Mac OS X). +// +// It includes the basic definitions for the test cases below. +// Not directly including Foundation.h directly makes this test case +// both svelte and portable to non-Mac platforms. +//===----------------------------------------------------------------------===// + +typedef signed char BOOL; +typedef unsigned int NSUInteger; +typedef struct _NSZone NSZone; +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; +@protocol NSObject - (BOOL)isEqual:(id)object; @end +@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end +@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end +@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end +@interface NSObject {} @end +@class NSString, NSData; +@class NSString, NSData, NSMutableData, NSMutableDictionary, NSMutableArray; +typedef struct {} NSFastEnumerationState; +@protocol NSFastEnumeration +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; +@end +@class NSData, NSIndexSet, NSString, NSURL; +@interface NSArray : NSObject +- (NSUInteger)count; +@end +@interface NSArray (NSArrayCreation) ++ (id)array; +- (NSUInteger)length; +- (void)addObject:(id)object; +@end +extern NSString * const NSUndoManagerCheckpointNotification; + +//===----------------------------------------------------------------------===// +// Test cases. +//===----------------------------------------------------------------------===// + +unsigned f1() { + NSString *aString; + return [aString length]; // expected-warning {{Receiver in message expression is an uninitialized value}} +} + +unsigned f2() { + NSString *aString = 0; + return [aString length]; // no-warning +} + +void f3() { + NSMutableArray *aArray = [NSArray array]; + NSString *aString; + [aArray addObject:aString]; // expected-warning {{Argument in message expression is an uninitialized value}} +} -- cgit v1.2.3