[cfe-commits] r53993 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis/CFRetainRelease_NSAssertionHandler.m

Ted Kremenek kremenek at apple.com
Thu Jul 24 11:47:16 PDT 2008


Author: kremenek
Date: Thu Jul 24 13:47:16 2008
New Revision: 53993

URL: http://llvm.org/viewvc/llvm-project?rev=53993&view=rev
Log:
Correctly handle NSAssertionHandle -handleFailureInMethod:object:file:lineNumber:description:
This fixes: http://llvm.org/bugs/show_bug.cgi?id=2593

Added:
    cfe/trunk/test/Analysis/CFRetainRelease_NSAssertionHandler.m
Modified:
    cfe/trunk/lib/Analysis/CFRefCount.cpp

Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=53993&r1=53992&r2=53993&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Thu Jul 24 13:47:16 2008
@@ -1038,6 +1038,7 @@
   
   II.clear();
   II.push_back(&Ctx.Idents.get("handleFailureInMethod"));
+  II.push_back(&Ctx.Idents.get("object"));
   II.push_back(&Ctx.Idents.get("file"));
   II.push_back(&Ctx.Idents.get("lineNumber"));
   II.push_back(&Ctx.Idents.get("description"));

Added: cfe/trunk/test/Analysis/CFRetainRelease_NSAssertionHandler.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/CFRetainRelease_NSAssertionHandler.m?rev=53993&view=auto

==============================================================================
--- cfe/trunk/test/Analysis/CFRetainRelease_NSAssertionHandler.m (added)
+++ cfe/trunk/test/Analysis/CFRetainRelease_NSAssertionHandler.m Thu Jul 24 13:47:16 2008
@@ -0,0 +1,64 @@
+// RUN: clang -checker-cfref -verify %s
+
+typedef struct objc_selector *SEL;
+typedef signed char BOOL;
+typedef int NSInteger;
+typedef unsigned int NSUInteger;
+typedef struct _NSZone NSZone;
+ at class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+ at protocol NSObject  - (BOOL)isEqual:(id)object; @end
+ at protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end
+ at protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone; @end
+ at protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end
+ at interface NSObject <NSObject> {} - (id)init; @end
+extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
+ at interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
+- (NSUInteger)length;
++ (id)stringWithUTF8String:(const char *)nullTerminatedCString;
+ at end extern NSString * const NSBundleDidLoadNotification;
+ at interface NSAssertionHandler : NSObject {}
++ (NSAssertionHandler *)currentHandler;
+- (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...;
+ at end
+extern NSString * const NSConnectionReplyMode;
+
+//----------------------------------------------------------------------------//
+// The following test case was filed in PR 2593:
+//   http://llvm.org/bugs/show_bug.cgi?id=2593
+//
+// There should be no null dereference flagged by the checker because of
+// NSParameterAssert and NSAssert.
+
+
+ at interface TestAssert : NSObject {}
+ at end
+
+ at implementation TestAssert
+
+- (id)initWithPointer: (int*)x
+{
+  // Expansion of: NSParameterAssert( x != 0 );
+  do { if (!((x != 0))) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:"CFRetainRelease_NSAssertionHandler.m"] lineNumber:21 description:(@"Invalid parameter not satisfying: %s"), ("x != 0"), (0), (0), (0), (0)]; } } while(0);
+
+  if( (self = [super init]) != 0 )
+  {
+    *x = 1; // no-warning
+  }
+
+  return self;
+}
+
+- (id)initWithPointer2: (int*)x
+{
+  // Expansion of: NSAssert( x != 0, @"" );
+  do { if (!((x != 0))) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:"CFRetainRelease_NSAssertionHandler.m"] lineNumber:33 description:((@"")), (0), (0), (0), (0), (0)]; } } while(0);  
+
+  if( (self = [super init]) != 0 )
+  {
+    *x = 1; // no-warning
+  }
+
+  return self;
+}
+
+ at end





More information about the cfe-commits mailing list