]> granicus.if.org Git - clang/commitdiff
Use dyn_cast instead of cast to allow our assumptions to be safely wrong.
authorTed Kremenek <kremenek@apple.com>
Fri, 15 May 2009 05:34:49 +0000 (05:34 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 15 May 2009 05:34:49 +0000 (05:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71843 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/GRExprEngineInternalChecks.cpp

index a29862952989b32dded96418f02ff00d7791adf7..9aea12447dd51b142ac66816463cbd5905f8705a 100644 (file)
@@ -631,22 +631,30 @@ static const Stmt *GetDerefExpr(const ExplodedNode<GRState> *N) {
 
 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 {