Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental -analyzer-store=basic -analyzer-constraints=basic -verify %s
      2 // RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental -analyzer-store=basic -analyzer-constraints=range -verify %s
      3 // RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental -analyzer-store=region -analyzer-constraints=basic -verify %s
      4 // RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental -analyzer-store=region -analyzer-constraints=range -verify %s
      5 
      6 #include <stdarg.h>
      7 
      8 //===----------------------------------------------------------------------===//
      9 // The following code is reduced using delta-debugging from
     10 // Foundation.h (Mac OS X).
     11 //
     12 // It includes the basic definitions for the test cases below.
     13 // Not directly including Foundation.h directly makes this test case 
     14 // both svelte and portable to non-Mac platforms.
     15 //===----------------------------------------------------------------------===//
     16 
     17 typedef signed char BOOL;
     18 typedef unsigned int NSUInteger;
     19 typedef struct _NSZone NSZone;
     20 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
     21 @protocol NSObject  - (BOOL)isEqual:(id)object;
     22 @end  @protocol NSCopying  - (id)copyWithZone:(NSZone *)zone;
     23 @end  @protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone; @end
     24 @protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end
     25 @interface NSObject <NSObject> {} @end
     26 extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
     27 @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
     28 - (NSUInteger)length;
     29 + (id)stringWithFormat:(NSString *)format, ...;
     30 @end
     31 @interface NSSimpleCString : NSString {} @end
     32 @interface NSConstantString : NSSimpleCString @end
     33 extern void *_NSConstantStringClassReference;
     34 typedef double NSTimeInterval;
     35 @interface NSDate : NSObject <NSCopying, NSCoding>  - (NSTimeInterval)timeIntervalSinceReferenceDate; @end
     36 @class NSString, NSDictionary, NSArray;
     37 @interface NSException : NSObject <NSCopying, NSCoding> {}
     38 + (NSException *)exceptionWithName:(NSString *)name reason:(NSString *)reason userInfo:(NSDictionary *)userInfo;
     39 - (void)raise;
     40 @end
     41 @interface NSException (NSExceptionRaisingConveniences)
     42 + (void)raise:(NSString *)name format:(NSString *)format, ...;
     43 + (void)raise:(NSString *)name format:(NSString *)format arguments:(va_list)argList;
     44 @end
     45 
     46 enum {NSPointerFunctionsStrongMemory = (0 << 0),     NSPointerFunctionsZeroingWeakMemory = (1 << 0),     NSPointerFunctionsOpaqueMemory = (2 << 0),     NSPointerFunctionsMallocMemory = (3 << 0),     NSPointerFunctionsMachVirtualMemory = (4 << 0),        NSPointerFunctionsObjectPersonality = (0 << 8),     NSPointerFunctionsOpaquePersonality = (1 << 8),     NSPointerFunctionsObjectPointerPersonality = (2 << 8),     NSPointerFunctionsCStringPersonality = (3 << 8),     NSPointerFunctionsStructPersonality = (4 << 8),     NSPointerFunctionsIntegerPersonality = (5 << 8),      NSPointerFunctionsCopyIn = (1 << 16), };
     47 
     48 //===----------------------------------------------------------------------===//
     49 // Test cases.
     50 //===----------------------------------------------------------------------===//
     51 
     52 int f1(int *x, NSString* s) {
     53   
     54   if (x) ++x;
     55   
     56   [NSException raise:@"Blah" format:[NSString stringWithFormat:@"Blah %@", s]];
     57   
     58   return *x; // no-warning
     59 }
     60 
     61 int f2(int *x, ...) {
     62   
     63   if (x) ++x;
     64   va_list alist;
     65   va_start(alist, x);
     66   
     67   [NSException raise:@"Blah" format:@"Blah %@" arguments:alist];
     68   
     69   return *x; // no-warning
     70 }
     71 
     72 int f3(int* x) {
     73   
     74   if (x) ++x;
     75   
     76   [[NSException exceptionWithName:@"My Exception" reason:@"Want to test exceptions." userInfo:0] raise];
     77 
     78   return *x; // no-warning
     79 }
     80 
     81