NoReturn.m revision ef74f4c6dcd59b3af1de9d8f613c1caf3e6cb63d
1// RUN: clang -cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s 2// RUN: clang -cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s 3// RUN: clang -cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s 4// RUN: clang -cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -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 17typedef signed char BOOL; 18typedef unsigned int NSUInteger; 19typedef 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 26extern 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 33extern void *_NSConstantStringClassReference; 34typedef 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 46enum {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 52int 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 61int 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 72int 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