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