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