From 7662af466edd22a7bb9042c88986be1e90cd0fa9 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 16 Jun 2008 19:35:31 +0000 Subject: [PATCH] Move Analysis-Apple/CFString.c to Analysis (the test case now works on all platforms). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52346 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Analysis-Apple/CFString.c | 30 --------------------- test/Analysis/CFString.c | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 30 deletions(-) delete mode 100644 test/Analysis-Apple/CFString.c create mode 100644 test/Analysis/CFString.c diff --git a/test/Analysis-Apple/CFString.c b/test/Analysis-Apple/CFString.c deleted file mode 100644 index ebd9275e10..0000000000 --- a/test/Analysis-Apple/CFString.c +++ /dev/null @@ -1,30 +0,0 @@ -// RUN: clang -checker-cfref -verify %s - -#include -#include - -void f1() { - - // Create the array. - CFMutableArrayRef A = CFArrayCreateMutable(NULL, 10, &kCFTypeArrayCallBacks); - - // Create a string. - CFStringRef s1 = CFStringCreateWithCString(NULL, "hello world", - kCFStringEncodingUTF8); - - // Add the string to the array. - CFArrayAppendValue(A, s1); - - // Decrement the reference count. - CFRelease(s1); // no-warning - - // Get the string. We don't own it. - s1 = (CFStringRef) CFArrayGetValueAtIndex(A, 0); - - // Release the array. - CFRelease(A); // no-warning - - // Release the string. This is a bug. - CFRelease(s1); // expected-warning{{Incorrect decrement of the reference count}} -} - diff --git a/test/Analysis/CFString.c b/test/Analysis/CFString.c new file mode 100644 index 0000000000..eab6d3bd1e --- /dev/null +++ b/test/Analysis/CFString.c @@ -0,0 +1,49 @@ +// RUN: clang -checker-cfref -verify %s + +//===----------------------------------------------------------------------===// +// The following code is reduced using delta-debugging from +// CoreFoundation.h (Mac OS X). +// +// It includes the basic definitions for the test cases below. +// Not directly including CoreFoundation.h directly makes this test case +// both svelt and portable to non-Mac platforms. +//===----------------------------------------------------------------------===// + +typedef signed long CFIndex; +typedef const struct __CFString * CFStringRef; +typedef struct {} CFArrayCallBacks; +extern const CFArrayCallBacks kCFTypeArrayCallBacks; +typedef const struct __CFArray * CFArrayRef; +typedef struct __CFArray * CFMutableArrayRef; +extern const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx); +enum { kCFStringEncodingMacRoman = 0, kCFStringEncodingWindowsLatin1 = 0x0500, kCFStringEncodingISOLatin1 = 0x0201, kCFStringEncodingNextStepLatin = 0x0B01, kCFStringEncodingASCII = 0x0600, kCFStringEncodingUnicode = 0x0100, kCFStringEncodingUTF8 = 0x08000100, kCFStringEncodingNonLossyASCII = 0x0BFF , kCFStringEncodingUTF16 = 0x0100, kCFStringEncodingUTF16BE = 0x10000100, kCFStringEncodingUTF16LE = 0x14000100, kCFStringEncodingUTF32 = 0x0c000100, kCFStringEncodingUTF32BE = 0x18000100, kCFStringEncodingUTF32LE = 0x1c000100 }; + +//===----------------------------------------------------------------------===// +// Test cases. +//===----------------------------------------------------------------------===// + +void f1() { + + // Create the array. + CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + + // Create a string. + CFStringRef s1 = CFStringCreateWithCString(0, "hello world", + kCFStringEncodingUTF8); + + // Add the string to the array. + CFArrayAppendValue(A, s1); + + // Decrement the reference count. + CFRelease(s1); // no-warning + + // Get the string. We don't own it. + s1 = (CFStringRef) CFArrayGetValueAtIndex(A, 0); + + // Release the array. + CFRelease(A); // no-warning + + // Release the string. This is a bug. + CFRelease(s1); // expected-warning{{Incorrect decrement of the reference count}} +} + -- 2.40.0