blob: a2b7477db8bcaccca49f5e07219815580daea464 [file] [log] [blame]
Ted Kremenek8382cf52009-11-13 18:46:29 +00001// RUN: clang-cc -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s
2// RUN: clang-cc -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s
3// RUN: clang-cc -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s
4// RUN: clang-cc -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s
Ted Kremenekc083b0d2008-07-18 20:48:10 +00005
6// This test case was reported in <rdar:problem/6080742>.
7// It tests path-sensitivity with respect to '!(cfstring != 0)' (negation of inequality).
8
9int printf(const char *restrict,...);
10typedef unsigned long UInt32;
11typedef signed long SInt32;
12typedef SInt32 OSStatus;
13typedef unsigned char Boolean;
14enum { noErr = 0};
15typedef const void *CFTypeRef;
16typedef const struct __CFString *CFStringRef;
17typedef const struct __CFAllocator *CFAllocatorRef;
18extern void CFRelease(CFTypeRef cf);
19typedef UInt32 CFStringEncoding;
20enum { kCFStringEncodingMacRoman = 0, kCFStringEncodingWindowsLatin1 = 0x0500,
21 kCFStringEncodingISOLatin1 = 0x0201, kCFStringEncodingNextStepLatin = 0x0B01,
22 kCFStringEncodingASCII = 0x0600, kCFStringEncodingUnicode = 0x0100,
23 kCFStringEncodingUTF8 = 0x08000100, kCFStringEncodingNonLossyASCII = 0x0BFF,
24 kCFStringEncodingUTF16 = 0x0100, kCFStringEncodingUTF16BE = 0x10000100,
25 kCFStringEncodingUTF16LE = 0x14000100, kCFStringEncodingUTF32 = 0x0c000100,
26 kCFStringEncodingUTF32BE = 0x18000100, kCFStringEncodingUTF32LE = 0x1c000100};
27extern CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding);
28
29enum { memROZWarn = -99, memROZError = -99, memROZErr = -99, memFullErr = -108,
30 nilHandleErr = -109, memWZErr = -111, memPurErr = -112, memAdrErr = -110,
31 memAZErr = -113, memPCErr = -114, memBCErr = -115, memSCErr = -116, memLockedErr = -117};
32
33#define DEBUG1
34
35void DebugStop(const char *format,...);
36void DebugTraceIf(unsigned int condition, const char *format,...);
37Boolean DebugDisplayOSStatusMsg(OSStatus status, const char *statusStr, const char *fileName, unsigned long lineNumber);
38
39#define Assert(condition)if (!(condition)) { DebugStop("Assertion failure: %s [File: %s, Line: %lu]", #condition, __FILE__, __LINE__); }
40#define AssertMsg(condition, message)if (!(condition)) { DebugStop("Assertion failure: %s (%s) [File: %s, Line: %lu]", #condition, message, __FILE__, __LINE__); }
41#define Require(condition)if (!(condition)) { DebugStop("Assertion failure: %s [File: %s, Line: %lu]", #condition, __FILE__, __LINE__); }
42#define RequireAction(condition, action)if (!(condition)) { DebugStop("Assertion failure: %s [File: %s, Line: %lu]", #condition, __FILE__, __LINE__); action }
43#define RequireActionSilent(condition, action)if (!(condition)) { action }
44#define AssertNoErr(err){ DebugDisplayOSStatusMsg((err), #err, __FILE__, __LINE__); }
45#define RequireNoErr(err, action){ if( DebugDisplayOSStatusMsg((err), #err, __FILE__, __LINE__) ) { action }}
46
Mike Stump1eb44332009-09-09 15:08:12 +000047void DebugStop(const char *format,...); /* Not an abort function. */
Ted Kremenekc083b0d2008-07-18 20:48:10 +000048
49int main(int argc, char *argv[]) {
Mike Stump1eb44332009-09-09 15:08:12 +000050 CFStringRef cfString;
51 OSStatus status = noErr;
52 cfString = CFStringCreateWithCString(0, "hello", kCFStringEncodingUTF8);
53 RequireAction(cfString != 0, return memFullErr;) //no - warning
54 printf("cfstring %p\n", cfString);
55 Exit:
56 CFRelease(cfString);
57 return 0;
Ted Kremenekc083b0d2008-07-18 20:48:10 +000058}