ExprEngine.cpp 74 KB

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