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