[cfe-commits] r53758 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRCoreEngine.h lib/Analysis/CFRefCount.cpp

Ted Kremenek kremenek at apple.com
Fri Jul 18 10:24:20 PDT 2008


Author: kremenek
Date: Fri Jul 18 12:24:20 2008
New Revision: 53758

URL: http://llvm.org/viewvc/llvm-project?rev=53758&view=rev
Log:
Add panic support for NSAssertionHandler.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
    cfe/trunk/lib/Analysis/CFRefCount.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h?rev=53758&r1=53757&r2=53758&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h Fri Jul 18 12:24:20 2008
@@ -254,6 +254,15 @@
     return N;
   }
   
+  NodeTy* MakeSinkNode(ExplodedNodeSet<StateTy>& Dst, Stmt* S,
+                       NodeTy* Pred, const StateTy* St) { 
+    bool Tmp = BuildSinks;
+    BuildSinks = true;
+    NodeTy* N = MakeNode(Dst, S, Pred, St);
+    BuildSinks = Tmp;
+    return N;
+  }
+  
   bool PurgingDeadSymbols;
   bool BuildSinks;
   bool HasGeneratedNode;

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Jul 18 12:24:20 2008
@@ -208,11 +208,16 @@
   ///  alias of one of the arguments in the call, and so on.
   RetEffect   Ret;
   
+  /// EndPath - Indicates that execution of this method/function should
+  ///  terminate the simulation of a path.
+  bool EndPath;
+  
 public:
   
   RetainSummary(ArgEffects* A, RetEffect R, ArgEffect defaultEff,
-                ArgEffect ReceiverEff)
-    : Args(A), DefaultArgEffect(defaultEff), Receiver(ReceiverEff), Ret(R) {}  
+                ArgEffect ReceiverEff, bool endpath = false)
+    : Args(A), DefaultArgEffect(defaultEff), Receiver(ReceiverEff), Ret(R),
+      EndPath(endpath) {}  
   
   /// getArg - Return the argument effect on the argument specified by
   ///  idx (starting from 0).
@@ -243,6 +248,10 @@
     return Ret;
   }
   
+  /// isEndPath - Returns true if executing the given method/function should
+  ///  terminate the path.
+  bool isEndPath() const { return EndPath; }
+  
   /// getReceiverEffect - Returns the effect on the receiver of the call.
   ///  This is only meaningful if the summary applies to an ObjCMessageExpr*.
   ArgEffect getReceiverEffect() const {
@@ -446,6 +455,10 @@
   /// NSPanelII - An IdentifierInfo* representing the identifier "NSPanel."
   IdentifierInfo* NSPanelII;
   
+  /// NSAssertionHandlerII - An IdentifierInfo* representing the identifier
+  //  "NSAssertionHandler".
+  IdentifierInfo* NSAssertionHandlerII;
+  
   /// CFDictionaryCreateII - An IdentifierInfo* representing the indentifier
   ///  "CFDictionaryCreate".
   IdentifierInfo* CFDictionaryCreateII;
@@ -499,7 +512,8 @@
   
   RetainSummary* getPersistentSummary(ArgEffects* AE, RetEffect RetEff,
                                       ArgEffect ReceiverEff = DoNothing,
-                                      ArgEffect DefaultEff = MayEscape);
+                                      ArgEffect DefaultEff = MayEscape,
+                                      bool isEndPath = false);
                  
 
   RetainSummary* getPersistentSummary(RetEffect RE,
@@ -523,7 +537,12 @@
 
   void InitializeClassMethodSummaries();
   void InitializeMethodSummaries();
-    
+      
+  void addClsMethSummary(IdentifierInfo* ClsII, Selector S,
+                         RetainSummary* Summ) {
+    ObjCClassMethodSummaries[ObjCSummaryKey(ClsII, S)] = Summ;
+  }
+  
   void addNSObjectClsMethSummary(Selector S, RetainSummary *Summ) {
     ObjCClassMethodSummaries[S] = Summ;
   }
@@ -540,12 +559,20 @@
     ObjCMethodSummaries[ObjCSummaryKey(NSPanelII, S)] = Summ;
   }
   
+  void addPanicSummary(IdentifierInfo* ClsII, Selector S) {
+    RetainSummary* Summ = getPersistentSummary(0, RetEffect::MakeNoRet(),
+                                               DoNothing,  DoNothing, true);
+    
+    ObjCMethodSummaries[ObjCSummaryKey(ClsII, S)] = Summ;
+  }
+  
 public:
   
   RetainSummaryManager(ASTContext& ctx, bool gcenabled)
    : Ctx(ctx),
      NSWindowII(&ctx.Idents.get("NSWindow")),
      NSPanelII(&ctx.Idents.get("NSPanel")),
+     NSAssertionHandlerII(&ctx.Idents.get("NSAssertionHandler")),
      CFDictionaryCreateII(&ctx.Idents.get("CFDictionaryCreate")),
      GCEnabled(gcenabled), StopSummary(0) {
 
@@ -611,7 +638,8 @@
 RetainSummary*
 RetainSummaryManager::getPersistentSummary(ArgEffects* AE, RetEffect RetEff,
                                            ArgEffect ReceiverEff,
-                                           ArgEffect DefaultEff) {
+                                           ArgEffect DefaultEff,
+                                           bool isEndPath) {
   
   // Generate a profile for the summary.
   llvm::FoldingSetNodeID profile;
@@ -626,7 +654,7 @@
   
   // Create the summary and return it.
   Summ = (RetainSummary*) BPAlloc.Allocate<RetainSummary>();
-  new (Summ) RetainSummary(AE, RetEff, DefaultEff, ReceiverEff);
+  new (Summ) RetainSummary(AE, RetEff, DefaultEff, ReceiverEff, isEndPath);
   SummarySet.InsertNode(Summ, InsertPos);
   
   return Summ;
@@ -929,6 +957,11 @@
   addNSObjectClsMethSummary(GetNullarySelector("alloc", Ctx), Summ);
   addNSObjectClsMethSummary(GetNullarySelector("new", Ctx), Summ);
   addNSObjectClsMethSummary(GetUnarySelector("allocWithZone", Ctx), Summ);
+  
+  // Create the [NSAssertionHandler currentHander] summary.  
+  addClsMethSummary(NSAssertionHandlerII,
+                    GetUnarySelector("currentHandler", Ctx),
+                    getPersistentSummary(RetEffect::MakeNotOwned()));  
 }
 
 void RetainSummaryManager::InitializeMethodSummaries() {
@@ -991,6 +1024,23 @@
   S = Ctx.Selectors.getSelector(II.size(), &II[0]);
   addNSWindowMethSummary(S, NSWindowSumm);
   addNSPanelMethSummary(S, InitSumm);
+  
+  // Create NSAssertionHandler summaries.
+  II.clear();
+  II.push_back(&Ctx.Idents.get("handleFailureInFunction"));
+  II.push_back(&Ctx.Idents.get("file"));
+  II.push_back(&Ctx.Idents.get("lineNumber"));
+  II.push_back(&Ctx.Idents.get("description"));
+  S = Ctx.Selectors.getSelector(II.size(), &II[0]);
+  addPanicSummary(NSAssertionHandlerII, S);
+  
+  II.clear();
+  II.push_back(&Ctx.Idents.get("handleFailureInMethod"));
+  II.push_back(&Ctx.Idents.get("file"));
+  II.push_back(&Ctx.Idents.get("lineNumber"));
+  II.push_back(&Ctx.Idents.get("description"));
+  S = Ctx.Selectors.getSelector(II.size(), &II[0]);
+  addPanicSummary(NSAssertionHandlerII, S);
 }
 
 //===----------------------------------------------------------------------===//
@@ -1375,6 +1425,10 @@
   return Summ ? Summ->getReceiverEffect() : DoNothing;
 }
 
+static inline bool IsEndPath(RetainSummary* Summ) {
+  return Summ ? Summ->isEndPath() : false;
+}
+
 void CFRefCount::ProcessNonLeakError(ExplodedNodeSet<ValueState>& Dst,
                                      GRStmtNodeBuilder<ValueState>& Builder,
                                      Expr* NodeExpr, Expr* ErrorExpr,                        
@@ -1549,7 +1603,7 @@
     return;
   }
   
-  // Finally, consult the summary for the return value.  
+  // Consult the summary for the return value.  
   RetEffect RE = GetRetEffect(Summ);
   
   switch (RE.getKind()) {
@@ -1630,7 +1684,11 @@
     }
   }
   
-  Builder.MakeNode(Dst, Ex, Pred, St);
+  // Is this a sink?
+  if (IsEndPath(Summ))
+    Builder.MakeSinkNode(Dst, Ex, Pred, St);
+  else
+    Builder.MakeNode(Dst, Ex, Pred, St);
 }
 
 





More information about the cfe-commits mailing list