[cfe-commits] r71843 - /cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp

Ted Kremenek kremenek at apple.com
Thu May 14 22:34:51 PDT 2009


Author: kremenek
Date: Fri May 15 00:34:49 2009
New Revision: 71843

URL: http://llvm.org/viewvc/llvm-project?rev=71843&view=rev
Log:
Use dyn_cast instead of cast to allow our assumptions to be safely wrong.

Modified:
    cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp Fri May 15 00:34:49 2009
@@ -631,22 +631,30 @@
 
 static const Stmt *GetReceiverExpr(const ExplodedNode<GRState> *N) {
   const Stmt *S = N->getLocationAs<PostStmt>()->getStmt();
-  return cast<ObjCMessageExpr>(S)->getReceiver();
+  if (const ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(S))
+    return ME->getReceiver();
+  return NULL;
 }
   
 static const Stmt *GetDenomExpr(const ExplodedNode<GRState> *N) {
   const Stmt *S = N->getLocationAs<PostStmt>()->getStmt();
-  return cast<BinaryOperator>(S)->getRHS();
+  if (const BinaryOperator *BE = dyn_cast<BinaryOperator>(S))
+    return BE->getRHS();
+  return NULL;
 }
   
 static const Stmt *GetCalleeExpr(const ExplodedNode<GRState> *N) {
   const Stmt *S = N->getLocationAs<PostStmt>()->getStmt();
-  return cast<CallExpr>(S)->getCallee();
+  if (const CallExpr *CE = dyn_cast<CallExpr>(S))
+    return CE->getCallee();
+  return NULL;
 }
   
 static const Stmt *GetRetValExpr(const ExplodedNode<GRState> *N) {
   const Stmt *S = N->getLocationAs<PostStmt>()->getStmt();
-  return cast<ReturnStmt>(S)->getRetValue();
+  if (const ReturnStmt *RS = dyn_cast<ReturnStmt>(S))
+    return RS->getRetValue();
+  return NULL;
 }
 
 namespace {





More information about the cfe-commits mailing list