[cfe-commits] r64937 - /cfe/trunk/lib/Analysis/CFRefCount.cpp

Ted Kremenek kremenek at apple.com
Wed Feb 18 10:54:34 PST 2009


Author: kremenek
Date: Wed Feb 18 12:54:33 2009
New Revision: 64937

URL: http://llvm.org/viewvc/llvm-project?rev=64937&view=rev
Log:
retain/release checker: Distinguish in the function summaries between
retain/releases performed via [... release] and CFRetain(). The former are
no-ops in GC. The checker already handled this, but now we emit nice diagnostics
to the user telling them that these are no-ops.

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=64937&r1=64936&r2=64937&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Wed Feb 18 12:54:33 2009
@@ -131,7 +131,9 @@
 namespace {
 /// ArgEffect is used to summarize a function/method call's effect on a
 /// particular argument.
-enum ArgEffect { IncRef, DecRef, DoNothing, DoNothingByRef,
+enum ArgEffect { IncRefMsg, IncRef,  
+                 DecRefMsg, DecRef,
+                 DoNothing, DoNothingByRef,
                  StopTracking, MayEscape, SelfOwn, Autorelease };
 
 /// ArgEffects summarizes the effects of a function/method call on all of
@@ -1025,11 +1027,11 @@
   
   // Create the "retain" selector.
   E = RetEffect::MakeReceiverAlias();
-  Summ = getPersistentSummary(E, isGCEnabled() ? DoNothing : IncRef);
+  Summ = getPersistentSummary(E, IncRefMsg);
   addNSObjectMethSummary(GetNullarySelector("retain", Ctx), Summ);
   
   // Create the "release" selector.
-  Summ = getPersistentSummary(E, isGCEnabled() ? DoNothing : DecRef);
+  Summ = getPersistentSummary(E, DecRefMsg);
   addNSObjectMethSummary(GetNullarySelector("release", Ctx), Summ);
   
   // Create the "drain" selector.
@@ -1936,9 +1938,13 @@
                                RefVal V, ArgEffect E,
                                RefVal::Kind& hasErr,
                                RefBindings::Factory& RefBFactory) {
-  
-  // FIXME: This dispatch can potentially be sped up by unifiying it into
-  //  a single switch statement.  Opt for simplicity for now.
+
+  // In GC mode [... release] and [... retain] do nothing.
+  switch (E) {
+    default: break;
+    case IncRefMsg: E = isGCEnabled() ? DoNothing : IncRef; break;
+    case DecRefMsg: E = isGCEnabled() ? DoNothing : DecRef; break;
+  }
   
   switch (E) {
     default:
@@ -1987,7 +1993,7 @@
       
     case SelfOwn:
       V = V ^ RefVal::NotOwned;
-      // Fall-through.      
+      // Fall-through.
     case DecRef:
       switch (V.getKind()) {
         default:
@@ -2344,11 +2350,20 @@
     for (llvm::SmallVectorImpl<ArgEffect>::iterator I=AEffects.begin(),
           E=AEffects.end(); I != E; ++I) {
 
-      // Did we do an 'autorelease' in GC mode?
-      if (TF.isGCEnabled() && *I == Autorelease) {
-        os << "In GC mode an 'autorelease' has no effect.";
-        continue;
-      }
+      // A bunch of things have alternate behavior under GC.
+      if (TF.isGCEnabled())
+        switch (*I) {
+          default: break;
+          case Autorelease:
+            os << "In GC mode an 'autorelease' has no effect.";
+            continue;
+          case IncRefMsg:
+            os << "In GC mode the 'retain' message has no effect.";
+            continue;
+          case DecRefMsg:
+            os << "In GC mode the 'release' message has no effect.";
+            continue;
+        }
     }
   }
 





More information about the cfe-commits mailing list