From 8a1288860be794630912213d82a4efd6fb29ff6c Mon Sep 17 00:00:00 2001 From: Dulma Rodriguez Date: Mon, 18 Apr 2016 03:56:33 -0700 Subject: [PATCH] Make alloc save a given procanem in the path Reviewed By: ddino Differential Revision: D3184313 fb-gh-sync-id: 53624c4 fbshipit-source-id: 53624c4 --- .../objc/src/CoreFoundation/CFBitVector.c | 20 ------ infer/models/objc/src/CoreFoundation/CFDate.c | 18 ----- .../objc/src/CoreFoundation/CFDictionary.c | 23 ------- .../models/objc/src/CoreFoundation/CFLocale.c | 5 -- .../CFMutableAttributedString.c | 18 ----- .../src/CoreFoundation/CFMutableDictionary.c | 7 -- .../objc/src/CoreFoundation/CFMutableSet.c | 7 -- .../objc/src/CoreFoundation/CFPreferences.c | 21 ------ .../objc/src/CoreFoundation/CFRunLoop.c | 27 -------- .../src/CoreFoundation/CFRunLoopObserver.c | 34 --------- .../src/CoreFoundation/CFStringTokenizer.c | 22 ------ infer/models/objc/src/CoreFoundation/CFUUID.c | 24 ------- .../CoreFoundation/SCNetworkReachability.c | 25 ------- infer/models/objc/src/CoreFoundation/SecKey.c | 10 --- infer/models/objc/src/CoreGraphics/CGColor.c | 10 --- .../objc/src/CoreGraphics/CGDataProvider.c | 25 ------- .../models/objc/src/CoreGraphics/CGGradient.c | 15 ---- infer/models/objc/src/CoreGraphics/CGImage.c | 55 --------------- .../src/CoreGraphics/CGImageDestination.c | 31 --------- .../objc/src/CoreGraphics/CGImageSource.c | 16 ----- infer/models/objc/src/CoreGraphics/CGPath.c | 35 ---------- infer/src/backend/modelBuiltins.ml | 69 +++++++++++-------- infer/src/clang/cTrans.ml | 2 +- infer/src/clang/cTrans_utils.ml | 22 +++--- infer/src/clang/cTrans_utils.mli | 3 +- .../MemoryLeakExample.dot | 12 ++-- .../objc/frontend/boxing/dict_literal.dot | 2 +- 27 files changed, 62 insertions(+), 496 deletions(-) delete mode 100644 infer/models/objc/src/CoreFoundation/CFBitVector.c delete mode 100644 infer/models/objc/src/CoreFoundation/CFDate.c delete mode 100644 infer/models/objc/src/CoreFoundation/CFMutableAttributedString.c delete mode 100644 infer/models/objc/src/CoreFoundation/CFPreferences.c delete mode 100644 infer/models/objc/src/CoreFoundation/CFRunLoop.c delete mode 100644 infer/models/objc/src/CoreFoundation/CFRunLoopObserver.c delete mode 100644 infer/models/objc/src/CoreFoundation/CFStringTokenizer.c delete mode 100644 infer/models/objc/src/CoreFoundation/CFUUID.c delete mode 100644 infer/models/objc/src/CoreFoundation/SCNetworkReachability.c delete mode 100644 infer/models/objc/src/CoreGraphics/CGImageDestination.c diff --git a/infer/models/objc/src/CoreFoundation/CFBitVector.c b/infer/models/objc/src/CoreFoundation/CFBitVector.c deleted file mode 100644 index 267e96aed..000000000 --- a/infer/models/objc/src/CoreFoundation/CFBitVector.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import - -CFBitVectorRef __cf_alloc(CFBitVectorRef); -CFBitVectorRef __cf_non_null_alloc(CFBitVectorRef); - -CFBitVectorRef CFBitVectorCreate(CFAllocatorRef allocator, - const UInt8* bytes, - CFIndex numBits) { - CFBitVectorRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/CFDate.c b/infer/models/objc/src/CoreFoundation/CFDate.c deleted file mode 100644 index a780c3682..000000000 --- a/infer/models/objc/src/CoreFoundation/CFDate.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import - -CFDateRef __cf_alloc(CFDateRef); -CFDateRef __cf_non_null_alloc(CFDateRef); - -CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at) { - CFDateRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/CFDictionary.c b/infer/models/objc/src/CoreFoundation/CFDictionary.c index f08267e6f..4e3f3102f 100644 --- a/infer/models/objc/src/CoreFoundation/CFDictionary.c +++ b/infer/models/objc/src/CoreFoundation/CFDictionary.c @@ -15,13 +15,6 @@ CFDictionaryRef __cf_non_null_alloc(CFDictionaryRef); CFDictionaryRef __cf_alloc(CFDictionaryRef); -CFDictionaryRef CGImageSourceCopyPropertiesAtIndex(CGImageSourceRef isrc, - size_t index, - CFDictionaryRef options) { - CFDictionaryRef c; - return __cf_non_null_alloc(c); -} - CFDictionaryRef CFDictionaryCreate( CFAllocatorRef allocator, const void** keys, @@ -39,17 +32,6 @@ CFDictionaryRef CFDictionaryCreateCopy(CFAllocatorRef allocator, return __cf_alloc(c); } -CFDictionaryRef CFNetworkCopySystemProxySettings(void) { - CFDictionaryRef c; - return __cf_non_null_alloc(c); -} - -CFDictionaryRef CGImageSourceCopyProperties(CGImageSourceRef isrc, - CFDictionaryRef options) { - CFDictionaryRef c; - return __cf_non_null_alloc(c); -} - CFDictionaryRef CMCopyDictionaryOfAttachments(CFAllocatorRef allocator, CMAttachmentBearerRef target, CMAttachmentMode attachmentMode) { @@ -62,11 +44,6 @@ CFDictionaryRef CFHTTPMessageCopyAllHeaderFields(CFHTTPMessageRef message) { return __cf_alloc(c); } -CFDictionaryRef CNCopyCurrentNetworkInfo(CFStringRef interfaceName) { - CFDictionaryRef c; - return __cf_non_null_alloc(c); -} - CFDictionaryRef CMTimeCopyAsDictionary(CMTime time, CFAllocatorRef allocator) { CFDictionaryRef c; return __cf_alloc(c); diff --git a/infer/models/objc/src/CoreFoundation/CFLocale.c b/infer/models/objc/src/CoreFoundation/CFLocale.c index 1ccabd5c5..b14637113 100644 --- a/infer/models/objc/src/CoreFoundation/CFLocale.c +++ b/infer/models/objc/src/CoreFoundation/CFLocale.c @@ -12,11 +12,6 @@ CFLocaleRef __cf_alloc(CFLocaleRef); CFLocaleRef __cf_non_null_alloc(CFLocaleRef); -CFLocaleRef CFLocaleCopyCurrent(void) { - CFLocaleRef c; - return __cf_non_null_alloc(c); -} - CFLocaleRef CFLocaleCreate(CFAllocatorRef allocator, CFStringRef localeIdentifier) { CFLocaleRef c; diff --git a/infer/models/objc/src/CoreFoundation/CFMutableAttributedString.c b/infer/models/objc/src/CoreFoundation/CFMutableAttributedString.c deleted file mode 100644 index 7dfd681ab..000000000 --- a/infer/models/objc/src/CoreFoundation/CFMutableAttributedString.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import - -CFMutableAttributedStringRef __cf_non_null_alloc(CFMutableAttributedStringRef); - -CFMutableAttributedStringRef CFAttributedStringCreateMutable( - CFAllocatorRef alloc, CFIndex maxLength) { - CFMutableAttributedStringRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/CFMutableDictionary.c b/infer/models/objc/src/CoreFoundation/CFMutableDictionary.c index d2bc98f11..cb1007ea8 100644 --- a/infer/models/objc/src/CoreFoundation/CFMutableDictionary.c +++ b/infer/models/objc/src/CoreFoundation/CFMutableDictionary.c @@ -23,10 +23,3 @@ CFMutableDictionaryRef CFDictionaryCreateMutable( CFMutableDictionaryRef c; return __cf_alloc(c); } - -CFMutableDictionaryRef CFDictionaryCreateMutableCopy(CFAllocatorRef allocator, - CFIndex capacity, - CFDictionaryRef theDict) { - CFMutableDictionaryRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/CFMutableSet.c b/infer/models/objc/src/CoreFoundation/CFMutableSet.c index af046031b..2ec41e83b 100644 --- a/infer/models/objc/src/CoreFoundation/CFMutableSet.c +++ b/infer/models/objc/src/CoreFoundation/CFMutableSet.c @@ -18,10 +18,3 @@ CFMutableSetRef CFSetCreateMutable(CFAllocatorRef allocator, CFMutableSetRef c; return __cf_alloc(c); } - -CFMutableSetRef CFSetCreateMutableCopy(CFAllocatorRef allocator, - CFIndex capacity, - CFSetRef theSet) { - CFMutableSetRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/CFPreferences.c b/infer/models/objc/src/CoreFoundation/CFPreferences.c deleted file mode 100644 index bfd203d9e..000000000 --- a/infer/models/objc/src/CoreFoundation/CFPreferences.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import - -CFDictionaryRef __cf_alloc(CFDictionaryRef); -CFDictionaryRef __cf_non_null_alloc(CFDictionaryRef); - -CFDictionaryRef CFPreferencesCopyMultiple(CFArrayRef keysToFetch, - CFStringRef appName, - CFStringRef user, - CFStringRef host) { - CFDictionaryRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/CFRunLoop.c b/infer/models/objc/src/CoreFoundation/CFRunLoop.c deleted file mode 100644 index 7b5f03610..000000000 --- a/infer/models/objc/src/CoreFoundation/CFRunLoop.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import - -CFRunLoopSourceRef __cf_alloc(CFRunLoopSourceRef); -CFRunLoopSourceRef __cf_non_null_alloc(CFRunLoopSourceRef); - -CFRunLoopSourceRef CFRunLoopSourceCreate(CFAllocatorRef allocator, - CFIndex order, - CFRunLoopSourceContext* context) { - CFRunLoopSourceRef c; - return __cf_non_null_alloc(c); -} - -CFRunLoopSourceRef CFSocketCreateRunLoopSource(CFAllocatorRef allocator, - CFSocketRef s, - CFIndex order) { - CFRunLoopSourceRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/CFRunLoopObserver.c b/infer/models/objc/src/CoreFoundation/CFRunLoopObserver.c deleted file mode 100644 index 132207d12..000000000 --- a/infer/models/objc/src/CoreFoundation/CFRunLoopObserver.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import - -CFRunLoopObserverRef __cf_alloc(CFRunLoopObserverRef); -CFRunLoopSourceRef __cf_non_null_alloc(CFRunLoopSourceRef); - -CFRunLoopObserverRef CFRunLoopObserverCreate( - CFAllocatorRef allocator, - CFOptionFlags activities, - Boolean repeats, - CFIndex order, - CFRunLoopObserverCallBack callout, - CFRunLoopObserverContext* context) { - CFRunLoopObserverRef c; - return __cf_non_null_alloc(c); -} - -CFRunLoopObserverRef CFRunLoopObserverCreateWithHandler( - CFAllocatorRef allocator, - CFOptionFlags activities, - Boolean repeats, - CFIndex order, - void (^block)(CFRunLoopObserverRef observer, CFRunLoopActivity activity)) { - CFRunLoopObserverRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/CFStringTokenizer.c b/infer/models/objc/src/CoreFoundation/CFStringTokenizer.c deleted file mode 100644 index 7309fd241..000000000 --- a/infer/models/objc/src/CoreFoundation/CFStringTokenizer.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import - -CFStringTokenizerRef __cf_alloc(CFStringTokenizerRef); -CFStringTokenizerRef __cf_non_null_alloc(CFStringTokenizerRef); - -CFStringTokenizerRef CFStringTokenizerCreate(CFAllocatorRef alloc, - CFStringRef string, - CFRange range, - CFOptionFlags options, - CFLocaleRef locale) { - CFStringTokenizerRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/CFUUID.c b/infer/models/objc/src/CoreFoundation/CFUUID.c deleted file mode 100644 index c88573879..000000000 --- a/infer/models/objc/src/CoreFoundation/CFUUID.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import - -CFUUIDRef __cf_alloc(CFUUIDRef); -CFUUIDRef __cf_non_null_alloc(CFUUIDRef); - -CFUUIDRef CFUUIDCreate(CFAllocatorRef alloc) { - CFUUIDRef c; - return __cf_non_null_alloc(c); -} - -CFUUIDRef CFUUIDCreateFromUUIDBytes(CFAllocatorRef alloc, CFUUIDBytes bytes) { - - CFUUIDRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/SCNetworkReachability.c b/infer/models/objc/src/CoreFoundation/SCNetworkReachability.c deleted file mode 100644 index 5afd462c7..000000000 --- a/infer/models/objc/src/CoreFoundation/SCNetworkReachability.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import "SystemConfiguration/SCNetworkReachability.h" -#import - -SCNetworkReachabilityRef __cf_non_null_alloc(SCNetworkReachabilityRef); - -SCNetworkReachabilityRef SCNetworkReachabilityCreateWithName( - CFAllocatorRef allocator, const char* nodename) { - SCNetworkReachabilityRef c; - return __cf_non_null_alloc(c); -} - -SCNetworkReachabilityRef SCNetworkReachabilityCreateWithAddress( - CFAllocatorRef allocator, const struct sockaddr* address) { - SCNetworkReachabilityRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreFoundation/SecKey.c b/infer/models/objc/src/CoreFoundation/SecKey.c index 670f45a5c..3bac2587e 100644 --- a/infer/models/objc/src/CoreFoundation/SecKey.c +++ b/infer/models/objc/src/CoreFoundation/SecKey.c @@ -18,13 +18,3 @@ SecKeyRef SecTrustCopyPublicKey(SecTrustRef trust) { SecKeyRef c; return __cf_alloc(c); } - -SecPolicyRef SecPolicyCreateSSL(Boolean server, CFStringRef hostname) { - SecPolicyRef c; - return __cf_non_null_alloc(c); -} - -SecPolicyRef SecPolicyCreateBasicX509(void) { - SecPolicyRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreGraphics/CGColor.c b/infer/models/objc/src/CoreGraphics/CGColor.c index fba9301a2..736d0f9ac 100644 --- a/infer/models/objc/src/CoreGraphics/CGColor.c +++ b/infer/models/objc/src/CoreGraphics/CGColor.c @@ -18,16 +18,6 @@ void CGColorRelease(CGColorRef color) { __objc_release_cf(color); } -CGColorRef CGColorCreate(CGColorSpaceRef space, const CGFloat components[]) { - CGColorRef c; - return __cf_non_null_alloc(c); -} - -CGColorRef CGColorCreateCopyWithAlpha(CGColorRef color, CGFloat alpha) { - CGColorRef c; - return __cf_non_null_alloc(c); -} - // FB own code CGColorRef FBColorCreateWithGray(CGFloat gray, CGFloat a) { diff --git a/infer/models/objc/src/CoreGraphics/CGDataProvider.c b/infer/models/objc/src/CoreGraphics/CGDataProvider.c index 6ab5cb3ee..358116a47 100644 --- a/infer/models/objc/src/CoreGraphics/CGDataProvider.c +++ b/infer/models/objc/src/CoreGraphics/CGDataProvider.c @@ -20,33 +20,8 @@ CGDataProviderRef __cf_alloc(CGDataProviderRef); CGDataProviderRef __cf_non_null_alloc(CGDataProviderRef); -CGDataProviderRef CGDataProviderCreateWithCFData(CFDataRef data) { - CGDataProviderRef c; - return __cf_non_null_alloc(c); -} - -CGDataProviderRef CGDataProviderCreateWithData( - void* info, - const void* data, - size_t size, - CGDataProviderReleaseDataCallback releaseData) { - CGDataProviderRef c; - return __cf_non_null_alloc(c); -} - CGDataProviderRef CGDataProviderCreateWithURL(CFURLRef url) { CGDataProviderRef c; return __cf_alloc(c); } -CGDataProviderRef CGDataProviderCreateDirect( - void* info, off_t size, const CGDataProviderDirectCallbacks* callbacks) { - CGDataProviderRef c; - return __cf_non_null_alloc(c); -} - -CGDataProviderRef CGDataProviderCreateSequential( - void* info, const CGDataProviderSequentialCallbacks* callbacks) { - CGDataProviderRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreGraphics/CGGradient.c b/infer/models/objc/src/CoreGraphics/CGGradient.c index 0847aa25f..5e33037e5 100644 --- a/infer/models/objc/src/CoreGraphics/CGGradient.c +++ b/infer/models/objc/src/CoreGraphics/CGGradient.c @@ -17,18 +17,3 @@ void CGGradientRelease(CGGradientRef gradient) { } CGGradientRef __cf_non_null_alloc(CGGradientRef); - -CGGradientRef CGGradientCreateWithColors(CGColorSpaceRef space, - CFArrayRef colors, - const CGFloat locations[]) { - CGGradientRef c; - return __cf_non_null_alloc(c); -} - -CGGradientRef CGGradientCreateWithColorComponents(CGColorSpaceRef space, - const CGFloat components[], - const CGFloat locations[], - size_t count) { - CGGradientRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreGraphics/CGImage.c b/infer/models/objc/src/CoreGraphics/CGImage.c index a9cbaf026..14cfd5f67 100644 --- a/infer/models/objc/src/CoreGraphics/CGImage.c +++ b/infer/models/objc/src/CoreGraphics/CGImage.c @@ -14,20 +14,6 @@ CGImageRef __cf_non_null_alloc(CGImageRef); CGImageRef __cf_alloc(CGImageRef); void __objc_release_cf(CGImageRef); -CGImageRef CGImageSourceCreateImageAtIndex(CGImageSourceRef isrc, - size_t index, - CFDictionaryRef options) { - CGImageRef c; - return __cf_non_null_alloc(c); -} - -CGImageRef CGImageSourceCreateThumbnailAtIndex(CGImageSourceRef isrc, - size_t index, - CFDictionaryRef options) { - CGImageRef c; - return __cf_non_null_alloc(c); -} - void CGImageRelease(CGImageRef image) { if (image) __objc_release_cf(image); @@ -38,48 +24,7 @@ CGImageRef CGBitmapContextCreateImage(CGContextRef context) { return __cf_alloc(c); } -CGImageRef CGImageCreateCopy(CGImageRef image) { - CGImageRef c; - return __cf_non_null_alloc(c); -} - CGImageRef CGImageCreateWithImageInRect(CGImageRef image, CGRect rect) { CGImageRef c; return __cf_alloc(c); } - -CGImageRef CGImageCreateWithJPEGDataProvider(CGDataProviderRef source, - const CGFloat decode[], - bool shouldInterpolate, - CGColorRenderingIntent intent) { - CGImageRef c; - return __cf_non_null_alloc(c); -} - -CGImageRef CGImageCreateWithPNGDataProvider(CGDataProviderRef source, - const CGFloat decode[], - bool shouldInterpolate, - CGColorRenderingIntent intent) { - CGImageRef c; - return __cf_non_null_alloc(c); -} - -CGImageRef CGImageCreate(size_t width, - size_t height, - size_t bitsPerComponent, - size_t bitsPerPixel, - size_t bytesPerRow, - CGColorSpaceRef space, - CGBitmapInfo bitmapInfo, - CGDataProviderRef provider, - const CGFloat decode[], - bool shouldInterpolate, - CGColorRenderingIntent intent) { - CGImageRef c; - return __cf_non_null_alloc(c); -} - -CGImageRef CGImageCreateWithMask(CGImageRef image, CGImageRef mask) { - CGImageRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreGraphics/CGImageDestination.c b/infer/models/objc/src/CoreGraphics/CGImageDestination.c deleted file mode 100644 index b9feed705..000000000 --- a/infer/models/objc/src/CoreGraphics/CGImageDestination.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2015 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import -#import - -CGImageDestinationRef __cf_non_null_alloc(CGImageDestinationRef); -CGImageDestinationRef __cf_alloc(CGImageDestinationRef); - -CGImageDestinationRef CGImageDestinationCreateWithURL(CFURLRef url, - CFStringRef type, - size_t count, - CFDictionaryRef options) { - CGImageDestinationRef c; - return __cf_non_null_alloc(c); -} - -CGImageDestinationRef CGImageDestinationCreateWithData( - CFMutableDataRef data, - CFStringRef type, - size_t count, - CFDictionaryRef options) { - CGImageDestinationRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/models/objc/src/CoreGraphics/CGImageSource.c b/infer/models/objc/src/CoreGraphics/CGImageSource.c index 15402b384..2eb729b5b 100644 --- a/infer/models/objc/src/CoreGraphics/CGImageSource.c +++ b/infer/models/objc/src/CoreGraphics/CGImageSource.c @@ -14,28 +14,12 @@ CGImageSourceRef __cf_non_null_alloc(CGImageSourceRef); CGImageSourceRef __cf_alloc(CGImageSourceRef); void __objc_release_cf(CGImageSourceRef); -CGImageSourceRef CGImageSourceCreateWithData(CFDataRef data, - CFDictionaryRef options) { - CGImageSourceRef c; - return __cf_non_null_alloc(c); -} - -CGImageSourceRef CGImageSourceCreateWithDataProvider(CGDataProviderRef provider, - CFDictionaryRef options) { - CGImageSourceRef c; - return __cf_non_null_alloc(c); -} - CGImageSourceRef CGImageSourceCreateWithURL(CFURLRef url, CFDictionaryRef options) { CGImageSourceRef c; return __cf_alloc(c); } -CGImageSourceRef CGImageSourceCreateIncremental(CFDictionaryRef options) { - CGImageSourceRef c; - return __cf_non_null_alloc(c); -} void CGImageSourceRelease(CGImageSourceRef image) { if (image) diff --git a/infer/models/objc/src/CoreGraphics/CGPath.c b/infer/models/objc/src/CoreGraphics/CGPath.c index 74eec17ea..8e516c9ce 100644 --- a/infer/models/objc/src/CoreGraphics/CGPath.c +++ b/infer/models/objc/src/CoreGraphics/CGPath.c @@ -13,43 +13,8 @@ CGPathRef __cf_non_null_alloc(CGPathRef); void __objc_release_cf(CGPathRef); -CGMutablePathRef CGPathCreateMutable() { - CGMutablePathRef c; - return (CGMutablePathRef)__cf_non_null_alloc(c); -} - -CGPathRef CGPathCreateWithRect(CGRect rect, - const CGAffineTransform* transform) { - CGPathRef c; - return __cf_non_null_alloc(c); -} - void CGPathRelease(CGPathRef path) { if (path) __objc_release_cf(path); } -CGPathRef CGPathCreateWithEllipseInRect(CGRect rect, - const CGAffineTransform* transform) { - CGPathRef c; - return __cf_non_null_alloc(c); -} - -CGPathRef CGPathCreateCopy(CGPathRef path) { - CGPathRef c; - return __cf_non_null_alloc(c); -} - -CGPathRef CGPathCreateCopyByTransformingPath( - CGPathRef path, const CGAffineTransform* transform) { - CGPathRef c; - return __cf_non_null_alloc(c); -} - -CGPathRef CGPathCreateWithRoundedRect(CGRect rect, - CGFloat cornerWidth, - CGFloat cornerHeight, - const CGAffineTransform* transform) { - CGPathRef c; - return __cf_non_null_alloc(c); -} diff --git a/infer/src/backend/modelBuiltins.ml b/infer/src/backend/modelBuiltins.ml index b975802cd..1791ad404 100644 --- a/infer/src/backend/modelBuiltins.ml +++ b/infer/src/backend/modelBuiltins.ml @@ -748,11 +748,11 @@ let execute_alloc mk can_return_null | Sil.Sizeof _ -> e in let handle_sizeof_exp size_exp = Sil.Sizeof (Sil.Tarray (Sil.Tint Sil.IChar, size_exp), Sil.Subtype.exact) in - let size_exp = match args with + let size_exp, procname = match args with | [(size_exp, _)] -> (* for malloc and __new *) - size_exp - | [(num_obj, _); (base_exp, _)] -> (* for __new_array *) - Sil.BinOp (Sil.Mult, num_obj, base_exp) + size_exp, Sil.mem_alloc_pname mk + | [(size_exp, _); (Sil.Const (Sil.Cfun pname), _)] -> + size_exp, pname | _ -> raise (Exceptions.Wrong_argument_number __POS__) in let ret_id = match ret_ids with @@ -768,12 +768,11 @@ let execute_alloc mk can_return_null let ptsto_new = Prop.mk_ptsto_exp (Some tenv) Prop.Fld_init (exp_new, cnt_te, None) Sil.Ialloc in let prop_plus_ptsto = - let pname = Sil.mem_alloc_pname mk in let prop' = Prop.normalize (Prop.prop_sigma_star prop [ptsto_new]) in let ra = { Sil.ra_kind = Sil.Racquire; Sil.ra_res = Sil.Rmemory mk; - Sil.ra_pname = pname; + Sil.ra_pname = procname; Sil.ra_loc = loc; Sil.ra_vpath = None } in (* mark value as allocated *) @@ -1123,62 +1122,72 @@ let _ = Builtin.register "wscanf" (execute_scan_function 1) let execute_objc_alloc_no_fail - symb_state typ + symb_state typ alloc_fun_opt { Builtin.pdesc; tenv; ret_ids; loc; } = let alloc_fun = Sil.Const (Sil.Cfun __objc_alloc_no_fail) in let ptr_typ = Sil.Tptr (typ, Sil.Pk_pointer) in let sizeof_typ = Sil.Sizeof (typ, Sil.Subtype.exact) in - let alloc_instr = Sil.Call (ret_ids, alloc_fun, [sizeof_typ, ptr_typ], loc, Sil.cf_default) in + let alloc_fun_exp = + match alloc_fun_opt with + | Some pname -> [Sil.Const (Sil.Cfun pname), Sil.Tvoid] + | None -> [] in + let alloc_instr = + Sil.Call (ret_ids, alloc_fun, [(sizeof_typ, ptr_typ)] @ alloc_fun_exp, loc, Sil.cf_default) in SymExec.instrs tenv pdesc [alloc_instr] symb_state +let mk_objc_class_method class_name method_name = + let method_kind = Procname.mangled_of_objc_method_kind Procname.Class_objc_method in + (Procname.ObjC_Cpp + (Procname.objc_cpp class_name method_name method_kind)) + +(* NSArray models *) + +let arrayWithObjects_pname = mk_objc_class_method "NSArray" "arrayWithObjects:" + +let arrayWithObjectsCount_pname = mk_objc_class_method "NSArray" "arrayWithObjects:count:" + let execute_objc_NSArray_alloc_no_fail - ({ Builtin.tenv; } as builtin_args) symb_state = + ({ Builtin.tenv; } as builtin_args) symb_state pname = let nsarray_typ_ = Sil.Tvar (Typename.TN_csu (Csu.Class Csu.Objc, Mangled.from_string "NSArray")) in let nsarray_typ = Tenv.expand_type tenv nsarray_typ_ in - execute_objc_alloc_no_fail symb_state nsarray_typ builtin_args + execute_objc_alloc_no_fail symb_state nsarray_typ (Some pname) builtin_args let execute_NSArray_arrayWithObjects_count builtin_args = let n_formals = 1 in let res = SymExec.check_variadic_sentinel ~fails_on_nil: true n_formals (0,1) builtin_args in - execute_objc_NSArray_alloc_no_fail builtin_args res + execute_objc_NSArray_alloc_no_fail builtin_args res arrayWithObjectsCount_pname let execute_NSArray_arrayWithObjects builtin_args = let n_formals = 1 in let res = SymExec.check_variadic_sentinel n_formals (0,1) builtin_args in - execute_objc_NSArray_alloc_no_fail builtin_args res + execute_objc_NSArray_alloc_no_fail builtin_args res arrayWithObjects_pname let _ = - let method_kind = Procname.mangled_of_objc_method_kind Procname.Class_objc_method in - Builtin.register_procname - (Procname.ObjC_Cpp - (Procname.objc_cpp "NSArray" "arrayWithObjects:count:" method_kind)) - execute_NSArray_arrayWithObjects_count -let _ = - let method_kind = Procname.mangled_of_objc_method_kind Procname.Class_objc_method in - Builtin.register_procname - (Procname.ObjC_Cpp - (Procname.objc_cpp "NSArray" "arrayWithObjects:" method_kind)) - execute_NSArray_arrayWithObjects + Builtin.register_procname arrayWithObjectsCount_pname execute_NSArray_arrayWithObjects_count; + Builtin.register_procname arrayWithObjects_pname execute_NSArray_arrayWithObjects + +(* NSDictionary models *) let execute_objc_NSDictionary_alloc_no_fail - symb_state + symb_state pname ({ Builtin.tenv; } as builtin_args) = let nsdictionary_typ_ = Sil.Tvar (Typename.TN_csu (Csu.Class Csu.Objc, Mangled.from_string "NSDictionary")) in let nsdictionary_typ = Tenv.expand_type tenv nsdictionary_typ_ in - execute_objc_alloc_no_fail symb_state nsdictionary_typ builtin_args + execute_objc_alloc_no_fail symb_state nsdictionary_typ (Some pname) builtin_args + +let __objc_dictionary_literal_pname = + mk_objc_class_method "NSDictionary" "dictionaryWithObjects:forKeys:count:" let execute___objc_dictionary_literal builtin_args = let n_formals = 1 in let res' = SymExec.check_variadic_sentinel ~fails_on_nil: true n_formals (0,1) builtin_args in - execute_objc_NSDictionary_alloc_no_fail res' builtin_args + let pname = __objc_dictionary_literal_pname in + execute_objc_NSDictionary_alloc_no_fail res' pname builtin_args let __objc_dictionary_literal = - let method_kind = Procname.mangled_of_objc_method_kind Procname.Class_objc_method in - let pname = - Procname.ObjC_Cpp - (Procname.objc_cpp "NSDictionary" "__objc_dictionary_literal:" method_kind) in + let pname = __objc_dictionary_literal_pname in Builtin.register_procname pname execute___objc_dictionary_literal; pname diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 544b3e2dc..57ba51b42 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -139,7 +139,7 @@ struct Tenv.add tenv block_name block_struct_typ; let trans_res = CTrans_utils.alloc_trans - trans_state loc (Ast_expressions.dummy_stmt_info ()) block_type true in + trans_state loc (Ast_expressions.dummy_stmt_info ()) block_type true None in let id_block = match trans_res.exps with | [(Sil.Var id, _)] -> id | _ -> assert false in diff --git a/infer/src/clang/cTrans_utils.ml b/infer/src/clang/cTrans_utils.ml index a01011ba9..b456b6c17 100644 --- a/infer/src/clang/cTrans_utils.ml +++ b/infer/src/clang/cTrans_utils.ml @@ -291,7 +291,7 @@ struct end (** This function handles ObjC new/alloc and C++ new calls *) -let create_alloc_instrs context sil_loc function_type fname size_exp_opt = +let create_alloc_instrs context sil_loc function_type fname size_exp_opt procname_opt = let function_type, function_type_np = match function_type with | Sil.Tptr (styp, Sil.Pk_pointer) @@ -306,17 +306,21 @@ let create_alloc_instrs context sil_loc function_type fname size_exp_opt = | Some exp -> Sil.BinOp (Sil.Mult, sizeof_exp_, exp) | None -> sizeof_exp_ in let exp = (sizeof_exp, Sil.Tint Sil.IULong) in + let procname_arg = match procname_opt with + | Some procname -> [Sil.Const (Sil.Cfun (procname)), Sil.Tvoid] + | None -> [] in + let args = exp :: procname_arg in let ret_id = Ident.create_fresh Ident.knormal in - let stmt_call = Sil.Call([ret_id], (Sil.Const (Sil.Cfun fname)), [exp], sil_loc, Sil.cf_default) in + let stmt_call = Sil.Call([ret_id], (Sil.Const (Sil.Cfun fname)), args, sil_loc, Sil.cf_default) in (function_type, ret_id, stmt_call, Sil.Var ret_id) -let alloc_trans trans_state loc stmt_info function_type is_cf_non_null_alloc = +let alloc_trans trans_state loc stmt_info function_type is_cf_non_null_alloc procname_opt = let fname = if is_cf_non_null_alloc then ModelBuiltins.__objc_alloc_no_fail else ModelBuiltins.__objc_alloc in let (function_type, ret_id, stmt_call, exp) = - create_alloc_instrs trans_state.context loc function_type fname None in + create_alloc_instrs trans_state.context loc function_type fname None procname_opt in let res_trans_tmp = { empty_res_trans with ids =[ret_id]; instrs =[stmt_call]} in let res_trans = let nname = "Call alloc" in @@ -326,7 +330,7 @@ let alloc_trans trans_state loc stmt_info function_type is_cf_non_null_alloc = let objc_new_trans trans_state loc stmt_info cls_name function_type = let fname = ModelBuiltins.__objc_alloc_no_fail in let (alloc_ret_type, alloc_ret_id, alloc_stmt_call, _) = - create_alloc_instrs trans_state.context loc function_type fname None in + create_alloc_instrs trans_state.context loc function_type fname None None in let init_ret_id = Ident.create_fresh Ident.knormal in let is_instance = true in let call_flags = { Sil.cf_default with Sil.cf_virtual = is_instance; } in @@ -350,7 +354,7 @@ let new_or_alloc_trans trans_state loc stmt_info type_ptr class_name_opt selecto | Some class_name -> class_name | None -> CTypes.classname_of_type function_type in if selector = CFrontend_config.alloc then - alloc_trans trans_state loc stmt_info function_type true + alloc_trans trans_state loc stmt_info function_type true None else if selector = CFrontend_config.new_str then objc_new_trans trans_state loc stmt_info class_name function_type else assert false @@ -361,7 +365,7 @@ let cpp_new_trans trans_state sil_loc function_type size_exp_opt = | Some _ -> ModelBuiltins.__new_array | None -> ModelBuiltins.__new in let (function_type, ret_id, stmt_call, exp) = - create_alloc_instrs trans_state.context sil_loc function_type fname size_exp_opt in + create_alloc_instrs trans_state.context sil_loc function_type fname size_exp_opt None in { empty_res_trans with ids = [ret_id]; instrs = [stmt_call]; exps = [(exp, function_type)] } let create_cast_instrs context exp cast_from_typ cast_to_typ sil_loc = @@ -385,9 +389,9 @@ let cast_trans context exps sil_loc callee_pname_opt function_type = let builtin_trans trans_state loc stmt_info function_type callee_pname_opt = if CTrans_models.is_cf_non_null_alloc callee_pname_opt || CTrans_models.is_alloc_model function_type callee_pname_opt then - Some (alloc_trans trans_state loc stmt_info function_type true) + Some (alloc_trans trans_state loc stmt_info function_type true callee_pname_opt) else if CTrans_models.is_alloc callee_pname_opt then - Some (alloc_trans trans_state loc stmt_info function_type false) + Some (alloc_trans trans_state loc stmt_info function_type false None) else None let dereference_var_sil (exp, typ) sil_loc = diff --git a/infer/src/clang/cTrans_utils.mli b/infer/src/clang/cTrans_utils.mli index 05d90ff19..603de29aa 100644 --- a/infer/src/clang/cTrans_utils.mli +++ b/infer/src/clang/cTrans_utils.mli @@ -101,7 +101,8 @@ val builtin_trans : trans_state -> Location.t -> Clang_ast_t.stmt_info -> Sil.typ -> Procname.t option -> trans_result option val alloc_trans : - trans_state -> Location.t -> Clang_ast_t.stmt_info -> Sil.typ -> bool -> trans_result + trans_state -> Location.t -> Clang_ast_t.stmt_info -> Sil.typ -> bool -> + Procname.t option -> trans_result val new_or_alloc_trans : trans_state -> Location.t -> Clang_ast_t.stmt_info -> Clang_ast_t.type_ptr -> string option -> string -> trans_result diff --git a/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/MemoryLeakExample.dot b/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/MemoryLeakExample.dot index 8d10c3fd5..a22d6f3df 100644 --- a/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/MemoryLeakExample.dot +++ b/infer/tests/codetoanalyze/objc/errors/memory_leaks_benchmark/MemoryLeakExample.dot @@ -154,7 +154,7 @@ digraph iCFG { 33 -> 32 ; -32 [label="32: DeclStmt \n n$25=_fun_CGPathCreateMutable() [line 62]\n *&path1:struct CGPath *=n$25 [line 62]\n REMOVE_TEMPS(n$25); [line 62]\n " shape="box"] +32 [label="32: DeclStmt \n n$25=_fun___objc_alloc_no_fail(sizeof(struct CGPath ):unsigned long ,_fun_CGPathCreateMutable:void ) [line 62]\n *&path1:struct CGPath *=n$25 [line 62]\n REMOVE_TEMPS(n$25); [line 62]\n " shape="box"] 32 -> 31 ; @@ -173,7 +173,7 @@ digraph iCFG { 28 -> 27 ; -27 [label="27: Call _fun_CGPathCreateMutable \n n$21=_fun_CGPathCreateMutable() [line 55]\n REMOVE_TEMPS(n$21); [line 55]\n APPLY_ABSTRACTION; [line 55]\n " shape="box"] +27 [label="27: Call alloc \n n$21=_fun___objc_alloc_no_fail(sizeof(struct CGPath ):unsigned long ,_fun_CGPathCreateMutable:void ) [line 55]\n REMOVE_TEMPS(n$21); [line 55]\n APPLY_ABSTRACTION; [line 55]\n " shape="box"] 27 -> 26 ; @@ -210,7 +210,7 @@ digraph iCFG { 18 -> 20 ; -17 [label="17: DeclStmt \n n$16=_fun_CFAttributedStringCreateMutable(0:struct __CFAllocator *,0:long ) [line 40]\n *&maString:struct __CFAttributedString *=n$16 [line 39]\n REMOVE_TEMPS(n$16); [line 39]\n " shape="box"] +17 [label="17: DeclStmt \n n$16=_fun___objc_alloc_no_fail(sizeof(struct __CFAttributedString ):unsigned long ,_fun_CFAttributedStringCreateMutable:void ) [line 40]\n *&maString:struct __CFAttributedString *=n$16 [line 39]\n REMOVE_TEMPS(n$16); [line 39]\n " shape="box"] 17 -> 16 ; @@ -225,7 +225,7 @@ digraph iCFG { 14 -> 17 ; -13 [label="13: Call _fun_CFAttributedStringCreateMutable \n n$14=_fun_CFAttributedStringCreateMutable(0:struct __CFAllocator *,0:long ) [line 35]\n REMOVE_TEMPS(n$14); [line 35]\n APPLY_ABSTRACTION; [line 35]\n " shape="box"] +13 [label="13: Call alloc \n n$14=_fun___objc_alloc_no_fail(sizeof(struct __CFAttributedString ):unsigned long ,_fun_CFAttributedStringCreateMutable:void ) [line 35]\n REMOVE_TEMPS(n$14); [line 35]\n APPLY_ABSTRACTION; [line 35]\n " shape="box"] 13 -> 12 ; @@ -236,7 +236,7 @@ digraph iCFG { 11 -> 13 ; -10 [label="10: DeclStmt \n n$10=*&self:class MemoryLeakExample * [line 30]\n n$11=_fun_MemoryLeakExample_backgroundCoveringView(n$10:class MemoryLeakExample *) [line 30]\n n$12=_fun_UIView_bounds(n$11:class UIView *) [line 30]\n n$13=_fun_CGPathCreateWithRect(n$12:struct CGRect ,0:struct CGAffineTransform *) [line 30]\n *&shadowPath:struct CGPath *=n$13 [line 29]\n REMOVE_TEMPS(n$10,n$11,n$12,n$13); [line 29]\n " shape="box"] +10 [label="10: DeclStmt \n n$13=_fun___objc_alloc_no_fail(sizeof(struct CGPath ):unsigned long ,_fun_CGPathCreateWithRect:void ) [line 30]\n *&shadowPath:struct CGPath *=n$13 [line 29]\n REMOVE_TEMPS(n$13); [line 29]\n " shape="box"] 10 -> 9 ; @@ -255,7 +255,7 @@ digraph iCFG { 6 -> 5 ; -5 [label="5: DeclStmt \n n$2=*&attachmentContainerView:class UIView * [line 22]\n n$3=_fun_UIView_bounds(n$2:class UIView *) [line 22]\n n$4=_fun_CGPathCreateWithRect(n$3:struct CGRect ,0:struct CGAffineTransform *) [line 22]\n *&shadowPath:struct CGPath *=n$4 [line 21]\n REMOVE_TEMPS(n$2,n$3,n$4); [line 21]\n " shape="box"] +5 [label="5: DeclStmt \n n$4=_fun___objc_alloc_no_fail(sizeof(struct CGPath ):unsigned long ,_fun_CGPathCreateWithRect:void ) [line 22]\n *&shadowPath:struct CGPath *=n$4 [line 21]\n REMOVE_TEMPS(n$4); [line 21]\n " shape="box"] 5 -> 4 ; diff --git a/infer/tests/codetoanalyze/objc/frontend/boxing/dict_literal.dot b/infer/tests/codetoanalyze/objc/frontend/boxing/dict_literal.dot index 39b4a2e1f..db6785d29 100644 --- a/infer/tests/codetoanalyze/objc/frontend/boxing/dict_literal.dot +++ b/infer/tests/codetoanalyze/objc/frontend/boxing/dict_literal.dot @@ -1,5 +1,5 @@ digraph iCFG { -6 [label="6: Return Stmt \n n$0=_fun_NSString_stringWithUTF8String:(\"Matt\":char *) [line 25]\n n$1=_fun_NSString_stringWithUTF8String:(\"firstName\":char *) [line 25]\n n$2=_fun_NSString_stringWithUTF8String:(\"Galloway\":char *) [line 25]\n n$3=_fun_NSString_stringWithUTF8String:(\"lastName\":char *) [line 25]\n n$4=_fun_NSNumber_numberWithInt:(28:int ) [line 25]\n n$5=_fun_NSString_stringWithUTF8String:(\"age\":char *) [line 25]\n n$6=_fun_NSDictionary___objc_dictionary_literal:(n$0:struct objc_object *,n$1:struct objc_object *,n$2:struct objc_object *,n$3:struct objc_object *,n$4:struct objc_object *,n$5:struct objc_object *,0:struct objc_object *) [line 25]\n *&return:class NSDictionary *=n$6 [line 25]\n REMOVE_TEMPS(n$0,n$1,n$2,n$3,n$4,n$5,n$6); [line 25]\n APPLY_ABSTRACTION; [line 25]\n " shape="box"] +6 [label="6: Return Stmt \n n$0=_fun_NSString_stringWithUTF8String:(\"Matt\":char *) [line 25]\n n$1=_fun_NSString_stringWithUTF8String:(\"firstName\":char *) [line 25]\n n$2=_fun_NSString_stringWithUTF8String:(\"Galloway\":char *) [line 25]\n n$3=_fun_NSString_stringWithUTF8String:(\"lastName\":char *) [line 25]\n n$4=_fun_NSNumber_numberWithInt:(28:int ) [line 25]\n n$5=_fun_NSString_stringWithUTF8String:(\"age\":char *) [line 25]\n n$6=_fun_NSDictionary_dictionaryWithObjects:forKeys:count:(n$0:struct objc_object *,n$1:struct objc_object *,n$2:struct objc_object *,n$3:struct objc_object *,n$4:struct objc_object *,n$5:struct objc_object *,0:struct objc_object *) [line 25]\n *&return:class NSDictionary *=n$6 [line 25]\n REMOVE_TEMPS(n$0,n$1,n$2,n$3,n$4,n$5,n$6); [line 25]\n APPLY_ABSTRACTION; [line 25]\n " shape="box"] 6 -> 5 ;