ExprEngine.cpp revision dc84cd5efdd3430efb22546b4ac656aa0540b210
1//=-- ExprEngine.cpp - Path-Sensitive Expression-Level Dataflow ---*- 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 a meta-engine for path-sensitive dataflow analysis that 11// is built on GREngine, but provides the boilerplate to execute transfer 12// functions and build the ExplodedGraph at the expression level. 13// 14//===----------------------------------------------------------------------===// 15 16#define DEBUG_TYPE "ExprEngine" 17 18#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h" 19#include "clang/AST/CharUnits.h" 20#include "clang/AST/ParentMap.h" 21#include "clang/AST/StmtCXX.h" 22#include "clang/AST/StmtObjC.h" 23#include "clang/Basic/Builtins.h" 24#include "clang/Basic/PrettyStackTrace.h" 25#include "clang/Basic/SourceManager.h" 26#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" 27#include "clang/StaticAnalyzer/Core/CheckerManager.h" 28#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h" 29#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" 30#include "llvm/ADT/ImmutableList.h" 31#include "llvm/ADT/Statistic.h" 32#include "llvm/Support/raw_ostream.h" 33 34#ifndef NDEBUG 35#include "llvm/Support/GraphWriter.h" 36#endif 37 38using namespace clang; 39using namespace ento; 40using llvm::APSInt; 41 42STATISTIC(NumRemoveDeadBindings, 43 "The # of times RemoveDeadBindings is called"); 44STATISTIC(NumMaxBlockCountReached, 45 "The # of aborted paths due to reaching the maximum block count in " 46 "a top level function"); 47STATISTIC(NumMaxBlockCountReachedInInlined, 48 "The # of aborted paths due to reaching the maximum block count in " 49 "an inlined function"); 50STATISTIC(NumTimesRetriedWithoutInlining, 51 "The # of times we re-evaluated a call without inlining"); 52 53//===----------------------------------------------------------------------===// 54// Engine construction and deletion. 55//===----------------------------------------------------------------------===// 56 57ExprEngine::ExprEngine(AnalysisManager &mgr, bool gcEnabled, 58 SetOfConstDecls *VisitedCalleesIn, 59 FunctionSummariesTy *FS, 60 InliningModes HowToInlineIn) 61 : AMgr(mgr), 62 AnalysisDeclContexts(mgr.getAnalysisDeclContextManager()), 63 Engine(*this, FS), 64 G(Engine.getGraph()), 65 StateMgr(getContext(), mgr.getStoreManagerCreator(), 66 mgr.getConstraintManagerCreator(), G.getAllocator(), 67 this), 68 SymMgr(StateMgr.getSymbolManager()), 69 svalBuilder(StateMgr.getSValBuilder()), 70 currStmtIdx(0), currBldrCtx(0), 71 ObjCNoRet(mgr.getASTContext()), 72 ObjCGCEnabled(gcEnabled), BR(mgr, *this), 73 VisitedCallees(VisitedCalleesIn), 74 HowToInline(HowToInlineIn) 75{ 76 unsigned TrimInterval = mgr.options.getGraphTrimInterval(); 77 if (TrimInterval != 0) { 78 // Enable eager node reclaimation when constructing the ExplodedGraph. 79 G.enableNodeReclamation(TrimInterval); 80 } 81} 82 83ExprEngine::~ExprEngine() { 84 BR.FlushReports(); 85} 86 87//===----------------------------------------------------------------------===// 88// Utility methods. 89//===----------------------------------------------------------------------===// 90 91ProgramStateRef ExprEngine::getInitialState(const LocationContext *InitLoc) { 92 ProgramStateRef state = StateMgr.getInitialState(InitLoc); 93 const Decl *D = InitLoc->getDecl(); 94 95 // Preconditions. 96 // FIXME: It would be nice if we had a more general mechanism to add 97 // such preconditions. Some day. 98 do { 99 100 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 101 // Precondition: the first argument of 'main' is an integer guaranteed 102 // to be > 0. 103 const IdentifierInfo *II = FD->getIdentifier(); 104 if (!II || !(II->getName() == "main" && FD->getNumParams() > 0)) 105 break; 106 107 const ParmVarDecl *PD = FD->getParamDecl(0); 108 QualType T = PD->getType(); 109 if (!T->isIntegerType()) 110 break; 111 112 const MemRegion *R = state->getRegion(PD, InitLoc); 113 if (!R) 114 break; 115 116 SVal V = state->getSVal(loc::MemRegionVal(R)); 117 SVal Constraint_untested = evalBinOp(state, BO_GT, V, 118 svalBuilder.makeZeroVal(T), 119 getContext().IntTy); 120 121 Optional<DefinedOrUnknownSVal> Constraint = 122 Constraint_untested.getAs<DefinedOrUnknownSVal>(); 123 124 if (!Constraint) 125 break; 126 127 if (ProgramStateRef newState = state->assume(*Constraint, true)) 128 state = newState; 129 } 130 break; 131 } 132 while (0); 133 134 if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { 135 // Precondition: 'self' is always non-null upon entry to an Objective-C 136 // method. 137 const ImplicitParamDecl *SelfD = MD->getSelfDecl(); 138 const MemRegion *R = state->getRegion(SelfD, InitLoc); 139 SVal V = state->getSVal(loc::MemRegionVal(R)); 140 141 if (Optional<Loc> LV = V.getAs<Loc>()) { 142 // Assume that the pointer value in 'self' is non-null. 143 state = state->assume(*LV, true); 144 assert(state && "'self' cannot be null"); 145 } 146 } 147 148 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) { 149 if (!MD->isStatic()) { 150 // Precondition: 'this' is always non-null upon entry to the 151 // top-level function. This is our starting assumption for 152 // analyzing an "open" program. 153 const StackFrameContext *SFC = InitLoc->getCurrentStackFrame(); 154 if (SFC->getParent() == 0) { 155 loc::MemRegionVal L = svalBuilder.getCXXThis(MD, SFC); 156 SVal V = state->getSVal(L); 157 if (Optional<Loc> LV = V.getAs<Loc>()) { 158 state = state->assume(*LV, true); 159 assert(state && "'this' cannot be null"); 160 } 161 } 162 } 163 } 164 165 return state; 166} 167 168/// If the value of the given expression is a NonLoc, copy it into a new 169/// temporary region, and replace the value of the expression with that. 170static ProgramStateRef createTemporaryRegionIfNeeded(ProgramStateRef State, 171 const LocationContext *LC, 172 const Expr *E) { 173 SVal V = State->getSVal(E, LC); 174 175 if (V.getAs<NonLoc>()) { 176 MemRegionManager &MRMgr = State->getStateManager().getRegionManager(); 177 const MemRegion *R = MRMgr.getCXXTempObjectRegion(E, LC); 178 State = State->bindLoc(loc::MemRegionVal(R), V); 179 State = State->BindExpr(E, LC, loc::MemRegionVal(R)); 180 } 181 182 return State; 183} 184 185//===----------------------------------------------------------------------===// 186// Top-level transfer function logic (Dispatcher). 187//===----------------------------------------------------------------------===// 188 189/// evalAssume - Called by ConstraintManager. Used to call checker-specific 190/// logic for handling assumptions on symbolic values. 191ProgramStateRef ExprEngine::processAssume(ProgramStateRef state, 192 SVal cond, bool assumption) { 193 return getCheckerManager().runCheckersForEvalAssume(state, cond, assumption); 194} 195 196bool ExprEngine::wantsRegionChangeUpdate(ProgramStateRef state) { 197 return getCheckerManager().wantsRegionChangeUpdate(state); 198} 199 200ProgramStateRef 201ExprEngine::processRegionChanges(ProgramStateRef state, 202 const InvalidatedSymbols *invalidated, 203 ArrayRef<const MemRegion *> Explicits, 204 ArrayRef<const MemRegion *> Regions, 205 const CallEvent *Call) { 206 return getCheckerManager().runCheckersForRegionChanges(state, invalidated, 207 Explicits, Regions, Call); 208} 209 210void ExprEngine::printState(raw_ostream &Out, ProgramStateRef State, 211 const char *NL, const char *Sep) { 212 getCheckerManager().runCheckersForPrintState(Out, State, NL, Sep); 213} 214 215void ExprEngine::processEndWorklist(bool hasWorkRemaining) { 216 getCheckerManager().runCheckersForEndAnalysis(G, BR, *this); 217} 218 219void ExprEngine::processCFGElement(const CFGElement E, ExplodedNode *Pred, 220 unsigned StmtIdx, NodeBuilderContext *Ctx) { 221 currStmtIdx = StmtIdx; 222 currBldrCtx = Ctx; 223 224 switch (E.getKind()) { 225 case CFGElement::Invalid: 226 llvm_unreachable("Unexpected CFGElement kind."); 227 case CFGElement::Statement: 228 ProcessStmt(const_cast<Stmt*>(E.getAs<CFGStmt>()->getStmt()), Pred); 229 return; 230 case CFGElement::Initializer: 231 ProcessInitializer(E.getAs<CFGInitializer>()->getInitializer(), Pred); 232 return; 233 case CFGElement::AutomaticObjectDtor: 234 case CFGElement::BaseDtor: 235 case CFGElement::MemberDtor: 236 case CFGElement::TemporaryDtor: 237 ProcessImplicitDtor(*E.getAs<CFGImplicitDtor>(), Pred); 238 return; 239 } 240 currBldrCtx = 0; 241} 242 243static bool shouldRemoveDeadBindings(AnalysisManager &AMgr, 244 const CFGStmt S, 245 const ExplodedNode *Pred, 246 const LocationContext *LC) { 247 248 // Are we never purging state values? 249 if (AMgr.options.AnalysisPurgeOpt == PurgeNone) 250 return false; 251 252 // Is this the beginning of a basic block? 253 if (isa<BlockEntrance>(Pred->getLocation())) 254 return true; 255 256 // Is this on a non-expression? 257 if (!isa<Expr>(S.getStmt())) 258 return true; 259 260 // Run before processing a call. 261 if (CallEvent::isCallStmt(S.getStmt())) 262 return true; 263 264 // Is this an expression that is consumed by another expression? If so, 265 // postpone cleaning out the state. 266 ParentMap &PM = LC->getAnalysisDeclContext()->getParentMap(); 267 return !PM.isConsumedExpr(cast<Expr>(S.getStmt())); 268} 269 270void ExprEngine::removeDead(ExplodedNode *Pred, ExplodedNodeSet &Out, 271 const Stmt *ReferenceStmt, 272 const LocationContext *LC, 273 const Stmt *DiagnosticStmt, 274 ProgramPoint::Kind K) { 275 assert((K == ProgramPoint::PreStmtPurgeDeadSymbolsKind || 276 ReferenceStmt == 0 || isa<ReturnStmt>(ReferenceStmt)) 277 && "PostStmt is not generally supported by the SymbolReaper yet"); 278 assert(LC && "Must pass the current (or expiring) LocationContext"); 279 280 if (!DiagnosticStmt) { 281 DiagnosticStmt = ReferenceStmt; 282 assert(DiagnosticStmt && "Required for clearing a LocationContext"); 283 } 284 285 NumRemoveDeadBindings++; 286 ProgramStateRef CleanedState = Pred->getState(); 287 288 // LC is the location context being destroyed, but SymbolReaper wants a 289 // location context that is still live. (If this is the top-level stack 290 // frame, this will be null.) 291 if (!ReferenceStmt) { 292 assert(K == ProgramPoint::PostStmtPurgeDeadSymbolsKind && 293 "Use PostStmtPurgeDeadSymbolsKind for clearing a LocationContext"); 294 LC = LC->getParent(); 295 } 296 297 const StackFrameContext *SFC = LC ? LC->getCurrentStackFrame() : 0; 298 SymbolReaper SymReaper(SFC, ReferenceStmt, SymMgr, getStoreManager()); 299 300 getCheckerManager().runCheckersForLiveSymbols(CleanedState, SymReaper); 301 302 // Create a state in which dead bindings are removed from the environment 303 // and the store. TODO: The function should just return new env and store, 304 // not a new state. 305 CleanedState = StateMgr.removeDeadBindings(CleanedState, SFC, SymReaper); 306 307 // Process any special transfer function for dead symbols. 308 // A tag to track convenience transitions, which can be removed at cleanup. 309 static SimpleProgramPointTag cleanupTag("ExprEngine : Clean Node"); 310 if (!SymReaper.hasDeadSymbols()) { 311 // Generate a CleanedNode that has the environment and store cleaned 312 // up. Since no symbols are dead, we can optimize and not clean out 313 // the constraint manager. 314 StmtNodeBuilder Bldr(Pred, Out, *currBldrCtx); 315 Bldr.generateNode(DiagnosticStmt, Pred, CleanedState, &cleanupTag, K); 316 317 } else { 318 // Call checkers with the non-cleaned state so that they could query the 319 // values of the soon to be dead symbols. 320 ExplodedNodeSet CheckedSet; 321 getCheckerManager().runCheckersForDeadSymbols(CheckedSet, Pred, SymReaper, 322 DiagnosticStmt, *this, K); 323 324 // For each node in CheckedSet, generate CleanedNodes that have the 325 // environment, the store, and the constraints cleaned up but have the 326 // user-supplied states as the predecessors. 327 StmtNodeBuilder Bldr(CheckedSet, Out, *currBldrCtx); 328 for (ExplodedNodeSet::const_iterator 329 I = CheckedSet.begin(), E = CheckedSet.end(); I != E; ++I) { 330 ProgramStateRef CheckerState = (*I)->getState(); 331 332 // The constraint manager has not been cleaned up yet, so clean up now. 333 CheckerState = getConstraintManager().removeDeadBindings(CheckerState, 334 SymReaper); 335 336 assert(StateMgr.haveEqualEnvironments(CheckerState, Pred->getState()) && 337 "Checkers are not allowed to modify the Environment as a part of " 338 "checkDeadSymbols processing."); 339 assert(StateMgr.haveEqualStores(CheckerState, Pred->getState()) && 340 "Checkers are not allowed to modify the Store as a part of " 341 "checkDeadSymbols processing."); 342 343 // Create a state based on CleanedState with CheckerState GDM and 344 // generate a transition to that state. 345 ProgramStateRef CleanedCheckerSt = 346 StateMgr.getPersistentStateWithGDM(CleanedState, CheckerState); 347 Bldr.generateNode(DiagnosticStmt, *I, CleanedCheckerSt, &cleanupTag, K); 348 } 349 } 350} 351 352void ExprEngine::ProcessStmt(const CFGStmt S, 353 ExplodedNode *Pred) { 354 // Reclaim any unnecessary nodes in the ExplodedGraph. 355 G.reclaimRecentlyAllocatedNodes(); 356 357 const Stmt *currStmt = S.getStmt(); 358 PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(), 359 currStmt->getLocStart(), 360 "Error evaluating statement"); 361 362 // Remove dead bindings and symbols. 363 ExplodedNodeSet CleanedStates; 364 if (shouldRemoveDeadBindings(AMgr, S, Pred, Pred->getLocationContext())){ 365 removeDead(Pred, CleanedStates, currStmt, Pred->getLocationContext()); 366 } else 367 CleanedStates.Add(Pred); 368 369 // Visit the statement. 370 ExplodedNodeSet Dst; 371 for (ExplodedNodeSet::iterator I = CleanedStates.begin(), 372 E = CleanedStates.end(); I != E; ++I) { 373 ExplodedNodeSet DstI; 374 // Visit the statement. 375 Visit(currStmt, *I, DstI); 376 Dst.insert(DstI); 377 } 378 379 // Enqueue the new nodes onto the work list. 380 Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx); 381} 382 383void ExprEngine::ProcessInitializer(const CFGInitializer Init, 384 ExplodedNode *Pred) { 385 const CXXCtorInitializer *BMI = Init.getInitializer(); 386 387 PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(), 388 BMI->getSourceLocation(), 389 "Error evaluating initializer"); 390 391 // We don't clean up dead bindings here. 392 const StackFrameContext *stackFrame = 393 cast<StackFrameContext>(Pred->getLocationContext()); 394 const CXXConstructorDecl *decl = 395 cast<CXXConstructorDecl>(stackFrame->getDecl()); 396 397 ProgramStateRef State = Pred->getState(); 398 SVal thisVal = State->getSVal(svalBuilder.getCXXThis(decl, stackFrame)); 399 400 PostInitializer PP(BMI, stackFrame); 401 ExplodedNodeSet Tmp(Pred); 402 403 // Evaluate the initializer, if necessary 404 if (BMI->isAnyMemberInitializer()) { 405 // Constructors build the object directly in the field, 406 // but non-objects must be copied in from the initializer. 407 const Expr *Init = BMI->getInit()->IgnoreImplicit(); 408 if (!isa<CXXConstructExpr>(Init)) { 409 SVal FieldLoc; 410 if (BMI->isIndirectMemberInitializer()) 411 FieldLoc = State->getLValue(BMI->getIndirectMember(), thisVal); 412 else 413 FieldLoc = State->getLValue(BMI->getMember(), thisVal); 414 415 SVal InitVal = State->getSVal(BMI->getInit(), stackFrame); 416 417 Tmp.clear(); 418 evalBind(Tmp, Init, Pred, FieldLoc, InitVal, /*isInit=*/true, &PP); 419 } 420 } else { 421 assert(BMI->isBaseInitializer() || BMI->isDelegatingInitializer()); 422 // We already did all the work when visiting the CXXConstructExpr. 423 } 424 425 // Construct PostInitializer nodes whether the state changed or not, 426 // so that the diagnostics don't get confused. 427 ExplodedNodeSet Dst; 428 NodeBuilder Bldr(Tmp, Dst, *currBldrCtx); 429 for (ExplodedNodeSet::iterator I = Tmp.begin(), E = Tmp.end(); I != E; ++I) { 430 ExplodedNode *N = *I; 431 Bldr.generateNode(PP, N->getState(), N); 432 } 433 434 // Enqueue the new nodes onto the work list. 435 Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx); 436} 437 438void ExprEngine::ProcessImplicitDtor(const CFGImplicitDtor D, 439 ExplodedNode *Pred) { 440 ExplodedNodeSet Dst; 441 switch (D.getKind()) { 442 case CFGElement::AutomaticObjectDtor: 443 ProcessAutomaticObjDtor(cast<CFGAutomaticObjDtor>(D), Pred, Dst); 444 break; 445 case CFGElement::BaseDtor: 446 ProcessBaseDtor(cast<CFGBaseDtor>(D), Pred, Dst); 447 break; 448 case CFGElement::MemberDtor: 449 ProcessMemberDtor(cast<CFGMemberDtor>(D), Pred, Dst); 450 break; 451 case CFGElement::TemporaryDtor: 452 ProcessTemporaryDtor(cast<CFGTemporaryDtor>(D), Pred, Dst); 453 break; 454 default: 455 llvm_unreachable("Unexpected dtor kind."); 456 } 457 458 // Enqueue the new nodes onto the work list. 459 Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx); 460} 461 462void ExprEngine::ProcessAutomaticObjDtor(const CFGAutomaticObjDtor Dtor, 463 ExplodedNode *Pred, 464 ExplodedNodeSet &Dst) { 465 ProgramStateRef state = Pred->getState(); 466 const VarDecl *varDecl = Dtor.getVarDecl(); 467 468 QualType varType = varDecl->getType(); 469 470 if (const ReferenceType *refType = varType->getAs<ReferenceType>()) 471 varType = refType->getPointeeType(); 472 473 Loc dest = state->getLValue(varDecl, Pred->getLocationContext()); 474 475 VisitCXXDestructor(varType, dest.castAs<loc::MemRegionVal>().getRegion(), 476 Dtor.getTriggerStmt(), /*IsBase=*/ false, Pred, Dst); 477} 478 479void ExprEngine::ProcessBaseDtor(const CFGBaseDtor D, 480 ExplodedNode *Pred, ExplodedNodeSet &Dst) { 481 const LocationContext *LCtx = Pred->getLocationContext(); 482 ProgramStateRef State = Pred->getState(); 483 484 const CXXDestructorDecl *CurDtor = cast<CXXDestructorDecl>(LCtx->getDecl()); 485 Loc ThisPtr = getSValBuilder().getCXXThis(CurDtor, 486 LCtx->getCurrentStackFrame()); 487 SVal ThisVal = Pred->getState()->getSVal(ThisPtr); 488 489 // Create the base object region. 490 QualType BaseTy = D.getBaseSpecifier()->getType(); 491 SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, BaseTy); 492 493 VisitCXXDestructor(BaseTy, BaseVal.castAs<loc::MemRegionVal>().getRegion(), 494 CurDtor->getBody(), /*IsBase=*/ true, Pred, Dst); 495} 496 497void ExprEngine::ProcessMemberDtor(const CFGMemberDtor D, 498 ExplodedNode *Pred, ExplodedNodeSet &Dst) { 499 const FieldDecl *Member = D.getFieldDecl(); 500 ProgramStateRef State = Pred->getState(); 501 const LocationContext *LCtx = Pred->getLocationContext(); 502 503 const CXXDestructorDecl *CurDtor = cast<CXXDestructorDecl>(LCtx->getDecl()); 504 Loc ThisVal = getSValBuilder().getCXXThis(CurDtor, 505 LCtx->getCurrentStackFrame()); 506 SVal FieldVal = 507 State->getLValue(Member, State->getSVal(ThisVal).castAs<Loc>()); 508 509 VisitCXXDestructor(Member->getType(), 510 FieldVal.castAs<loc::MemRegionVal>().getRegion(), 511 CurDtor->getBody(), /*IsBase=*/false, Pred, Dst); 512} 513 514void ExprEngine::ProcessTemporaryDtor(const CFGTemporaryDtor D, 515 ExplodedNode *Pred, 516 ExplodedNodeSet &Dst) {} 517 518void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, 519 ExplodedNodeSet &DstTop) { 520 PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(), 521 S->getLocStart(), 522 "Error evaluating statement"); 523 ExplodedNodeSet Dst; 524 StmtNodeBuilder Bldr(Pred, DstTop, *currBldrCtx); 525 526 assert(!isa<Expr>(S) || S == cast<Expr>(S)->IgnoreParens()); 527 528 switch (S->getStmtClass()) { 529 // C++ and ARC stuff we don't support yet. 530 case Expr::ObjCIndirectCopyRestoreExprClass: 531 case Stmt::CXXDependentScopeMemberExprClass: 532 case Stmt::CXXPseudoDestructorExprClass: 533 case Stmt::CXXTryStmtClass: 534 case Stmt::CXXTypeidExprClass: 535 case Stmt::CXXUuidofExprClass: 536 case Stmt::CXXUnresolvedConstructExprClass: 537 case Stmt::DependentScopeDeclRefExprClass: 538 case Stmt::UnaryTypeTraitExprClass: 539 case Stmt::BinaryTypeTraitExprClass: 540 case Stmt::TypeTraitExprClass: 541 case Stmt::ArrayTypeTraitExprClass: 542 case Stmt::ExpressionTraitExprClass: 543 case Stmt::UnresolvedLookupExprClass: 544 case Stmt::UnresolvedMemberExprClass: 545 case Stmt::CXXNoexceptExprClass: 546 case Stmt::PackExpansionExprClass: 547 case Stmt::SubstNonTypeTemplateParmPackExprClass: 548 case Stmt::FunctionParmPackExprClass: 549 case Stmt::SEHTryStmtClass: 550 case Stmt::SEHExceptStmtClass: 551 case Stmt::LambdaExprClass: 552 case Stmt::SEHFinallyStmtClass: { 553 const ExplodedNode *node = Bldr.generateSink(S, Pred, Pred->getState()); 554 Engine.addAbortedBlock(node, currBldrCtx->getBlock()); 555 break; 556 } 557 558 case Stmt::ParenExprClass: 559 llvm_unreachable("ParenExprs already handled."); 560 case Stmt::GenericSelectionExprClass: 561 llvm_unreachable("GenericSelectionExprs already handled."); 562 // Cases that should never be evaluated simply because they shouldn't 563 // appear in the CFG. 564 case Stmt::BreakStmtClass: 565 case Stmt::CaseStmtClass: 566 case Stmt::CompoundStmtClass: 567 case Stmt::ContinueStmtClass: 568 case Stmt::CXXForRangeStmtClass: 569 case Stmt::DefaultStmtClass: 570 case Stmt::DoStmtClass: 571 case Stmt::ForStmtClass: 572 case Stmt::GotoStmtClass: 573 case Stmt::IfStmtClass: 574 case Stmt::IndirectGotoStmtClass: 575 case Stmt::LabelStmtClass: 576 case Stmt::AttributedStmtClass: 577 case Stmt::NoStmtClass: 578 case Stmt::NullStmtClass: 579 case Stmt::SwitchStmtClass: 580 case Stmt::WhileStmtClass: 581 case Expr::MSDependentExistsStmtClass: 582 llvm_unreachable("Stmt should not be in analyzer evaluation loop"); 583 584 case Stmt::ObjCSubscriptRefExprClass: 585 case Stmt::ObjCPropertyRefExprClass: 586 llvm_unreachable("These are handled by PseudoObjectExpr"); 587 588 case Stmt::GNUNullExprClass: { 589 // GNU __null is a pointer-width integer, not an actual pointer. 590 ProgramStateRef state = Pred->getState(); 591 state = state->BindExpr(S, Pred->getLocationContext(), 592 svalBuilder.makeIntValWithPtrWidth(0, false)); 593 Bldr.generateNode(S, Pred, state); 594 break; 595 } 596 597 case Stmt::ObjCAtSynchronizedStmtClass: 598 Bldr.takeNodes(Pred); 599 VisitObjCAtSynchronizedStmt(cast<ObjCAtSynchronizedStmt>(S), Pred, Dst); 600 Bldr.addNodes(Dst); 601 break; 602 603 case Stmt::ExprWithCleanupsClass: 604 // Handled due to fully linearised CFG. 605 break; 606 607 // Cases not handled yet; but will handle some day. 608 case Stmt::DesignatedInitExprClass: 609 case Stmt::ExtVectorElementExprClass: 610 case Stmt::ImaginaryLiteralClass: 611 case Stmt::ObjCAtCatchStmtClass: 612 case Stmt::ObjCAtFinallyStmtClass: 613 case Stmt::ObjCAtTryStmtClass: 614 case Stmt::ObjCAutoreleasePoolStmtClass: 615 case Stmt::ObjCEncodeExprClass: 616 case Stmt::ObjCIsaExprClass: 617 case Stmt::ObjCProtocolExprClass: 618 case Stmt::ObjCSelectorExprClass: 619 case Stmt::ParenListExprClass: 620 case Stmt::PredefinedExprClass: 621 case Stmt::ShuffleVectorExprClass: 622 case Stmt::VAArgExprClass: 623 case Stmt::CUDAKernelCallExprClass: 624 case Stmt::OpaqueValueExprClass: 625 case Stmt::AsTypeExprClass: 626 case Stmt::AtomicExprClass: 627 // Fall through. 628 629 // Cases we intentionally don't evaluate, since they don't need 630 // to be explicitly evaluated. 631 case Stmt::AddrLabelExprClass: 632 case Stmt::IntegerLiteralClass: 633 case Stmt::CharacterLiteralClass: 634 case Stmt::ImplicitValueInitExprClass: 635 case Stmt::CXXScalarValueInitExprClass: 636 case Stmt::CXXBoolLiteralExprClass: 637 case Stmt::ObjCBoolLiteralExprClass: 638 case Stmt::FloatingLiteralClass: 639 case Stmt::SizeOfPackExprClass: 640 case Stmt::StringLiteralClass: 641 case Stmt::ObjCStringLiteralClass: 642 case Stmt::CXXBindTemporaryExprClass: 643 case Stmt::SubstNonTypeTemplateParmExprClass: 644 case Stmt::CXXNullPtrLiteralExprClass: { 645 Bldr.takeNodes(Pred); 646 ExplodedNodeSet preVisit; 647 getCheckerManager().runCheckersForPreStmt(preVisit, Pred, S, *this); 648 getCheckerManager().runCheckersForPostStmt(Dst, preVisit, S, *this); 649 Bldr.addNodes(Dst); 650 break; 651 } 652 653 case Stmt::CXXDefaultArgExprClass: { 654 Bldr.takeNodes(Pred); 655 ExplodedNodeSet PreVisit; 656 getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this); 657 658 ExplodedNodeSet Tmp; 659 StmtNodeBuilder Bldr2(PreVisit, Tmp, *currBldrCtx); 660 661 const LocationContext *LCtx = Pred->getLocationContext(); 662 const Expr *ArgE = cast<CXXDefaultArgExpr>(S)->getExpr(); 663 664 // Avoid creating and destroying a lot of APSInts. 665 SVal V; 666 llvm::APSInt Result; 667 668 for (ExplodedNodeSet::iterator I = PreVisit.begin(), E = PreVisit.end(); 669 I != E; ++I) { 670 ProgramStateRef State = (*I)->getState(); 671 672 if (ArgE->EvaluateAsInt(Result, getContext())) 673 V = svalBuilder.makeIntVal(Result); 674 else 675 V = State->getSVal(ArgE, LCtx); 676 677 State = State->BindExpr(S, LCtx, V); 678 Bldr2.generateNode(S, *I, State); 679 } 680 681 getCheckerManager().runCheckersForPostStmt(Dst, Tmp, S, *this); 682 Bldr.addNodes(Dst); 683 break; 684 } 685 686 case Expr::ObjCArrayLiteralClass: 687 case Expr::ObjCDictionaryLiteralClass: 688 // FIXME: explicitly model with a region and the actual contents 689 // of the container. For now, conjure a symbol. 690 case Expr::ObjCBoxedExprClass: { 691 Bldr.takeNodes(Pred); 692 693 ExplodedNodeSet preVisit; 694 getCheckerManager().runCheckersForPreStmt(preVisit, Pred, S, *this); 695 696 ExplodedNodeSet Tmp; 697 StmtNodeBuilder Bldr2(preVisit, Tmp, *currBldrCtx); 698 699 const Expr *Ex = cast<Expr>(S); 700 QualType resultType = Ex->getType(); 701 702 for (ExplodedNodeSet::iterator it = preVisit.begin(), et = preVisit.end(); 703 it != et; ++it) { 704 ExplodedNode *N = *it; 705 const LocationContext *LCtx = N->getLocationContext(); 706 SVal result = svalBuilder.conjureSymbolVal(0, Ex, LCtx, resultType, 707 currBldrCtx->blockCount()); 708 ProgramStateRef state = N->getState()->BindExpr(Ex, LCtx, result); 709 Bldr2.generateNode(S, N, state); 710 } 711 712 getCheckerManager().runCheckersForPostStmt(Dst, Tmp, S, *this); 713 Bldr.addNodes(Dst); 714 break; 715 } 716 717 case Stmt::ArraySubscriptExprClass: 718 Bldr.takeNodes(Pred); 719 VisitLvalArraySubscriptExpr(cast<ArraySubscriptExpr>(S), Pred, Dst); 720 Bldr.addNodes(Dst); 721 break; 722 723 case Stmt::GCCAsmStmtClass: 724 Bldr.takeNodes(Pred); 725 VisitGCCAsmStmt(cast<GCCAsmStmt>(S), Pred, Dst); 726 Bldr.addNodes(Dst); 727 break; 728 729 case Stmt::MSAsmStmtClass: 730 Bldr.takeNodes(Pred); 731 VisitMSAsmStmt(cast<MSAsmStmt>(S), Pred, Dst); 732 Bldr.addNodes(Dst); 733 break; 734 735 case Stmt::BlockExprClass: 736 Bldr.takeNodes(Pred); 737 VisitBlockExpr(cast<BlockExpr>(S), Pred, Dst); 738 Bldr.addNodes(Dst); 739 break; 740 741 case Stmt::BinaryOperatorClass: { 742 const BinaryOperator* B = cast<BinaryOperator>(S); 743 if (B->isLogicalOp()) { 744 Bldr.takeNodes(Pred); 745 VisitLogicalExpr(B, Pred, Dst); 746 Bldr.addNodes(Dst); 747 break; 748 } 749 else if (B->getOpcode() == BO_Comma) { 750 ProgramStateRef state = Pred->getState(); 751 Bldr.generateNode(B, Pred, 752 state->BindExpr(B, Pred->getLocationContext(), 753 state->getSVal(B->getRHS(), 754 Pred->getLocationContext()))); 755 break; 756 } 757 758 Bldr.takeNodes(Pred); 759 760 if (AMgr.options.eagerlyAssumeBinOpBifurcation && 761 (B->isRelationalOp() || B->isEqualityOp())) { 762 ExplodedNodeSet Tmp; 763 VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Tmp); 764 evalEagerlyAssumeBinOpBifurcation(Dst, Tmp, cast<Expr>(S)); 765 } 766 else 767 VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst); 768 769 Bldr.addNodes(Dst); 770 break; 771 } 772 773 case Stmt::CXXOperatorCallExprClass: { 774 const CXXOperatorCallExpr *OCE = cast<CXXOperatorCallExpr>(S); 775 776 // For instance method operators, make sure the 'this' argument has a 777 // valid region. 778 const Decl *Callee = OCE->getCalleeDecl(); 779 if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(Callee)) { 780 if (MD->isInstance()) { 781 ProgramStateRef State = Pred->getState(); 782 const LocationContext *LCtx = Pred->getLocationContext(); 783 ProgramStateRef NewState = 784 createTemporaryRegionIfNeeded(State, LCtx, OCE->getArg(0)); 785 if (NewState != State) 786 Pred = Bldr.generateNode(OCE, Pred, NewState, /*Tag=*/0, 787 ProgramPoint::PreStmtKind); 788 } 789 } 790 // FALLTHROUGH 791 } 792 case Stmt::CallExprClass: 793 case Stmt::CXXMemberCallExprClass: 794 case Stmt::UserDefinedLiteralClass: { 795 Bldr.takeNodes(Pred); 796 VisitCallExpr(cast<CallExpr>(S), Pred, Dst); 797 Bldr.addNodes(Dst); 798 break; 799 } 800 801 case Stmt::CXXCatchStmtClass: { 802 Bldr.takeNodes(Pred); 803 VisitCXXCatchStmt(cast<CXXCatchStmt>(S), Pred, Dst); 804 Bldr.addNodes(Dst); 805 break; 806 } 807 808 case Stmt::CXXTemporaryObjectExprClass: 809 case Stmt::CXXConstructExprClass: { 810 Bldr.takeNodes(Pred); 811 VisitCXXConstructExpr(cast<CXXConstructExpr>(S), Pred, Dst); 812 Bldr.addNodes(Dst); 813 break; 814 } 815 816 case Stmt::CXXNewExprClass: { 817 Bldr.takeNodes(Pred); 818 ExplodedNodeSet PostVisit; 819 VisitCXXNewExpr(cast<CXXNewExpr>(S), Pred, PostVisit); 820 getCheckerManager().runCheckersForPostStmt(Dst, PostVisit, S, *this); 821 Bldr.addNodes(Dst); 822 break; 823 } 824 825 case Stmt::CXXDeleteExprClass: { 826 Bldr.takeNodes(Pred); 827 ExplodedNodeSet PreVisit; 828 const CXXDeleteExpr *CDE = cast<CXXDeleteExpr>(S); 829 getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this); 830 831 for (ExplodedNodeSet::iterator i = PreVisit.begin(), 832 e = PreVisit.end(); i != e ; ++i) 833 VisitCXXDeleteExpr(CDE, *i, Dst); 834 835 Bldr.addNodes(Dst); 836 break; 837 } 838 // FIXME: ChooseExpr is really a constant. We need to fix 839 // the CFG do not model them as explicit control-flow. 840 841 case Stmt::ChooseExprClass: { // __builtin_choose_expr 842 Bldr.takeNodes(Pred); 843 const ChooseExpr *C = cast<ChooseExpr>(S); 844 VisitGuardedExpr(C, C->getLHS(), C->getRHS(), Pred, Dst); 845 Bldr.addNodes(Dst); 846 break; 847 } 848 849 case Stmt::CompoundAssignOperatorClass: 850 Bldr.takeNodes(Pred); 851 VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst); 852 Bldr.addNodes(Dst); 853 break; 854 855 case Stmt::CompoundLiteralExprClass: 856 Bldr.takeNodes(Pred); 857 VisitCompoundLiteralExpr(cast<CompoundLiteralExpr>(S), Pred, Dst); 858 Bldr.addNodes(Dst); 859 break; 860 861 case Stmt::BinaryConditionalOperatorClass: 862 case Stmt::ConditionalOperatorClass: { // '?' operator 863 Bldr.takeNodes(Pred); 864 const AbstractConditionalOperator *C 865 = cast<AbstractConditionalOperator>(S); 866 VisitGuardedExpr(C, C->getTrueExpr(), C->getFalseExpr(), Pred, Dst); 867 Bldr.addNodes(Dst); 868 break; 869 } 870 871 case Stmt::CXXThisExprClass: 872 Bldr.takeNodes(Pred); 873 VisitCXXThisExpr(cast<CXXThisExpr>(S), Pred, Dst); 874 Bldr.addNodes(Dst); 875 break; 876 877 case Stmt::DeclRefExprClass: { 878 Bldr.takeNodes(Pred); 879 const DeclRefExpr *DE = cast<DeclRefExpr>(S); 880 VisitCommonDeclRefExpr(DE, DE->getDecl(), Pred, Dst); 881 Bldr.addNodes(Dst); 882 break; 883 } 884 885 case Stmt::DeclStmtClass: 886 Bldr.takeNodes(Pred); 887 VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst); 888 Bldr.addNodes(Dst); 889 break; 890 891 case Stmt::ImplicitCastExprClass: 892 case Stmt::CStyleCastExprClass: 893 case Stmt::CXXStaticCastExprClass: 894 case Stmt::CXXDynamicCastExprClass: 895 case Stmt::CXXReinterpretCastExprClass: 896 case Stmt::CXXConstCastExprClass: 897 case Stmt::CXXFunctionalCastExprClass: 898 case Stmt::ObjCBridgedCastExprClass: { 899 Bldr.takeNodes(Pred); 900 const CastExpr *C = cast<CastExpr>(S); 901 // Handle the previsit checks. 902 ExplodedNodeSet dstPrevisit; 903 getCheckerManager().runCheckersForPreStmt(dstPrevisit, Pred, C, *this); 904 905 // Handle the expression itself. 906 ExplodedNodeSet dstExpr; 907 for (ExplodedNodeSet::iterator i = dstPrevisit.begin(), 908 e = dstPrevisit.end(); i != e ; ++i) { 909 VisitCast(C, C->getSubExpr(), *i, dstExpr); 910 } 911 912 // Handle the postvisit checks. 913 getCheckerManager().runCheckersForPostStmt(Dst, dstExpr, C, *this); 914 Bldr.addNodes(Dst); 915 break; 916 } 917 918 case Expr::MaterializeTemporaryExprClass: { 919 Bldr.takeNodes(Pred); 920 const MaterializeTemporaryExpr *MTE = cast<MaterializeTemporaryExpr>(S); 921 CreateCXXTemporaryObject(MTE, Pred, Dst); 922 Bldr.addNodes(Dst); 923 break; 924 } 925 926 case Stmt::InitListExprClass: 927 Bldr.takeNodes(Pred); 928 VisitInitListExpr(cast<InitListExpr>(S), Pred, Dst); 929 Bldr.addNodes(Dst); 930 break; 931 932 case Stmt::MemberExprClass: 933 Bldr.takeNodes(Pred); 934 VisitMemberExpr(cast<MemberExpr>(S), Pred, Dst); 935 Bldr.addNodes(Dst); 936 break; 937 938 case Stmt::ObjCIvarRefExprClass: 939 Bldr.takeNodes(Pred); 940 VisitLvalObjCIvarRefExpr(cast<ObjCIvarRefExpr>(S), Pred, Dst); 941 Bldr.addNodes(Dst); 942 break; 943 944 case Stmt::ObjCForCollectionStmtClass: 945 Bldr.takeNodes(Pred); 946 VisitObjCForCollectionStmt(cast<ObjCForCollectionStmt>(S), Pred, Dst); 947 Bldr.addNodes(Dst); 948 break; 949 950 case Stmt::ObjCMessageExprClass: 951 Bldr.takeNodes(Pred); 952 VisitObjCMessage(cast<ObjCMessageExpr>(S), Pred, Dst); 953 Bldr.addNodes(Dst); 954 break; 955 956 case Stmt::ObjCAtThrowStmtClass: 957 case Stmt::CXXThrowExprClass: 958 // FIXME: This is not complete. We basically treat @throw as 959 // an abort. 960 Bldr.generateSink(S, Pred, Pred->getState()); 961 break; 962 963 case Stmt::ReturnStmtClass: 964 Bldr.takeNodes(Pred); 965 VisitReturnStmt(cast<ReturnStmt>(S), Pred, Dst); 966 Bldr.addNodes(Dst); 967 break; 968 969 case Stmt::OffsetOfExprClass: 970 Bldr.takeNodes(Pred); 971 VisitOffsetOfExpr(cast<OffsetOfExpr>(S), Pred, Dst); 972 Bldr.addNodes(Dst); 973 break; 974 975 case Stmt::UnaryExprOrTypeTraitExprClass: 976 Bldr.takeNodes(Pred); 977 VisitUnaryExprOrTypeTraitExpr(cast<UnaryExprOrTypeTraitExpr>(S), 978 Pred, Dst); 979 Bldr.addNodes(Dst); 980 break; 981 982 case Stmt::StmtExprClass: { 983 const StmtExpr *SE = cast<StmtExpr>(S); 984 985 if (SE->getSubStmt()->body_empty()) { 986 // Empty statement expression. 987 assert(SE->getType() == getContext().VoidTy 988 && "Empty statement expression must have void type."); 989 break; 990 } 991 992 if (Expr *LastExpr = dyn_cast<Expr>(*SE->getSubStmt()->body_rbegin())) { 993 ProgramStateRef state = Pred->getState(); 994 Bldr.generateNode(SE, Pred, 995 state->BindExpr(SE, Pred->getLocationContext(), 996 state->getSVal(LastExpr, 997 Pred->getLocationContext()))); 998 } 999 break; 1000 } 1001 1002 case Stmt::UnaryOperatorClass: { 1003 Bldr.takeNodes(Pred); 1004 const UnaryOperator *U = cast<UnaryOperator>(S); 1005 if (AMgr.options.eagerlyAssumeBinOpBifurcation && (U->getOpcode() == UO_LNot)) { 1006 ExplodedNodeSet Tmp; 1007 VisitUnaryOperator(U, Pred, Tmp); 1008 evalEagerlyAssumeBinOpBifurcation(Dst, Tmp, U); 1009 } 1010 else 1011 VisitUnaryOperator(U, Pred, Dst); 1012 Bldr.addNodes(Dst); 1013 break; 1014 } 1015 1016 case Stmt::PseudoObjectExprClass: { 1017 Bldr.takeNodes(Pred); 1018 ProgramStateRef state = Pred->getState(); 1019 const PseudoObjectExpr *PE = cast<PseudoObjectExpr>(S); 1020 if (const Expr *Result = PE->getResultExpr()) { 1021 SVal V = state->getSVal(Result, Pred->getLocationContext()); 1022 Bldr.generateNode(S, Pred, 1023 state->BindExpr(S, Pred->getLocationContext(), V)); 1024 } 1025 else 1026 Bldr.generateNode(S, Pred, 1027 state->BindExpr(S, Pred->getLocationContext(), 1028 UnknownVal())); 1029 1030 Bldr.addNodes(Dst); 1031 break; 1032 } 1033 } 1034} 1035 1036bool ExprEngine::replayWithoutInlining(ExplodedNode *N, 1037 const LocationContext *CalleeLC) { 1038 const StackFrameContext *CalleeSF = CalleeLC->getCurrentStackFrame(); 1039 const StackFrameContext *CallerSF = CalleeSF->getParent()->getCurrentStackFrame(); 1040 assert(CalleeSF && CallerSF); 1041 ExplodedNode *BeforeProcessingCall = 0; 1042 const Stmt *CE = CalleeSF->getCallSite(); 1043 1044 // Find the first node before we started processing the call expression. 1045 while (N) { 1046 ProgramPoint L = N->getLocation(); 1047 BeforeProcessingCall = N; 1048 N = N->pred_empty() ? NULL : *(N->pred_begin()); 1049 1050 // Skip the nodes corresponding to the inlined code. 1051 if (L.getLocationContext()->getCurrentStackFrame() != CallerSF) 1052 continue; 1053 // We reached the caller. Find the node right before we started 1054 // processing the call. 1055 if (L.isPurgeKind()) 1056 continue; 1057 if (isa<PreImplicitCall>(&L)) 1058 continue; 1059 if (isa<CallEnter>(&L)) 1060 continue; 1061 if (const StmtPoint *SP = dyn_cast<StmtPoint>(&L)) 1062 if (SP->getStmt() == CE) 1063 continue; 1064 break; 1065 } 1066 1067 if (!BeforeProcessingCall) 1068 return false; 1069 1070 // TODO: Clean up the unneeded nodes. 1071 1072 // Build an Epsilon node from which we will restart the analyzes. 1073 // Note that CE is permitted to be NULL! 1074 ProgramPoint NewNodeLoc = 1075 EpsilonPoint(BeforeProcessingCall->getLocationContext(), CE); 1076 // Add the special flag to GDM to signal retrying with no inlining. 1077 // Note, changing the state ensures that we are not going to cache out. 1078 ProgramStateRef NewNodeState = BeforeProcessingCall->getState(); 1079 NewNodeState = 1080 NewNodeState->set<ReplayWithoutInlining>(const_cast<Stmt *>(CE)); 1081 1082 // Make the new node a successor of BeforeProcessingCall. 1083 bool IsNew = false; 1084 ExplodedNode *NewNode = G.getNode(NewNodeLoc, NewNodeState, false, &IsNew); 1085 // We cached out at this point. Caching out is common due to us backtracking 1086 // from the inlined function, which might spawn several paths. 1087 if (!IsNew) 1088 return true; 1089 1090 NewNode->addPredecessor(BeforeProcessingCall, G); 1091 1092 // Add the new node to the work list. 1093 Engine.enqueueStmtNode(NewNode, CalleeSF->getCallSiteBlock(), 1094 CalleeSF->getIndex()); 1095 NumTimesRetriedWithoutInlining++; 1096 return true; 1097} 1098 1099/// Block entrance. (Update counters). 1100void ExprEngine::processCFGBlockEntrance(const BlockEdge &L, 1101 NodeBuilderWithSinks &nodeBuilder, 1102 ExplodedNode *Pred) { 1103 1104 // FIXME: Refactor this into a checker. 1105 if (nodeBuilder.getContext().blockCount() >= AMgr.options.maxBlockVisitOnPath) { 1106 static SimpleProgramPointTag tag("ExprEngine : Block count exceeded"); 1107 const ExplodedNode *Sink = 1108 nodeBuilder.generateSink(Pred->getState(), Pred, &tag); 1109 1110 // Check if we stopped at the top level function or not. 1111 // Root node should have the location context of the top most function. 1112 const LocationContext *CalleeLC = Pred->getLocation().getLocationContext(); 1113 const LocationContext *CalleeSF = CalleeLC->getCurrentStackFrame(); 1114 const LocationContext *RootLC = 1115 (*G.roots_begin())->getLocation().getLocationContext(); 1116 if (RootLC->getCurrentStackFrame() != CalleeSF) { 1117 Engine.FunctionSummaries->markReachedMaxBlockCount(CalleeSF->getDecl()); 1118 1119 // Re-run the call evaluation without inlining it, by storing the 1120 // no-inlining policy in the state and enqueuing the new work item on 1121 // the list. Replay should almost never fail. Use the stats to catch it 1122 // if it does. 1123 if ((!AMgr.options.NoRetryExhausted && 1124 replayWithoutInlining(Pred, CalleeLC))) 1125 return; 1126 NumMaxBlockCountReachedInInlined++; 1127 } else 1128 NumMaxBlockCountReached++; 1129 1130 // Make sink nodes as exhausted(for stats) only if retry failed. 1131 Engine.blocksExhausted.push_back(std::make_pair(L, Sink)); 1132 } 1133} 1134 1135//===----------------------------------------------------------------------===// 1136// Branch processing. 1137//===----------------------------------------------------------------------===// 1138 1139/// RecoverCastedSymbol - A helper function for ProcessBranch that is used 1140/// to try to recover some path-sensitivity for casts of symbolic 1141/// integers that promote their values (which are currently not tracked well). 1142/// This function returns the SVal bound to Condition->IgnoreCasts if all the 1143// cast(s) did was sign-extend the original value. 1144static SVal RecoverCastedSymbol(ProgramStateManager& StateMgr, 1145 ProgramStateRef state, 1146 const Stmt *Condition, 1147 const LocationContext *LCtx, 1148 ASTContext &Ctx) { 1149 1150 const Expr *Ex = dyn_cast<Expr>(Condition); 1151 if (!Ex) 1152 return UnknownVal(); 1153 1154 uint64_t bits = 0; 1155 bool bitsInit = false; 1156 1157 while (const CastExpr *CE = dyn_cast<CastExpr>(Ex)) { 1158 QualType T = CE->getType(); 1159 1160 if (!T->isIntegerType()) 1161 return UnknownVal(); 1162 1163 uint64_t newBits = Ctx.getTypeSize(T); 1164 if (!bitsInit || newBits < bits) { 1165 bitsInit = true; 1166 bits = newBits; 1167 } 1168 1169 Ex = CE->getSubExpr(); 1170 } 1171 1172 // We reached a non-cast. Is it a symbolic value? 1173 QualType T = Ex->getType(); 1174 1175 if (!bitsInit || !T->isIntegerType() || Ctx.getTypeSize(T) > bits) 1176 return UnknownVal(); 1177 1178 return state->getSVal(Ex, LCtx); 1179} 1180 1181static const Stmt *ResolveCondition(const Stmt *Condition, 1182 const CFGBlock *B) { 1183 if (const Expr *Ex = dyn_cast<Expr>(Condition)) 1184 Condition = Ex->IgnoreParens(); 1185 1186 const BinaryOperator *BO = dyn_cast<BinaryOperator>(Condition); 1187 if (!BO || !BO->isLogicalOp()) 1188 return Condition; 1189 1190 // For logical operations, we still have the case where some branches 1191 // use the traditional "merge" approach and others sink the branch 1192 // directly into the basic blocks representing the logical operation. 1193 // We need to distinguish between those two cases here. 1194 1195 // The invariants are still shifting, but it is possible that the 1196 // last element in a CFGBlock is not a CFGStmt. Look for the last 1197 // CFGStmt as the value of the condition. 1198 CFGBlock::const_reverse_iterator I = B->rbegin(), E = B->rend(); 1199 for (; I != E; ++I) { 1200 CFGElement Elem = *I; 1201 CFGStmt *CS = dyn_cast<CFGStmt>(&Elem); 1202 if (!CS) 1203 continue; 1204 if (CS->getStmt() != Condition) 1205 break; 1206 return Condition; 1207 } 1208 1209 assert(I != E); 1210 1211 while (Condition) { 1212 BO = dyn_cast<BinaryOperator>(Condition); 1213 if (!BO || !BO->isLogicalOp()) 1214 return Condition; 1215 Condition = BO->getRHS()->IgnoreParens(); 1216 } 1217 llvm_unreachable("could not resolve condition"); 1218} 1219 1220void ExprEngine::processBranch(const Stmt *Condition, const Stmt *Term, 1221 NodeBuilderContext& BldCtx, 1222 ExplodedNode *Pred, 1223 ExplodedNodeSet &Dst, 1224 const CFGBlock *DstT, 1225 const CFGBlock *DstF) { 1226 currBldrCtx = &BldCtx; 1227 1228 // Check for NULL conditions; e.g. "for(;;)" 1229 if (!Condition) { 1230 BranchNodeBuilder NullCondBldr(Pred, Dst, BldCtx, DstT, DstF); 1231 NullCondBldr.markInfeasible(false); 1232 NullCondBldr.generateNode(Pred->getState(), true, Pred); 1233 return; 1234 } 1235 1236 1237 // Resolve the condition in the precense of nested '||' and '&&'. 1238 if (const Expr *Ex = dyn_cast<Expr>(Condition)) 1239 Condition = Ex->IgnoreParens(); 1240 1241 Condition = ResolveCondition(Condition, BldCtx.getBlock()); 1242 PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(), 1243 Condition->getLocStart(), 1244 "Error evaluating branch"); 1245 1246 ExplodedNodeSet CheckersOutSet; 1247 getCheckerManager().runCheckersForBranchCondition(Condition, CheckersOutSet, 1248 Pred, *this); 1249 // We generated only sinks. 1250 if (CheckersOutSet.empty()) 1251 return; 1252 1253 BranchNodeBuilder builder(CheckersOutSet, Dst, BldCtx, DstT, DstF); 1254 for (NodeBuilder::iterator I = CheckersOutSet.begin(), 1255 E = CheckersOutSet.end(); E != I; ++I) { 1256 ExplodedNode *PredI = *I; 1257 1258 if (PredI->isSink()) 1259 continue; 1260 1261 ProgramStateRef PrevState = PredI->getState(); 1262 SVal X = PrevState->getSVal(Condition, PredI->getLocationContext()); 1263 1264 if (X.isUnknownOrUndef()) { 1265 // Give it a chance to recover from unknown. 1266 if (const Expr *Ex = dyn_cast<Expr>(Condition)) { 1267 if (Ex->getType()->isIntegerType()) { 1268 // Try to recover some path-sensitivity. Right now casts of symbolic 1269 // integers that promote their values are currently not tracked well. 1270 // If 'Condition' is such an expression, try and recover the 1271 // underlying value and use that instead. 1272 SVal recovered = RecoverCastedSymbol(getStateManager(), 1273 PrevState, Condition, 1274 PredI->getLocationContext(), 1275 getContext()); 1276 1277 if (!recovered.isUnknown()) { 1278 X = recovered; 1279 } 1280 } 1281 } 1282 } 1283 1284 // If the condition is still unknown, give up. 1285 if (X.isUnknownOrUndef()) { 1286 builder.generateNode(PrevState, true, PredI); 1287 builder.generateNode(PrevState, false, PredI); 1288 continue; 1289 } 1290 1291 DefinedSVal V = X.castAs<DefinedSVal>(); 1292 1293 ProgramStateRef StTrue, StFalse; 1294 tie(StTrue, StFalse) = PrevState->assume(V); 1295 1296 // Process the true branch. 1297 if (builder.isFeasible(true)) { 1298 if (StTrue) 1299 builder.generateNode(StTrue, true, PredI); 1300 else 1301 builder.markInfeasible(true); 1302 } 1303 1304 // Process the false branch. 1305 if (builder.isFeasible(false)) { 1306 if (StFalse) 1307 builder.generateNode(StFalse, false, PredI); 1308 else 1309 builder.markInfeasible(false); 1310 } 1311 } 1312 currBldrCtx = 0; 1313} 1314 1315/// processIndirectGoto - Called by CoreEngine. Used to generate successor 1316/// nodes by processing the 'effects' of a computed goto jump. 1317void ExprEngine::processIndirectGoto(IndirectGotoNodeBuilder &builder) { 1318 1319 ProgramStateRef state = builder.getState(); 1320 SVal V = state->getSVal(builder.getTarget(), builder.getLocationContext()); 1321 1322 // Three possibilities: 1323 // 1324 // (1) We know the computed label. 1325 // (2) The label is NULL (or some other constant), or Undefined. 1326 // (3) We have no clue about the label. Dispatch to all targets. 1327 // 1328 1329 typedef IndirectGotoNodeBuilder::iterator iterator; 1330 1331 if (Optional<loc::GotoLabel> LV = V.getAs<loc::GotoLabel>()) { 1332 const LabelDecl *L = LV->getLabel(); 1333 1334 for (iterator I = builder.begin(), E = builder.end(); I != E; ++I) { 1335 if (I.getLabel() == L) { 1336 builder.generateNode(I, state); 1337 return; 1338 } 1339 } 1340 1341 llvm_unreachable("No block with label."); 1342 } 1343 1344 if (V.getAs<loc::ConcreteInt>() || V.getAs<UndefinedVal>()) { 1345 // Dispatch to the first target and mark it as a sink. 1346 //ExplodedNode* N = builder.generateNode(builder.begin(), state, true); 1347 // FIXME: add checker visit. 1348 // UndefBranches.insert(N); 1349 return; 1350 } 1351 1352 // This is really a catch-all. We don't support symbolics yet. 1353 // FIXME: Implement dispatch for symbolic pointers. 1354 1355 for (iterator I=builder.begin(), E=builder.end(); I != E; ++I) 1356 builder.generateNode(I, state); 1357} 1358 1359/// ProcessEndPath - Called by CoreEngine. Used to generate end-of-path 1360/// nodes when the control reaches the end of a function. 1361void ExprEngine::processEndOfFunction(NodeBuilderContext& BC, 1362 ExplodedNode *Pred) { 1363 StateMgr.EndPath(Pred->getState()); 1364 1365 ExplodedNodeSet Dst; 1366 if (Pred->getLocationContext()->inTopFrame()) { 1367 // Remove dead symbols. 1368 ExplodedNodeSet AfterRemovedDead; 1369 removeDeadOnEndOfFunction(BC, Pred, AfterRemovedDead); 1370 1371 // Notify checkers. 1372 for (ExplodedNodeSet::iterator I = AfterRemovedDead.begin(), 1373 E = AfterRemovedDead.end(); I != E; ++I) { 1374 getCheckerManager().runCheckersForEndFunction(BC, Dst, *I, *this); 1375 } 1376 } else { 1377 getCheckerManager().runCheckersForEndFunction(BC, Dst, Pred, *this); 1378 } 1379 1380 Engine.enqueueEndOfFunction(Dst); 1381} 1382 1383/// ProcessSwitch - Called by CoreEngine. Used to generate successor 1384/// nodes by processing the 'effects' of a switch statement. 1385void ExprEngine::processSwitch(SwitchNodeBuilder& builder) { 1386 typedef SwitchNodeBuilder::iterator iterator; 1387 ProgramStateRef state = builder.getState(); 1388 const Expr *CondE = builder.getCondition(); 1389 SVal CondV_untested = state->getSVal(CondE, builder.getLocationContext()); 1390 1391 if (CondV_untested.isUndef()) { 1392 //ExplodedNode* N = builder.generateDefaultCaseNode(state, true); 1393 // FIXME: add checker 1394 //UndefBranches.insert(N); 1395 1396 return; 1397 } 1398 DefinedOrUnknownSVal CondV = CondV_untested.castAs<DefinedOrUnknownSVal>(); 1399 1400 ProgramStateRef DefaultSt = state; 1401 1402 iterator I = builder.begin(), EI = builder.end(); 1403 bool defaultIsFeasible = I == EI; 1404 1405 for ( ; I != EI; ++I) { 1406 // Successor may be pruned out during CFG construction. 1407 if (!I.getBlock()) 1408 continue; 1409 1410 const CaseStmt *Case = I.getCase(); 1411 1412 // Evaluate the LHS of the case value. 1413 llvm::APSInt V1 = Case->getLHS()->EvaluateKnownConstInt(getContext()); 1414 assert(V1.getBitWidth() == getContext().getTypeSize(CondE->getType())); 1415 1416 // Get the RHS of the case, if it exists. 1417 llvm::APSInt V2; 1418 if (const Expr *E = Case->getRHS()) 1419 V2 = E->EvaluateKnownConstInt(getContext()); 1420 else 1421 V2 = V1; 1422 1423 // FIXME: Eventually we should replace the logic below with a range 1424 // comparison, rather than concretize the values within the range. 1425 // This should be easy once we have "ranges" for NonLVals. 1426 1427 do { 1428 nonloc::ConcreteInt CaseVal(getBasicVals().getValue(V1)); 1429 DefinedOrUnknownSVal Res = svalBuilder.evalEQ(DefaultSt ? DefaultSt : state, 1430 CondV, CaseVal); 1431 1432 // Now "assume" that the case matches. 1433 if (ProgramStateRef stateNew = state->assume(Res, true)) { 1434 builder.generateCaseStmtNode(I, stateNew); 1435 1436 // If CondV evaluates to a constant, then we know that this 1437 // is the *only* case that we can take, so stop evaluating the 1438 // others. 1439 if (CondV.getAs<nonloc::ConcreteInt>()) 1440 return; 1441 } 1442 1443 // Now "assume" that the case doesn't match. Add this state 1444 // to the default state (if it is feasible). 1445 if (DefaultSt) { 1446 if (ProgramStateRef stateNew = DefaultSt->assume(Res, false)) { 1447 defaultIsFeasible = true; 1448 DefaultSt = stateNew; 1449 } 1450 else { 1451 defaultIsFeasible = false; 1452 DefaultSt = NULL; 1453 } 1454 } 1455 1456 // Concretize the next value in the range. 1457 if (V1 == V2) 1458 break; 1459 1460 ++V1; 1461 assert (V1 <= V2); 1462 1463 } while (true); 1464 } 1465 1466 if (!defaultIsFeasible) 1467 return; 1468 1469 // If we have switch(enum value), the default branch is not 1470 // feasible if all of the enum constants not covered by 'case:' statements 1471 // are not feasible values for the switch condition. 1472 // 1473 // Note that this isn't as accurate as it could be. Even if there isn't 1474 // a case for a particular enum value as long as that enum value isn't 1475 // feasible then it shouldn't be considered for making 'default:' reachable. 1476 const SwitchStmt *SS = builder.getSwitch(); 1477 const Expr *CondExpr = SS->getCond()->IgnoreParenImpCasts(); 1478 if (CondExpr->getType()->getAs<EnumType>()) { 1479 if (SS->isAllEnumCasesCovered()) 1480 return; 1481 } 1482 1483 builder.generateDefaultCaseNode(DefaultSt); 1484} 1485 1486//===----------------------------------------------------------------------===// 1487// Transfer functions: Loads and stores. 1488//===----------------------------------------------------------------------===// 1489 1490void ExprEngine::VisitCommonDeclRefExpr(const Expr *Ex, const NamedDecl *D, 1491 ExplodedNode *Pred, 1492 ExplodedNodeSet &Dst) { 1493 StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 1494 1495 ProgramStateRef state = Pred->getState(); 1496 const LocationContext *LCtx = Pred->getLocationContext(); 1497 1498 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 1499 assert(Ex->isGLValue()); 1500 SVal V = state->getLValue(VD, Pred->getLocationContext()); 1501 1502 // For references, the 'lvalue' is the pointer address stored in the 1503 // reference region. 1504 if (VD->getType()->isReferenceType()) { 1505 if (const MemRegion *R = V.getAsRegion()) 1506 V = state->getSVal(R); 1507 else 1508 V = UnknownVal(); 1509 } 1510 1511 Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), 0, 1512 ProgramPoint::PostLValueKind); 1513 return; 1514 } 1515 if (const EnumConstantDecl *ED = dyn_cast<EnumConstantDecl>(D)) { 1516 assert(!Ex->isGLValue()); 1517 SVal V = svalBuilder.makeIntVal(ED->getInitVal()); 1518 Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V)); 1519 return; 1520 } 1521 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 1522 SVal V = svalBuilder.getFunctionPointer(FD); 1523 Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), 0, 1524 ProgramPoint::PostLValueKind); 1525 return; 1526 } 1527 if (isa<FieldDecl>(D)) { 1528 // FIXME: Compute lvalue of field pointers-to-member. 1529 // Right now we just use a non-null void pointer, so that it gives proper 1530 // results in boolean contexts. 1531 SVal V = svalBuilder.conjureSymbolVal(Ex, LCtx, getContext().VoidPtrTy, 1532 currBldrCtx->blockCount()); 1533 state = state->assume(V.castAs<DefinedOrUnknownSVal>(), true); 1534 Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), 0, 1535 ProgramPoint::PostLValueKind); 1536 return; 1537 } 1538 1539 llvm_unreachable("Support for this Decl not implemented."); 1540} 1541 1542/// VisitArraySubscriptExpr - Transfer function for array accesses 1543void ExprEngine::VisitLvalArraySubscriptExpr(const ArraySubscriptExpr *A, 1544 ExplodedNode *Pred, 1545 ExplodedNodeSet &Dst){ 1546 1547 const Expr *Base = A->getBase()->IgnoreParens(); 1548 const Expr *Idx = A->getIdx()->IgnoreParens(); 1549 1550 1551 ExplodedNodeSet checkerPreStmt; 1552 getCheckerManager().runCheckersForPreStmt(checkerPreStmt, Pred, A, *this); 1553 1554 StmtNodeBuilder Bldr(checkerPreStmt, Dst, *currBldrCtx); 1555 1556 for (ExplodedNodeSet::iterator it = checkerPreStmt.begin(), 1557 ei = checkerPreStmt.end(); it != ei; ++it) { 1558 const LocationContext *LCtx = (*it)->getLocationContext(); 1559 ProgramStateRef state = (*it)->getState(); 1560 SVal V = state->getLValue(A->getType(), 1561 state->getSVal(Idx, LCtx), 1562 state->getSVal(Base, LCtx)); 1563 assert(A->isGLValue()); 1564 Bldr.generateNode(A, *it, state->BindExpr(A, LCtx, V), 0, 1565 ProgramPoint::PostLValueKind); 1566 } 1567} 1568 1569/// VisitMemberExpr - Transfer function for member expressions. 1570void ExprEngine::VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred, 1571 ExplodedNodeSet &TopDst) { 1572 1573 StmtNodeBuilder Bldr(Pred, TopDst, *currBldrCtx); 1574 ExplodedNodeSet Dst; 1575 ValueDecl *Member = M->getMemberDecl(); 1576 1577 // Handle static member variables and enum constants accessed via 1578 // member syntax. 1579 if (isa<VarDecl>(Member) || isa<EnumConstantDecl>(Member)) { 1580 Bldr.takeNodes(Pred); 1581 VisitCommonDeclRefExpr(M, Member, Pred, Dst); 1582 Bldr.addNodes(Dst); 1583 return; 1584 } 1585 1586 ProgramStateRef state = Pred->getState(); 1587 const LocationContext *LCtx = Pred->getLocationContext(); 1588 Expr *BaseExpr = M->getBase(); 1589 1590 // Handle C++ method calls. 1591 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Member)) { 1592 if (MD->isInstance()) 1593 state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr); 1594 1595 SVal MDVal = svalBuilder.getFunctionPointer(MD); 1596 state = state->BindExpr(M, LCtx, MDVal); 1597 1598 Bldr.generateNode(M, Pred, state); 1599 return; 1600 } 1601 1602 // Handle regular struct fields / member variables. 1603 state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr); 1604 SVal baseExprVal = state->getSVal(BaseExpr, LCtx); 1605 1606 FieldDecl *field = cast<FieldDecl>(Member); 1607 SVal L = state->getLValue(field, baseExprVal); 1608 if (M->isGLValue()) { 1609 if (field->getType()->isReferenceType()) { 1610 if (const MemRegion *R = L.getAsRegion()) 1611 L = state->getSVal(R); 1612 else 1613 L = UnknownVal(); 1614 } 1615 1616 Bldr.generateNode(M, Pred, state->BindExpr(M, LCtx, L), 0, 1617 ProgramPoint::PostLValueKind); 1618 } else { 1619 Bldr.takeNodes(Pred); 1620 evalLoad(Dst, M, M, Pred, state, L); 1621 Bldr.addNodes(Dst); 1622 } 1623} 1624 1625namespace { 1626class CollectReachableSymbolsCallback : public SymbolVisitor { 1627 InvalidatedSymbols Symbols; 1628public: 1629 CollectReachableSymbolsCallback(ProgramStateRef State) {} 1630 const InvalidatedSymbols &getSymbols() const { return Symbols; } 1631 1632 bool VisitSymbol(SymbolRef Sym) { 1633 Symbols.insert(Sym); 1634 return true; 1635 } 1636}; 1637} // end anonymous namespace 1638 1639// A value escapes in three possible cases: 1640// (1) We are binding to something that is not a memory region. 1641// (2) We are binding to a MemrRegion that does not have stack storage. 1642// (3) We are binding to a MemRegion with stack storage that the store 1643// does not understand. 1644ProgramStateRef ExprEngine::processPointerEscapedOnBind(ProgramStateRef State, 1645 SVal Loc, SVal Val) { 1646 // Are we storing to something that causes the value to "escape"? 1647 bool escapes = true; 1648 1649 // TODO: Move to StoreManager. 1650 if (Optional<loc::MemRegionVal> regionLoc = Loc.getAs<loc::MemRegionVal>()) { 1651 escapes = !regionLoc->getRegion()->hasStackStorage(); 1652 1653 if (!escapes) { 1654 // To test (3), generate a new state with the binding added. If it is 1655 // the same state, then it escapes (since the store cannot represent 1656 // the binding). 1657 // Do this only if we know that the store is not supposed to generate the 1658 // same state. 1659 SVal StoredVal = State->getSVal(regionLoc->getRegion()); 1660 if (StoredVal != Val) 1661 escapes = (State == (State->bindLoc(*regionLoc, Val))); 1662 } 1663 if (!escapes) { 1664 // Case 4: We do not currently model what happens when a symbol is 1665 // assigned to a struct field, so be conservative here and let the symbol 1666 // go. TODO: This could definitely be improved upon. 1667 escapes = !isa<VarRegion>(regionLoc->getRegion()); 1668 } 1669 } 1670 1671 // If our store can represent the binding and we aren't storing to something 1672 // that doesn't have local storage then just return and have the simulation 1673 // state continue as is. 1674 if (!escapes) 1675 return State; 1676 1677 // Otherwise, find all symbols referenced by 'val' that we are tracking 1678 // and stop tracking them. 1679 CollectReachableSymbolsCallback Scanner = 1680 State->scanReachableSymbols<CollectReachableSymbolsCallback>(Val); 1681 const InvalidatedSymbols &EscapedSymbols = Scanner.getSymbols(); 1682 State = getCheckerManager().runCheckersForPointerEscape(State, 1683 EscapedSymbols, 1684 /*CallEvent*/ 0, 1685 PSK_EscapeOnBind); 1686 1687 return State; 1688} 1689 1690ProgramStateRef 1691ExprEngine::processPointerEscapedOnInvalidateRegions(ProgramStateRef State, 1692 const InvalidatedSymbols *Invalidated, 1693 ArrayRef<const MemRegion *> ExplicitRegions, 1694 ArrayRef<const MemRegion *> Regions, 1695 const CallEvent *Call) { 1696 1697 if (!Invalidated || Invalidated->empty()) 1698 return State; 1699 1700 if (!Call) 1701 return getCheckerManager().runCheckersForPointerEscape(State, 1702 *Invalidated, 1703 0, 1704 PSK_EscapeOther); 1705 1706 // If the symbols were invalidated by a call, we want to find out which ones 1707 // were invalidated directly due to being arguments to the call. 1708 InvalidatedSymbols SymbolsDirectlyInvalidated; 1709 for (ArrayRef<const MemRegion *>::iterator I = ExplicitRegions.begin(), 1710 E = ExplicitRegions.end(); I != E; ++I) { 1711 if (const SymbolicRegion *R = (*I)->StripCasts()->getAs<SymbolicRegion>()) 1712 SymbolsDirectlyInvalidated.insert(R->getSymbol()); 1713 } 1714 1715 InvalidatedSymbols SymbolsIndirectlyInvalidated; 1716 for (InvalidatedSymbols::const_iterator I=Invalidated->begin(), 1717 E = Invalidated->end(); I!=E; ++I) { 1718 SymbolRef sym = *I; 1719 if (SymbolsDirectlyInvalidated.count(sym)) 1720 continue; 1721 SymbolsIndirectlyInvalidated.insert(sym); 1722 } 1723 1724 if (!SymbolsDirectlyInvalidated.empty()) 1725 State = getCheckerManager().runCheckersForPointerEscape(State, 1726 SymbolsDirectlyInvalidated, Call, PSK_DirectEscapeOnCall); 1727 1728 // Notify about the symbols that get indirectly invalidated by the call. 1729 if (!SymbolsIndirectlyInvalidated.empty()) 1730 State = getCheckerManager().runCheckersForPointerEscape(State, 1731 SymbolsIndirectlyInvalidated, Call, PSK_IndirectEscapeOnCall); 1732 1733 return State; 1734} 1735 1736/// evalBind - Handle the semantics of binding a value to a specific location. 1737/// This method is used by evalStore and (soon) VisitDeclStmt, and others. 1738void ExprEngine::evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE, 1739 ExplodedNode *Pred, 1740 SVal location, SVal Val, 1741 bool atDeclInit, const ProgramPoint *PP) { 1742 1743 const LocationContext *LC = Pred->getLocationContext(); 1744 PostStmt PS(StoreE, LC); 1745 if (!PP) 1746 PP = &PS; 1747 1748 // Do a previsit of the bind. 1749 ExplodedNodeSet CheckedSet; 1750 getCheckerManager().runCheckersForBind(CheckedSet, Pred, location, Val, 1751 StoreE, *this, *PP); 1752 1753 1754 StmtNodeBuilder Bldr(CheckedSet, Dst, *currBldrCtx); 1755 1756 // If the location is not a 'Loc', it will already be handled by 1757 // the checkers. There is nothing left to do. 1758 if (!location.getAs<Loc>()) { 1759 const ProgramPoint L = PostStore(StoreE, LC, /*Loc*/0, /*tag*/0); 1760 ProgramStateRef state = Pred->getState(); 1761 state = processPointerEscapedOnBind(state, location, Val); 1762 Bldr.generateNode(L, state, Pred); 1763 return; 1764 } 1765 1766 1767 for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end(); 1768 I!=E; ++I) { 1769 ExplodedNode *PredI = *I; 1770 ProgramStateRef state = PredI->getState(); 1771 1772 state = processPointerEscapedOnBind(state, location, Val); 1773 1774 // When binding the value, pass on the hint that this is a initialization. 1775 // For initializations, we do not need to inform clients of region 1776 // changes. 1777 state = state->bindLoc(location.castAs<Loc>(), 1778 Val, /* notifyChanges = */ !atDeclInit); 1779 1780 const MemRegion *LocReg = 0; 1781 if (Optional<loc::MemRegionVal> LocRegVal = 1782 location.getAs<loc::MemRegionVal>()) { 1783 LocReg = LocRegVal->getRegion(); 1784 } 1785 1786 const ProgramPoint L = PostStore(StoreE, LC, LocReg, 0); 1787 Bldr.generateNode(L, state, PredI); 1788 } 1789} 1790 1791/// evalStore - Handle the semantics of a store via an assignment. 1792/// @param Dst The node set to store generated state nodes 1793/// @param AssignE The assignment expression if the store happens in an 1794/// assignment. 1795/// @param LocationE The location expression that is stored to. 1796/// @param state The current simulation state 1797/// @param location The location to store the value 1798/// @param Val The value to be stored 1799void ExprEngine::evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, 1800 const Expr *LocationE, 1801 ExplodedNode *Pred, 1802 ProgramStateRef state, SVal location, SVal Val, 1803 const ProgramPointTag *tag) { 1804 // Proceed with the store. We use AssignE as the anchor for the PostStore 1805 // ProgramPoint if it is non-NULL, and LocationE otherwise. 1806 const Expr *StoreE = AssignE ? AssignE : LocationE; 1807 1808 // Evaluate the location (checks for bad dereferences). 1809 ExplodedNodeSet Tmp; 1810 evalLocation(Tmp, AssignE, LocationE, Pred, state, location, tag, false); 1811 1812 if (Tmp.empty()) 1813 return; 1814 1815 if (location.isUndef()) 1816 return; 1817 1818 for (ExplodedNodeSet::iterator NI=Tmp.begin(), NE=Tmp.end(); NI!=NE; ++NI) 1819 evalBind(Dst, StoreE, *NI, location, Val, false); 1820} 1821 1822void ExprEngine::evalLoad(ExplodedNodeSet &Dst, 1823 const Expr *NodeEx, 1824 const Expr *BoundEx, 1825 ExplodedNode *Pred, 1826 ProgramStateRef state, 1827 SVal location, 1828 const ProgramPointTag *tag, 1829 QualType LoadTy) 1830{ 1831 assert(!location.getAs<NonLoc>() && "location cannot be a NonLoc."); 1832 1833 // Are we loading from a region? This actually results in two loads; one 1834 // to fetch the address of the referenced value and one to fetch the 1835 // referenced value. 1836 if (const TypedValueRegion *TR = 1837 dyn_cast_or_null<TypedValueRegion>(location.getAsRegion())) { 1838 1839 QualType ValTy = TR->getValueType(); 1840 if (const ReferenceType *RT = ValTy->getAs<ReferenceType>()) { 1841 static SimpleProgramPointTag 1842 loadReferenceTag("ExprEngine : Load Reference"); 1843 ExplodedNodeSet Tmp; 1844 evalLoadCommon(Tmp, NodeEx, BoundEx, Pred, state, 1845 location, &loadReferenceTag, 1846 getContext().getPointerType(RT->getPointeeType())); 1847 1848 // Perform the load from the referenced value. 1849 for (ExplodedNodeSet::iterator I=Tmp.begin(), E=Tmp.end() ; I!=E; ++I) { 1850 state = (*I)->getState(); 1851 location = state->getSVal(BoundEx, (*I)->getLocationContext()); 1852 evalLoadCommon(Dst, NodeEx, BoundEx, *I, state, location, tag, LoadTy); 1853 } 1854 return; 1855 } 1856 } 1857 1858 evalLoadCommon(Dst, NodeEx, BoundEx, Pred, state, location, tag, LoadTy); 1859} 1860 1861void ExprEngine::evalLoadCommon(ExplodedNodeSet &Dst, 1862 const Expr *NodeEx, 1863 const Expr *BoundEx, 1864 ExplodedNode *Pred, 1865 ProgramStateRef state, 1866 SVal location, 1867 const ProgramPointTag *tag, 1868 QualType LoadTy) { 1869 assert(NodeEx); 1870 assert(BoundEx); 1871 // Evaluate the location (checks for bad dereferences). 1872 ExplodedNodeSet Tmp; 1873 evalLocation(Tmp, NodeEx, BoundEx, Pred, state, location, tag, true); 1874 if (Tmp.empty()) 1875 return; 1876 1877 StmtNodeBuilder Bldr(Tmp, Dst, *currBldrCtx); 1878 if (location.isUndef()) 1879 return; 1880 1881 // Proceed with the load. 1882 for (ExplodedNodeSet::iterator NI=Tmp.begin(), NE=Tmp.end(); NI!=NE; ++NI) { 1883 state = (*NI)->getState(); 1884 const LocationContext *LCtx = (*NI)->getLocationContext(); 1885 1886 SVal V = UnknownVal(); 1887 if (location.isValid()) { 1888 if (LoadTy.isNull()) 1889 LoadTy = BoundEx->getType(); 1890 V = state->getSVal(location.castAs<Loc>(), LoadTy); 1891 } 1892 1893 Bldr.generateNode(NodeEx, *NI, state->BindExpr(BoundEx, LCtx, V), tag, 1894 ProgramPoint::PostLoadKind); 1895 } 1896} 1897 1898void ExprEngine::evalLocation(ExplodedNodeSet &Dst, 1899 const Stmt *NodeEx, 1900 const Stmt *BoundEx, 1901 ExplodedNode *Pred, 1902 ProgramStateRef state, 1903 SVal location, 1904 const ProgramPointTag *tag, 1905 bool isLoad) { 1906 StmtNodeBuilder BldrTop(Pred, Dst, *currBldrCtx); 1907 // Early checks for performance reason. 1908 if (location.isUnknown()) { 1909 return; 1910 } 1911 1912 ExplodedNodeSet Src; 1913 BldrTop.takeNodes(Pred); 1914 StmtNodeBuilder Bldr(Pred, Src, *currBldrCtx); 1915 if (Pred->getState() != state) { 1916 // Associate this new state with an ExplodedNode. 1917 // FIXME: If I pass null tag, the graph is incorrect, e.g for 1918 // int *p; 1919 // p = 0; 1920 // *p = 0xDEADBEEF; 1921 // "p = 0" is not noted as "Null pointer value stored to 'p'" but 1922 // instead "int *p" is noted as 1923 // "Variable 'p' initialized to a null pointer value" 1924 1925 static SimpleProgramPointTag tag("ExprEngine: Location"); 1926 Bldr.generateNode(NodeEx, Pred, state, &tag); 1927 } 1928 ExplodedNodeSet Tmp; 1929 getCheckerManager().runCheckersForLocation(Tmp, Src, location, isLoad, 1930 NodeEx, BoundEx, *this); 1931 BldrTop.addNodes(Tmp); 1932} 1933 1934std::pair<const ProgramPointTag *, const ProgramPointTag*> 1935ExprEngine::geteagerlyAssumeBinOpBifurcationTags() { 1936 static SimpleProgramPointTag 1937 eagerlyAssumeBinOpBifurcationTrue("ExprEngine : Eagerly Assume True"), 1938 eagerlyAssumeBinOpBifurcationFalse("ExprEngine : Eagerly Assume False"); 1939 return std::make_pair(&eagerlyAssumeBinOpBifurcationTrue, 1940 &eagerlyAssumeBinOpBifurcationFalse); 1941} 1942 1943void ExprEngine::evalEagerlyAssumeBinOpBifurcation(ExplodedNodeSet &Dst, 1944 ExplodedNodeSet &Src, 1945 const Expr *Ex) { 1946 StmtNodeBuilder Bldr(Src, Dst, *currBldrCtx); 1947 1948 for (ExplodedNodeSet::iterator I=Src.begin(), E=Src.end(); I!=E; ++I) { 1949 ExplodedNode *Pred = *I; 1950 // Test if the previous node was as the same expression. This can happen 1951 // when the expression fails to evaluate to anything meaningful and 1952 // (as an optimization) we don't generate a node. 1953 ProgramPoint P = Pred->getLocation(); 1954 if (!isa<PostStmt>(P) || cast<PostStmt>(P).getStmt() != Ex) { 1955 continue; 1956 } 1957 1958 ProgramStateRef state = Pred->getState(); 1959 SVal V = state->getSVal(Ex, Pred->getLocationContext()); 1960 Optional<nonloc::SymbolVal> SEV = V.getAs<nonloc::SymbolVal>(); 1961 if (SEV && SEV->isExpression()) { 1962 const std::pair<const ProgramPointTag *, const ProgramPointTag*> &tags = 1963 geteagerlyAssumeBinOpBifurcationTags(); 1964 1965 ProgramStateRef StateTrue, StateFalse; 1966 tie(StateTrue, StateFalse) = state->assume(*SEV); 1967 1968 // First assume that the condition is true. 1969 if (StateTrue) { 1970 SVal Val = svalBuilder.makeIntVal(1U, Ex->getType()); 1971 StateTrue = StateTrue->BindExpr(Ex, Pred->getLocationContext(), Val); 1972 Bldr.generateNode(Ex, Pred, StateTrue, tags.first); 1973 } 1974 1975 // Next, assume that the condition is false. 1976 if (StateFalse) { 1977 SVal Val = svalBuilder.makeIntVal(0U, Ex->getType()); 1978 StateFalse = StateFalse->BindExpr(Ex, Pred->getLocationContext(), Val); 1979 Bldr.generateNode(Ex, Pred, StateFalse, tags.second); 1980 } 1981 } 1982 } 1983} 1984 1985void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, ExplodedNode *Pred, 1986 ExplodedNodeSet &Dst) { 1987 StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 1988 // We have processed both the inputs and the outputs. All of the outputs 1989 // should evaluate to Locs. Nuke all of their values. 1990 1991 // FIXME: Some day in the future it would be nice to allow a "plug-in" 1992 // which interprets the inline asm and stores proper results in the 1993 // outputs. 1994 1995 ProgramStateRef state = Pred->getState(); 1996 1997 for (GCCAsmStmt::const_outputs_iterator OI = A->begin_outputs(), 1998 OE = A->end_outputs(); OI != OE; ++OI) { 1999 SVal X = state->getSVal(*OI, Pred->getLocationContext()); 2000 assert (!X.getAs<NonLoc>()); // Should be an Lval, or unknown, undef. 2001 2002 if (Optional<Loc> LV = X.getAs<Loc>()) 2003 state = state->bindLoc(*LV, UnknownVal()); 2004 } 2005 2006 Bldr.generateNode(A, Pred, state); 2007} 2008 2009void ExprEngine::VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred, 2010 ExplodedNodeSet &Dst) { 2011 StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 2012 Bldr.generateNode(A, Pred, Pred->getState()); 2013} 2014 2015//===----------------------------------------------------------------------===// 2016// Visualization. 2017//===----------------------------------------------------------------------===// 2018 2019#ifndef NDEBUG 2020static ExprEngine* GraphPrintCheckerState; 2021static SourceManager* GraphPrintSourceManager; 2022 2023namespace llvm { 2024template<> 2025struct DOTGraphTraits<ExplodedNode*> : 2026 public DefaultDOTGraphTraits { 2027 2028 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} 2029 2030 // FIXME: Since we do not cache error nodes in ExprEngine now, this does not 2031 // work. 2032 static std::string getNodeAttributes(const ExplodedNode *N, void*) { 2033 2034#if 0 2035 // FIXME: Replace with a general scheme to tell if the node is 2036 // an error node. 2037 if (GraphPrintCheckerState->isImplicitNullDeref(N) || 2038 GraphPrintCheckerState->isExplicitNullDeref(N) || 2039 GraphPrintCheckerState->isUndefDeref(N) || 2040 GraphPrintCheckerState->isUndefStore(N) || 2041 GraphPrintCheckerState->isUndefControlFlow(N) || 2042 GraphPrintCheckerState->isUndefResult(N) || 2043 GraphPrintCheckerState->isBadCall(N) || 2044 GraphPrintCheckerState->isUndefArg(N)) 2045 return "color=\"red\",style=\"filled\""; 2046 2047 if (GraphPrintCheckerState->isNoReturnCall(N)) 2048 return "color=\"blue\",style=\"filled\""; 2049#endif 2050 return ""; 2051 } 2052 2053 static void printLocation(raw_ostream &Out, SourceLocation SLoc) { 2054 if (SLoc.isFileID()) { 2055 Out << "\\lline=" 2056 << GraphPrintSourceManager->getExpansionLineNumber(SLoc) 2057 << " col=" 2058 << GraphPrintSourceManager->getExpansionColumnNumber(SLoc) 2059 << "\\l"; 2060 } 2061 } 2062 2063 static std::string getNodeLabel(const ExplodedNode *N, void*){ 2064 2065 std::string sbuf; 2066 llvm::raw_string_ostream Out(sbuf); 2067 2068 // Program Location. 2069 ProgramPoint Loc = N->getLocation(); 2070 2071 switch (Loc.getKind()) { 2072 case ProgramPoint::BlockEntranceKind: { 2073 Out << "Block Entrance: B" 2074 << cast<BlockEntrance>(Loc).getBlock()->getBlockID(); 2075 if (const NamedDecl *ND = 2076 dyn_cast<NamedDecl>(Loc.getLocationContext()->getDecl())) { 2077 Out << " ("; 2078 ND->printName(Out); 2079 Out << ")"; 2080 } 2081 break; 2082 } 2083 2084 case ProgramPoint::BlockExitKind: 2085 assert (false); 2086 break; 2087 2088 case ProgramPoint::CallEnterKind: 2089 Out << "CallEnter"; 2090 break; 2091 2092 case ProgramPoint::CallExitBeginKind: 2093 Out << "CallExitBegin"; 2094 break; 2095 2096 case ProgramPoint::CallExitEndKind: 2097 Out << "CallExitEnd"; 2098 break; 2099 2100 case ProgramPoint::PostStmtPurgeDeadSymbolsKind: 2101 Out << "PostStmtPurgeDeadSymbols"; 2102 break; 2103 2104 case ProgramPoint::PreStmtPurgeDeadSymbolsKind: 2105 Out << "PreStmtPurgeDeadSymbols"; 2106 break; 2107 2108 case ProgramPoint::EpsilonKind: 2109 Out << "Epsilon Point"; 2110 break; 2111 2112 case ProgramPoint::PreImplicitCallKind: { 2113 ImplicitCallPoint *PC = cast<ImplicitCallPoint>(&Loc); 2114 Out << "PreCall: "; 2115 2116 // FIXME: Get proper printing options. 2117 PC->getDecl()->print(Out, LangOptions()); 2118 printLocation(Out, PC->getLocation()); 2119 break; 2120 } 2121 2122 case ProgramPoint::PostImplicitCallKind: { 2123 ImplicitCallPoint *PC = cast<ImplicitCallPoint>(&Loc); 2124 Out << "PostCall: "; 2125 2126 // FIXME: Get proper printing options. 2127 PC->getDecl()->print(Out, LangOptions()); 2128 printLocation(Out, PC->getLocation()); 2129 break; 2130 } 2131 2132 default: { 2133 if (StmtPoint *L = dyn_cast<StmtPoint>(&Loc)) { 2134 const Stmt *S = L->getStmt(); 2135 2136 Out << S->getStmtClassName() << ' ' << (const void*) S << ' '; 2137 LangOptions LO; // FIXME. 2138 S->printPretty(Out, 0, PrintingPolicy(LO)); 2139 printLocation(Out, S->getLocStart()); 2140 2141 if (isa<PreStmt>(Loc)) 2142 Out << "\\lPreStmt\\l;"; 2143 else if (isa<PostLoad>(Loc)) 2144 Out << "\\lPostLoad\\l;"; 2145 else if (isa<PostStore>(Loc)) 2146 Out << "\\lPostStore\\l"; 2147 else if (isa<PostLValue>(Loc)) 2148 Out << "\\lPostLValue\\l"; 2149 2150#if 0 2151 // FIXME: Replace with a general scheme to determine 2152 // the name of the check. 2153 if (GraphPrintCheckerState->isImplicitNullDeref(N)) 2154 Out << "\\|Implicit-Null Dereference.\\l"; 2155 else if (GraphPrintCheckerState->isExplicitNullDeref(N)) 2156 Out << "\\|Explicit-Null Dereference.\\l"; 2157 else if (GraphPrintCheckerState->isUndefDeref(N)) 2158 Out << "\\|Dereference of undefialied value.\\l"; 2159 else if (GraphPrintCheckerState->isUndefStore(N)) 2160 Out << "\\|Store to Undefined Loc."; 2161 else if (GraphPrintCheckerState->isUndefResult(N)) 2162 Out << "\\|Result of operation is undefined."; 2163 else if (GraphPrintCheckerState->isNoReturnCall(N)) 2164 Out << "\\|Call to function marked \"noreturn\"."; 2165 else if (GraphPrintCheckerState->isBadCall(N)) 2166 Out << "\\|Call to NULL/Undefined."; 2167 else if (GraphPrintCheckerState->isUndefArg(N)) 2168 Out << "\\|Argument in call is undefined"; 2169#endif 2170 2171 break; 2172 } 2173 2174 const BlockEdge &E = cast<BlockEdge>(Loc); 2175 Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B" 2176 << E.getDst()->getBlockID() << ')'; 2177 2178 if (const Stmt *T = E.getSrc()->getTerminator()) { 2179 2180 SourceLocation SLoc = T->getLocStart(); 2181 2182 Out << "\\|Terminator: "; 2183 LangOptions LO; // FIXME. 2184 E.getSrc()->printTerminator(Out, LO); 2185 2186 if (SLoc.isFileID()) { 2187 Out << "\\lline=" 2188 << GraphPrintSourceManager->getExpansionLineNumber(SLoc) 2189 << " col=" 2190 << GraphPrintSourceManager->getExpansionColumnNumber(SLoc); 2191 } 2192 2193 if (isa<SwitchStmt>(T)) { 2194 const Stmt *Label = E.getDst()->getLabel(); 2195 2196 if (Label) { 2197 if (const CaseStmt *C = dyn_cast<CaseStmt>(Label)) { 2198 Out << "\\lcase "; 2199 LangOptions LO; // FIXME. 2200 C->getLHS()->printPretty(Out, 0, PrintingPolicy(LO)); 2201 2202 if (const Stmt *RHS = C->getRHS()) { 2203 Out << " .. "; 2204 RHS->printPretty(Out, 0, PrintingPolicy(LO)); 2205 } 2206 2207 Out << ":"; 2208 } 2209 else { 2210 assert (isa<DefaultStmt>(Label)); 2211 Out << "\\ldefault:"; 2212 } 2213 } 2214 else 2215 Out << "\\l(implicit) default:"; 2216 } 2217 else if (isa<IndirectGotoStmt>(T)) { 2218 // FIXME 2219 } 2220 else { 2221 Out << "\\lCondition: "; 2222 if (*E.getSrc()->succ_begin() == E.getDst()) 2223 Out << "true"; 2224 else 2225 Out << "false"; 2226 } 2227 2228 Out << "\\l"; 2229 } 2230 2231#if 0 2232 // FIXME: Replace with a general scheme to determine 2233 // the name of the check. 2234 if (GraphPrintCheckerState->isUndefControlFlow(N)) { 2235 Out << "\\|Control-flow based on\\lUndefined value.\\l"; 2236 } 2237#endif 2238 } 2239 } 2240 2241 ProgramStateRef state = N->getState(); 2242 Out << "\\|StateID: " << (const void*) state.getPtr() 2243 << " NodeID: " << (const void*) N << "\\|"; 2244 state->printDOT(Out); 2245 2246 Out << "\\l"; 2247 2248 if (const ProgramPointTag *tag = Loc.getTag()) { 2249 Out << "\\|Tag: " << tag->getTagDescription(); 2250 Out << "\\l"; 2251 } 2252 return Out.str(); 2253 } 2254}; 2255} // end llvm namespace 2256#endif 2257 2258#ifndef NDEBUG 2259template <typename ITERATOR> 2260ExplodedNode *GetGraphNode(ITERATOR I) { return *I; } 2261 2262template <> ExplodedNode* 2263GetGraphNode<llvm::DenseMap<ExplodedNode*, Expr*>::iterator> 2264 (llvm::DenseMap<ExplodedNode*, Expr*>::iterator I) { 2265 return I->first; 2266} 2267#endif 2268 2269void ExprEngine::ViewGraph(bool trim) { 2270#ifndef NDEBUG 2271 if (trim) { 2272 std::vector<ExplodedNode*> Src; 2273 2274 // Flush any outstanding reports to make sure we cover all the nodes. 2275 // This does not cause them to get displayed. 2276 for (BugReporter::iterator I=BR.begin(), E=BR.end(); I!=E; ++I) 2277 const_cast<BugType*>(*I)->FlushReports(BR); 2278 2279 // Iterate through the reports and get their nodes. 2280 for (BugReporter::EQClasses_iterator 2281 EI = BR.EQClasses_begin(), EE = BR.EQClasses_end(); EI != EE; ++EI) { 2282 ExplodedNode *N = const_cast<ExplodedNode*>(EI->begin()->getErrorNode()); 2283 if (N) Src.push_back(N); 2284 } 2285 2286 ViewGraph(&Src[0], &Src[0]+Src.size()); 2287 } 2288 else { 2289 GraphPrintCheckerState = this; 2290 GraphPrintSourceManager = &getContext().getSourceManager(); 2291 2292 llvm::ViewGraph(*G.roots_begin(), "ExprEngine"); 2293 2294 GraphPrintCheckerState = NULL; 2295 GraphPrintSourceManager = NULL; 2296 } 2297#endif 2298} 2299 2300void ExprEngine::ViewGraph(ExplodedNode** Beg, ExplodedNode** End) { 2301#ifndef NDEBUG 2302 GraphPrintCheckerState = this; 2303 GraphPrintSourceManager = &getContext().getSourceManager(); 2304 2305 std::auto_ptr<ExplodedGraph> TrimmedG(G.Trim(Beg, End).first); 2306 2307 if (!TrimmedG.get()) 2308 llvm::errs() << "warning: Trimmed ExplodedGraph is empty.\n"; 2309 else 2310 llvm::ViewGraph(*TrimmedG->roots_begin(), "TrimmedExprEngine"); 2311 2312 GraphPrintCheckerState = NULL; 2313 GraphPrintSourceManager = NULL; 2314#endif 2315} 2316