ExprEngineCallAndReturn.cpp revision da29ac527063fc9714547088bf841bfa30557bf0
1//=-- ExprEngineCallAndReturn.cpp - Support for call/return -----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines ExprEngine's support for calls and returns. 11// 12//===----------------------------------------------------------------------===// 13 14#define DEBUG_TYPE "ExprEngine" 15 16#include "clang/Analysis/Analyses/LiveVariables.h" 17#include "clang/StaticAnalyzer/Core/CheckerManager.h" 18#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h" 19#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" 20#include "clang/AST/DeclCXX.h" 21#include "llvm/ADT/SmallSet.h" 22#include "llvm/ADT/Statistic.h" 23#include "llvm/Support/SaveAndRestore.h" 24 25#define CXX_INLINING_ENABLED 1 26 27using namespace clang; 28using namespace ento; 29 30STATISTIC(NumOfDynamicDispatchPathSplits, 31 "The # of times we split the path due to imprecise dynamic dispatch info"); 32 33void ExprEngine::processCallEnter(CallEnter CE, ExplodedNode *Pred) { 34 // Get the entry block in the CFG of the callee. 35 const StackFrameContext *calleeCtx = CE.getCalleeContext(); 36 const CFG *CalleeCFG = calleeCtx->getCFG(); 37 const CFGBlock *Entry = &(CalleeCFG->getEntry()); 38 39 // Validate the CFG. 40 assert(Entry->empty()); 41 assert(Entry->succ_size() == 1); 42 43 // Get the solitary sucessor. 44 const CFGBlock *Succ = *(Entry->succ_begin()); 45 46 // Construct an edge representing the starting location in the callee. 47 BlockEdge Loc(Entry, Succ, calleeCtx); 48 49 ProgramStateRef state = Pred->getState(); 50 51 // Construct a new node and add it to the worklist. 52 bool isNew; 53 ExplodedNode *Node = G.getNode(Loc, state, false, &isNew); 54 Node->addPredecessor(Pred, G); 55 if (isNew) 56 Engine.getWorkList()->enqueue(Node); 57} 58 59// Find the last statement on the path to the exploded node and the 60// corresponding Block. 61static std::pair<const Stmt*, 62 const CFGBlock*> getLastStmt(const ExplodedNode *Node) { 63 const Stmt *S = 0; 64 const StackFrameContext *SF = 65 Node->getLocation().getLocationContext()->getCurrentStackFrame(); 66 67 // Back up through the ExplodedGraph until we reach a statement node. 68 while (Node) { 69 const ProgramPoint &PP = Node->getLocation(); 70 71 if (const StmtPoint *SP = dyn_cast<StmtPoint>(&PP)) { 72 S = SP->getStmt(); 73 break; 74 } else if (const CallExitEnd *CEE = dyn_cast<CallExitEnd>(&PP)) { 75 S = CEE->getCalleeContext()->getCallSite(); 76 if (S) 77 break; 78 // If we have an implicit call, we'll probably end up with a 79 // StmtPoint inside the callee, which is acceptable. 80 // (It's possible a function ONLY contains implicit calls -- such as an 81 // implicitly-generated destructor -- so we shouldn't just skip back to 82 // the CallEnter node and keep going.) 83 } else if (const CallEnter *CE = dyn_cast<CallEnter>(&PP)) { 84 // If we reached the CallEnter for this function, it has no statements. 85 if (CE->getCalleeContext() == SF) 86 break; 87 } 88 89 Node = *Node->pred_begin(); 90 } 91 92 const CFGBlock *Blk = 0; 93 if (S) { 94 // Now, get the enclosing basic block. 95 while (Node && Node->pred_size() >=1 ) { 96 const ProgramPoint &PP = Node->getLocation(); 97 if (isa<BlockEdge>(PP) && 98 (PP.getLocationContext()->getCurrentStackFrame() == SF)) { 99 BlockEdge &EPP = cast<BlockEdge>(PP); 100 Blk = EPP.getDst(); 101 break; 102 } 103 Node = *Node->pred_begin(); 104 } 105 } 106 107 return std::pair<const Stmt*, const CFGBlock*>(S, Blk); 108} 109 110/// The call exit is simulated with a sequence of nodes, which occur between 111/// CallExitBegin and CallExitEnd. The following operations occur between the 112/// two program points: 113/// 1. CallExitBegin (triggers the start of call exit sequence) 114/// 2. Bind the return value 115/// 3. Run Remove dead bindings to clean up the dead symbols from the callee. 116/// 4. CallExitEnd (switch to the caller context) 117/// 5. PostStmt<CallExpr> 118void ExprEngine::processCallExit(ExplodedNode *CEBNode) { 119 // Step 1 CEBNode was generated before the call. 120 121 const StackFrameContext *calleeCtx = 122 CEBNode->getLocationContext()->getCurrentStackFrame(); 123 124 // The parent context might not be a stack frame, so make sure we 125 // look up the first enclosing stack frame. 126 const StackFrameContext *callerCtx = 127 calleeCtx->getParent()->getCurrentStackFrame(); 128 129 const Stmt *CE = calleeCtx->getCallSite(); 130 ProgramStateRef state = CEBNode->getState(); 131 // Find the last statement in the function and the corresponding basic block. 132 const Stmt *LastSt = 0; 133 const CFGBlock *Blk = 0; 134 llvm::tie(LastSt, Blk) = getLastStmt(CEBNode); 135 136 // Step 2: generate node with bound return value: CEBNode -> BindedRetNode. 137 138 // If the callee returns an expression, bind its value to CallExpr. 139 if (CE) { 140 if (const ReturnStmt *RS = dyn_cast_or_null<ReturnStmt>(LastSt)) { 141 const LocationContext *LCtx = CEBNode->getLocationContext(); 142 SVal V = state->getSVal(RS, LCtx); 143 state = state->BindExpr(CE, callerCtx, V); 144 } 145 146 // Bind the constructed object value to CXXConstructExpr. 147 if (const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(CE)) { 148 loc::MemRegionVal This = 149 svalBuilder.getCXXThis(CCE->getConstructor()->getParent(), calleeCtx); 150 SVal ThisV = state->getSVal(This); 151 152 // Always bind the region to the CXXConstructExpr. 153 state = state->BindExpr(CCE, callerCtx, ThisV); 154 } 155 } 156 157 // Generate a CallEvent /before/ cleaning the state, so that we can get the 158 // correct value for 'this' (if necessary). 159 CallEventManager &CEMgr = getStateManager().getCallEventManager(); 160 CallEventRef<> Call = CEMgr.getCaller(calleeCtx, state); 161 162 // Step 3: BindedRetNode -> CleanedNodes 163 // If we can find a statement and a block in the inlined function, run remove 164 // dead bindings before returning from the call. This is important to ensure 165 // that we report the issues such as leaks in the stack contexts in which 166 // they occurred. 167 ExplodedNodeSet CleanedNodes; 168 if (LastSt && Blk) { 169 static SimpleProgramPointTag retValBind("ExprEngine : Bind Return Value"); 170 PostStmt Loc(LastSt, calleeCtx, &retValBind); 171 bool isNew; 172 ExplodedNode *BindedRetNode = G.getNode(Loc, state, false, &isNew); 173 BindedRetNode->addPredecessor(CEBNode, G); 174 if (!isNew) 175 return; 176 177 NodeBuilderContext Ctx(getCoreEngine(), Blk, BindedRetNode); 178 currentBuilderContext = &Ctx; 179 // Here, we call the Symbol Reaper with 0 statement and caller location 180 // context, telling it to clean up everything in the callee's context 181 // (and it's children). We use LastStmt as a diagnostic statement, which 182 // which the PreStmtPurge Dead point will be associated. 183 removeDead(BindedRetNode, CleanedNodes, 0, callerCtx, LastSt, 184 ProgramPoint::PostStmtPurgeDeadSymbolsKind); 185 currentBuilderContext = 0; 186 } else { 187 CleanedNodes.Add(CEBNode); 188 } 189 190 for (ExplodedNodeSet::iterator I = CleanedNodes.begin(), 191 E = CleanedNodes.end(); I != E; ++I) { 192 193 // Step 4: Generate the CallExit and leave the callee's context. 194 // CleanedNodes -> CEENode 195 CallExitEnd Loc(calleeCtx, callerCtx); 196 bool isNew; 197 ProgramStateRef CEEState = (*I == CEBNode) ? state : (*I)->getState(); 198 ExplodedNode *CEENode = G.getNode(Loc, CEEState, false, &isNew); 199 CEENode->addPredecessor(*I, G); 200 if (!isNew) 201 return; 202 203 // Step 5: Perform the post-condition check of the CallExpr and enqueue the 204 // result onto the work list. 205 // CEENode -> Dst -> WorkList 206 NodeBuilderContext Ctx(Engine, calleeCtx->getCallSiteBlock(), CEENode); 207 SaveAndRestore<const NodeBuilderContext*> NBCSave(currentBuilderContext, 208 &Ctx); 209 SaveAndRestore<unsigned> CBISave(currentStmtIdx, calleeCtx->getIndex()); 210 211 CallEventRef<> UpdatedCall = Call.cloneWithState(CEEState); 212 213 ExplodedNodeSet DstPostCall; 214 getCheckerManager().runCheckersForPostCall(DstPostCall, CEENode, 215 *UpdatedCall, *this, 216 /*WasInlined=*/true); 217 218 ExplodedNodeSet Dst; 219 if (const ObjCMethodCall *Msg = dyn_cast<ObjCMethodCall>(Call)) { 220 getCheckerManager().runCheckersForPostObjCMessage(Dst, DstPostCall, *Msg, 221 *this, 222 /*WasInlined=*/true); 223 } else if (CE) { 224 getCheckerManager().runCheckersForPostStmt(Dst, DstPostCall, CE, 225 *this, /*WasInlined=*/true); 226 } else { 227 Dst.insert(DstPostCall); 228 } 229 230 // Enqueue the next element in the block. 231 for (ExplodedNodeSet::iterator PSI = Dst.begin(), PSE = Dst.end(); 232 PSI != PSE; ++PSI) { 233 Engine.getWorkList()->enqueue(*PSI, calleeCtx->getCallSiteBlock(), 234 calleeCtx->getIndex()+1); 235 } 236 } 237} 238 239static unsigned getNumberStackFrames(const LocationContext *LCtx) { 240 unsigned count = 0; 241 while (LCtx) { 242 if (isa<StackFrameContext>(LCtx)) 243 ++count; 244 LCtx = LCtx->getParent(); 245 } 246 return count; 247} 248 249// Determine if we should inline the call. 250bool ExprEngine::shouldInlineDecl(const Decl *D, ExplodedNode *Pred) { 251 AnalysisDeclContext *CalleeADC = AMgr.getAnalysisDeclContext(D); 252 const CFG *CalleeCFG = CalleeADC->getCFG(); 253 254 // It is possible that the CFG cannot be constructed. 255 // Be safe, and check if the CalleeCFG is valid. 256 if (!CalleeCFG) 257 return false; 258 259 if (getNumberStackFrames(Pred->getLocationContext()) 260 == AMgr.InlineMaxStackDepth) 261 return false; 262 263 if (Engine.FunctionSummaries->hasReachedMaxBlockCount(D)) 264 return false; 265 266 if (CalleeCFG->getNumBlockIDs() > AMgr.InlineMaxFunctionSize) 267 return false; 268 269 // Do not inline variadic calls (for now). 270 if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { 271 if (BD->isVariadic()) 272 return false; 273 } 274 else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 275 if (FD->isVariadic()) 276 return false; 277 } 278 279 // It is possible that the live variables analysis cannot be 280 // run. If so, bail out. 281 if (!CalleeADC->getAnalysis<RelaxedLiveVariables>()) 282 return false; 283 284 return true; 285} 286 287/// The GDM component containing the dynamic dispatch bifurcation info. When 288/// the exact type of the receiver is not known, we want to explore both paths - 289/// one on which we do inline it and the other one on which we don't. This is 290/// done to ensure we do not drop coverage. 291/// This is the map from the receiver region to a bool, specifying either we 292/// consider this region's information precise or not along the given path. 293namespace clang { 294namespace ento { 295enum DynamicDispatchMode { DynamicDispatchModeInlined = 1, 296 DynamicDispatchModeConservative }; 297 298struct DynamicDispatchBifurcationMap {}; 299typedef llvm::ImmutableMap<const MemRegion*, 300 unsigned int> DynamicDispatchBifur; 301template<> struct ProgramStateTrait<DynamicDispatchBifurcationMap> 302 : public ProgramStatePartialTrait<DynamicDispatchBifur> { 303 static void *GDMIndex() { static int index; return &index; } 304}; 305 306}} 307 308bool ExprEngine::inlineCall(const CallEvent &Call, const Decl *D, 309 NodeBuilder &Bldr, ExplodedNode *Pred, 310 ProgramStateRef State) { 311 assert(D); 312 313 const LocationContext *CurLC = Pred->getLocationContext(); 314 const StackFrameContext *CallerSFC = CurLC->getCurrentStackFrame(); 315 const LocationContext *ParentOfCallee = 0; 316 317 // FIXME: Refactor this check into a hypothetical CallEvent::canInline. 318 switch (Call.getKind()) { 319 case CE_Function: 320 break; 321 case CE_CXXMember: 322 case CE_CXXMemberOperator: 323 if (!CXX_INLINING_ENABLED) 324 return false; 325 break; 326 case CE_CXXConstructor: { 327 if (!CXX_INLINING_ENABLED) 328 return false; 329 330 // Only inline constructors and destructors if we built the CFGs for them 331 // properly. 332 const AnalysisDeclContext *ADC = CallerSFC->getAnalysisDeclContext(); 333 if (!ADC->getCFGBuildOptions().AddImplicitDtors || 334 !ADC->getCFGBuildOptions().AddInitializers) 335 return false; 336 337 const CXXConstructorCall &Ctor = cast<CXXConstructorCall>(Call); 338 339 // FIXME: We don't handle constructors or destructors for arrays properly. 340 const MemRegion *Target = Ctor.getCXXThisVal().getAsRegion(); 341 if (Target && isa<ElementRegion>(Target)) 342 return false; 343 344 // FIXME: This is a hack. We don't handle temporary destructors 345 // right now, so we shouldn't inline their constructors. 346 const CXXConstructExpr *CtorExpr = Ctor.getOriginExpr(); 347 if (CtorExpr->getConstructionKind() == CXXConstructExpr::CK_Complete) 348 if (!Target || !isa<DeclRegion>(Target)) 349 return false; 350 351 break; 352 } 353 case CE_CXXDestructor: { 354 if (!CXX_INLINING_ENABLED) 355 return false; 356 357 // Only inline constructors and destructors if we built the CFGs for them 358 // properly. 359 const AnalysisDeclContext *ADC = CallerSFC->getAnalysisDeclContext(); 360 if (!ADC->getCFGBuildOptions().AddImplicitDtors || 361 !ADC->getCFGBuildOptions().AddInitializers) 362 return false; 363 364 const CXXDestructorCall &Dtor = cast<CXXDestructorCall>(Call); 365 366 // FIXME: We don't handle constructors or destructors for arrays properly. 367 const MemRegion *Target = Dtor.getCXXThisVal().getAsRegion(); 368 if (Target && isa<ElementRegion>(Target)) 369 return false; 370 371 break; 372 } 373 case CE_CXXAllocator: 374 if (!CXX_INLINING_ENABLED) 375 return false; 376 377 // Do not inline allocators until we model deallocators. 378 // This is unfortunate, but basically necessary for smart pointers and such. 379 return false; 380 case CE_Block: { 381 const BlockDataRegion *BR = cast<BlockCall>(Call).getBlockRegion(); 382 assert(BR && "If we have the block definition we should have its region"); 383 AnalysisDeclContext *BlockCtx = AMgr.getAnalysisDeclContext(D); 384 ParentOfCallee = BlockCtx->getBlockInvocationContext(CallerSFC, 385 cast<BlockDecl>(D), 386 BR); 387 break; 388 } 389 case CE_ObjCMessage: 390 if (!(getAnalysisManager().IPAMode == DynamicDispatch || 391 getAnalysisManager().IPAMode == DynamicDispatchBifurcate)) 392 return false; 393 break; 394 } 395 396 if (!shouldInlineDecl(D, Pred)) 397 return false; 398 399 if (!ParentOfCallee) 400 ParentOfCallee = CallerSFC; 401 402 // This may be NULL, but that's fine. 403 const Expr *CallE = Call.getOriginExpr(); 404 405 // Construct a new stack frame for the callee. 406 AnalysisDeclContext *CalleeADC = AMgr.getAnalysisDeclContext(D); 407 const StackFrameContext *CalleeSFC = 408 CalleeADC->getStackFrame(ParentOfCallee, CallE, 409 currentBuilderContext->getBlock(), 410 currentStmtIdx); 411 412 CallEnter Loc(CallE, CalleeSFC, CurLC); 413 414 // Construct a new state which contains the mapping from actual to 415 // formal arguments. 416 State = State->enterStackFrame(Call, CalleeSFC); 417 418 bool isNew; 419 if (ExplodedNode *N = G.getNode(Loc, State, false, &isNew)) { 420 N->addPredecessor(Pred, G); 421 if (isNew) 422 Engine.getWorkList()->enqueue(N); 423 } 424 425 // If we decided to inline the call, the successor has been manually 426 // added onto the work list so remove it from the node builder. 427 Bldr.takeNodes(Pred); 428 429 return true; 430} 431 432static ProgramStateRef getInlineFailedState(ProgramStateRef State, 433 const Stmt *CallE) { 434 void *ReplayState = State->get<ReplayWithoutInlining>(); 435 if (!ReplayState) 436 return 0; 437 438 assert(ReplayState == (const void*)CallE && "Backtracked to the wrong call."); 439 (void)CallE; 440 441 return State->remove<ReplayWithoutInlining>(); 442} 443 444void ExprEngine::VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred, 445 ExplodedNodeSet &dst) { 446 // Perform the previsit of the CallExpr. 447 ExplodedNodeSet dstPreVisit; 448 getCheckerManager().runCheckersForPreStmt(dstPreVisit, Pred, CE, *this); 449 450 // Get the call in its initial state. We use this as a template to perform 451 // all the checks. 452 CallEventManager &CEMgr = getStateManager().getCallEventManager(); 453 CallEventRef<> CallTemplate 454 = CEMgr.getSimpleCall(CE, Pred->getState(), Pred->getLocationContext()); 455 456 // Evaluate the function call. We try each of the checkers 457 // to see if the can evaluate the function call. 458 ExplodedNodeSet dstCallEvaluated; 459 for (ExplodedNodeSet::iterator I = dstPreVisit.begin(), E = dstPreVisit.end(); 460 I != E; ++I) { 461 evalCall(dstCallEvaluated, *I, *CallTemplate); 462 } 463 464 // Finally, perform the post-condition check of the CallExpr and store 465 // the created nodes in 'Dst'. 466 // Note that if the call was inlined, dstCallEvaluated will be empty. 467 // The post-CallExpr check will occur in processCallExit. 468 getCheckerManager().runCheckersForPostStmt(dst, dstCallEvaluated, CE, 469 *this); 470} 471 472void ExprEngine::evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred, 473 const CallEvent &Call) { 474 // WARNING: At this time, the state attached to 'Call' may be older than the 475 // state in 'Pred'. This is a minor optimization since CheckerManager will 476 // use an updated CallEvent instance when calling checkers, but if 'Call' is 477 // ever used directly in this function all callers should be updated to pass 478 // the most recent state. (It is probably not worth doing the work here since 479 // for some callers this will not be necessary.) 480 481 // Run any pre-call checks using the generic call interface. 482 ExplodedNodeSet dstPreVisit; 483 getCheckerManager().runCheckersForPreCall(dstPreVisit, Pred, Call, *this); 484 485 // Actually evaluate the function call. We try each of the checkers 486 // to see if the can evaluate the function call, and get a callback at 487 // defaultEvalCall if all of them fail. 488 ExplodedNodeSet dstCallEvaluated; 489 getCheckerManager().runCheckersForEvalCall(dstCallEvaluated, dstPreVisit, 490 Call, *this); 491 492 // Finally, run any post-call checks. 493 getCheckerManager().runCheckersForPostCall(Dst, dstCallEvaluated, 494 Call, *this); 495} 496 497ProgramStateRef ExprEngine::bindReturnValue(const CallEvent &Call, 498 const LocationContext *LCtx, 499 ProgramStateRef State) { 500 const Expr *E = Call.getOriginExpr(); 501 if (!E) 502 return State; 503 504 // Some method families have known return values. 505 if (const ObjCMethodCall *Msg = dyn_cast<ObjCMethodCall>(&Call)) { 506 switch (Msg->getMethodFamily()) { 507 default: 508 break; 509 case OMF_autorelease: 510 case OMF_retain: 511 case OMF_self: { 512 // These methods return their receivers. 513 return State->BindExpr(E, LCtx, Msg->getReceiverSVal()); 514 } 515 } 516 } else if (const CXXConstructorCall *C = dyn_cast<CXXConstructorCall>(&Call)){ 517 return State->BindExpr(E, LCtx, C->getCXXThisVal()); 518 } 519 520 // Conjure a symbol if the return value is unknown. 521 QualType ResultTy = Call.getResultType(); 522 SValBuilder &SVB = getSValBuilder(); 523 unsigned Count = currentBuilderContext->getCurrentBlockCount(); 524 SVal R = SVB.getConjuredSymbolVal(0, E, LCtx, ResultTy, Count); 525 return State->BindExpr(E, LCtx, R); 526} 527 528// Conservatively evaluate call by invalidating regions and binding 529// a conjured return value. 530void ExprEngine::conservativeEvalCall(const CallEvent &Call, NodeBuilder &Bldr, 531 ExplodedNode *Pred, ProgramStateRef State) { 532 unsigned Count = currentBuilderContext->getCurrentBlockCount(); 533 State = Call.invalidateRegions(Count, State); 534 State = bindReturnValue(Call, Pred->getLocationContext(), State); 535 536 // And make the result node. 537 Bldr.generateNode(Call.getProgramPoint(), State, Pred); 538} 539 540void ExprEngine::defaultEvalCall(NodeBuilder &Bldr, ExplodedNode *Pred, 541 const CallEvent &CallTemplate) { 542 // Make sure we have the most recent state attached to the call. 543 ProgramStateRef State = Pred->getState(); 544 CallEventRef<> Call = CallTemplate.cloneWithState(State); 545 546 if (!getAnalysisManager().shouldInlineCall()) { 547 conservativeEvalCall(*Call, Bldr, Pred, State); 548 return; 549 } 550 // Try to inline the call. 551 // The origin expression here is just used as a kind of checksum; 552 // this should still be safe even for CallEvents that don't come from exprs. 553 const Expr *E = Call->getOriginExpr(); 554 ProgramStateRef InlinedFailedState = getInlineFailedState(State, E); 555 556 if (InlinedFailedState) { 557 // If we already tried once and failed, make sure we don't retry later. 558 State = InlinedFailedState; 559 } else { 560 RuntimeDefinition RD = Call->getRuntimeDefinition(); 561 const Decl *D = RD.getDecl(); 562 if (D) { 563 if (RD.mayHaveOtherDefinitions()) { 564 // Explore with and without inlining the call. 565 if (getAnalysisManager().IPAMode == DynamicDispatchBifurcate) { 566 BifurcateCall(RD.getDispatchRegion(), *Call, D, Bldr, Pred); 567 return; 568 } 569 570 // Don't inline if we're not in any dynamic dispatch mode. 571 if (getAnalysisManager().IPAMode != DynamicDispatch) { 572 conservativeEvalCall(*Call, Bldr, Pred, State); 573 return; 574 } 575 } 576 577 // We are not bifurcating and we do have a Decl, so just inline. 578 if (inlineCall(*Call, D, Bldr, Pred, State)) 579 return; 580 } 581 } 582 583 // If we can't inline it, handle the return value and invalidate the regions. 584 conservativeEvalCall(*Call, Bldr, Pred, State); 585} 586 587void ExprEngine::BifurcateCall(const MemRegion *BifurReg, 588 const CallEvent &Call, const Decl *D, 589 NodeBuilder &Bldr, ExplodedNode *Pred) { 590 assert(BifurReg); 591 BifurReg = BifurReg->StripCasts(); 592 593 // Check if we've performed the split already - note, we only want 594 // to split the path once per memory region. 595 ProgramStateRef State = Pred->getState(); 596 const unsigned int *BState = 597 State->get<DynamicDispatchBifurcationMap>(BifurReg); 598 if (BState) { 599 // If we are on "inline path", keep inlining if possible. 600 if (*BState == DynamicDispatchModeInlined) 601 if (inlineCall(Call, D, Bldr, Pred, State)) 602 return; 603 // If inline failed, or we are on the path where we assume we 604 // don't have enough info about the receiver to inline, conjure the 605 // return value and invalidate the regions. 606 conservativeEvalCall(Call, Bldr, Pred, State); 607 return; 608 } 609 610 // If we got here, this is the first time we process a message to this 611 // region, so split the path. 612 ProgramStateRef IState = 613 State->set<DynamicDispatchBifurcationMap>(BifurReg, 614 DynamicDispatchModeInlined); 615 inlineCall(Call, D, Bldr, Pred, IState); 616 617 ProgramStateRef NoIState = 618 State->set<DynamicDispatchBifurcationMap>(BifurReg, 619 DynamicDispatchModeConservative); 620 conservativeEvalCall(Call, Bldr, Pred, NoIState); 621 622 NumOfDynamicDispatchPathSplits++; 623 return; 624} 625 626 627void ExprEngine::VisitReturnStmt(const ReturnStmt *RS, ExplodedNode *Pred, 628 ExplodedNodeSet &Dst) { 629 630 ExplodedNodeSet dstPreVisit; 631 getCheckerManager().runCheckersForPreStmt(dstPreVisit, Pred, RS, *this); 632 633 StmtNodeBuilder B(dstPreVisit, Dst, *currentBuilderContext); 634 635 if (RS->getRetValue()) { 636 for (ExplodedNodeSet::iterator it = dstPreVisit.begin(), 637 ei = dstPreVisit.end(); it != ei; ++it) { 638 B.generateNode(RS, *it, (*it)->getState()); 639 } 640 } 641} 642