[cfe-commits] r125422 - in /cfe/trunk: lib/StaticAnalyzer/Core/CFRefCount.cpp test/Analysis/idempotent-operations.m

Ted Kremenek kremenek at apple.com
Fri Feb 11 17:01:31 PST 2011


Author: kremenek
Date: Fri Feb 11 19:01:31 2011
New Revision: 125422

URL: http://llvm.org/viewvc/llvm-project?rev=125422&view=rev
Log:
static analyzer: Also invalidate instance variables of a receiver in a message expression, just as we do with parameters.

Fixes <rdar://problem/8725041>.

Added:
    cfe/trunk/test/Analysis/idempotent-operations.m
Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp?rev=125422&r1=125421&r2=125422&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp Fri Feb 11 19:01:31 2011
@@ -2514,6 +2514,18 @@
   //  done an invalidation pass.
   llvm::DenseSet<SymbolRef> WhitelistedSymbols;
 
+  // Invalidate all instance variables of the receiver of a message.
+  // FIXME: We should be able to do better with inter-procedural analysis.
+  if (Receiver) {
+    SVal V = Receiver.getSValAsScalarOrLoc(state);
+    if (SymbolRef Sym = V.getAsLocSymbol()) {
+      if (state->get<RefBindings>(Sym))
+        WhitelistedSymbols.insert(Sym);
+    }
+    if (const MemRegion *region = V.getAsRegion())
+      RegionsToInvalidate.push_back(region);
+  }
+  
   for (unsigned idx = 0, e = callOrMsg.getNumArgs(); idx != e; ++idx) {
     SVal V = callOrMsg.getArgSValAsScalarOrLoc(idx);
     SymbolRef Sym = V.getAsLocSymbol();

Added: cfe/trunk/test/Analysis/idempotent-operations.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/idempotent-operations.m?rev=125422&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/idempotent-operations.m (added)
+++ cfe/trunk/test/Analysis/idempotent-operations.m Fri Feb 11 19:01:31 2011
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-check-idempotent-operations -verify %s
+
+typedef signed char BOOL;
+typedef unsigned long NSUInteger;
+typedef struct _NSZone NSZone;
+ at protocol NSObject  - (BOOL)isEqual:(id)object;
+ at end    @interface NSObject <NSObject> {
+}
+ at end
+
+
+// <rdar://problem/8725041> - Don't flag idempotent operation warnings when
+// a method may invalidate an instance variable.
+ at interface Rdar8725041 : NSObject {
+  id _attribute;
+}
+  - (void) method2;
+ at end
+
+ at implementation Rdar8725041
+- (BOOL) method1 {
+  BOOL needsUpdate = (BOOL)0;
+  id oldAttribute = _attribute;
+  [self method2];
+  needsUpdate |= (_attribute != oldAttribute); // no-warning
+  return needsUpdate;
+}
+
+- (void) method2
+{
+  _attribute = ((void*)0);
+}
+ at end
+





More information about the cfe-commits mailing list