ExprEngineC.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  1. //=-- ExprEngineC.cpp - ExprEngine support for C expressions ----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines ExprEngine's support for C expressions.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/AST/ExprCXX.h"
  14. #include "clang/AST/DeclCXX.h"
  15. #include "clang/StaticAnalyzer/Core/CheckerManager.h"
  16. #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
  17. using namespace clang;
  18. using namespace ento;
  19. using llvm::APSInt;
  20. void ExprEngine::VisitBinaryOperator(const BinaryOperator* B,
  21. ExplodedNode *Pred,
  22. ExplodedNodeSet &Dst) {
  23. Expr *LHS = B->getLHS()->IgnoreParens();
  24. Expr *RHS = B->getRHS()->IgnoreParens();
  25. // FIXME: Prechecks eventually go in ::Visit().
  26. ExplodedNodeSet CheckedSet;
  27. ExplodedNodeSet Tmp2;
  28. getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, B, *this);
  29. // With both the LHS and RHS evaluated, process the operation itself.
  30. for (ExplodedNodeSet::iterator it=CheckedSet.begin(), ei=CheckedSet.end();
  31. it != ei; ++it) {
  32. ProgramStateRef state = (*it)->getState();
  33. const LocationContext *LCtx = (*it)->getLocationContext();
  34. SVal LeftV = state->getSVal(LHS, LCtx);
  35. SVal RightV = state->getSVal(RHS, LCtx);
  36. BinaryOperator::Opcode Op = B->getOpcode();
  37. if (Op == BO_Assign) {
  38. // EXPERIMENTAL: "Conjured" symbols.
  39. // FIXME: Handle structs.
  40. if (RightV.isUnknown()) {
  41. unsigned Count = currBldrCtx->blockCount();
  42. RightV = svalBuilder.conjureSymbolVal(nullptr, B->getRHS(), LCtx,
  43. Count);
  44. }
  45. // Simulate the effects of a "store": bind the value of the RHS
  46. // to the L-Value represented by the LHS.
  47. SVal ExprVal = B->isGLValue() ? LeftV : RightV;
  48. evalStore(Tmp2, B, LHS, *it, state->BindExpr(B, LCtx, ExprVal),
  49. LeftV, RightV);
  50. continue;
  51. }
  52. if (!B->isAssignmentOp()) {
  53. StmtNodeBuilder Bldr(*it, Tmp2, *currBldrCtx);
  54. if (B->isAdditiveOp()) {
  55. // If one of the operands is a location, conjure a symbol for the other
  56. // one (offset) if it's unknown so that memory arithmetic always
  57. // results in an ElementRegion.
  58. // TODO: This can be removed after we enable history tracking with
  59. // SymSymExpr.
  60. unsigned Count = currBldrCtx->blockCount();
  61. if (LeftV.getAs<Loc>() &&
  62. RHS->getType()->isIntegralOrEnumerationType() &&
  63. RightV.isUnknown()) {
  64. RightV = svalBuilder.conjureSymbolVal(RHS, LCtx, RHS->getType(),
  65. Count);
  66. }
  67. if (RightV.getAs<Loc>() &&
  68. LHS->getType()->isIntegralOrEnumerationType() &&
  69. LeftV.isUnknown()) {
  70. LeftV = svalBuilder.conjureSymbolVal(LHS, LCtx, LHS->getType(),
  71. Count);
  72. }
  73. }
  74. // Although we don't yet model pointers-to-members, we do need to make
  75. // sure that the members of temporaries have a valid 'this' pointer for
  76. // other checks.
  77. if (B->getOpcode() == BO_PtrMemD)
  78. state = createTemporaryRegionIfNeeded(state, LCtx, LHS);
  79. // Process non-assignments except commas or short-circuited
  80. // logical expressions (LAnd and LOr).
  81. SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
  82. if (Result.isUnknown()) {
  83. Bldr.generateNode(B, *it, state);
  84. continue;
  85. }
  86. state = state->BindExpr(B, LCtx, Result);
  87. Bldr.generateNode(B, *it, state);
  88. continue;
  89. }
  90. assert (B->isCompoundAssignmentOp());
  91. switch (Op) {
  92. default:
  93. llvm_unreachable("Invalid opcode for compound assignment.");
  94. case BO_MulAssign: Op = BO_Mul; break;
  95. case BO_DivAssign: Op = BO_Div; break;
  96. case BO_RemAssign: Op = BO_Rem; break;
  97. case BO_AddAssign: Op = BO_Add; break;
  98. case BO_SubAssign: Op = BO_Sub; break;
  99. case BO_ShlAssign: Op = BO_Shl; break;
  100. case BO_ShrAssign: Op = BO_Shr; break;
  101. case BO_AndAssign: Op = BO_And; break;
  102. case BO_XorAssign: Op = BO_Xor; break;
  103. case BO_OrAssign: Op = BO_Or; break;
  104. }
  105. // Perform a load (the LHS). This performs the checks for
  106. // null dereferences, and so on.
  107. ExplodedNodeSet Tmp;
  108. SVal location = LeftV;
  109. evalLoad(Tmp, B, LHS, *it, state, location);
  110. for (ExplodedNodeSet::iterator I = Tmp.begin(), E = Tmp.end(); I != E;
  111. ++I) {
  112. state = (*I)->getState();
  113. const LocationContext *LCtx = (*I)->getLocationContext();
  114. SVal V = state->getSVal(LHS, LCtx);
  115. // Get the computation type.
  116. QualType CTy =
  117. cast<CompoundAssignOperator>(B)->getComputationResultType();
  118. CTy = getContext().getCanonicalType(CTy);
  119. QualType CLHSTy =
  120. cast<CompoundAssignOperator>(B)->getComputationLHSType();
  121. CLHSTy = getContext().getCanonicalType(CLHSTy);
  122. QualType LTy = getContext().getCanonicalType(LHS->getType());
  123. // Promote LHS.
  124. V = svalBuilder.evalCast(V, CLHSTy, LTy);
  125. // Compute the result of the operation.
  126. SVal Result = svalBuilder.evalCast(evalBinOp(state, Op, V, RightV, CTy),
  127. B->getType(), CTy);
  128. // EXPERIMENTAL: "Conjured" symbols.
  129. // FIXME: Handle structs.
  130. SVal LHSVal;
  131. if (Result.isUnknown()) {
  132. // The symbolic value is actually for the type of the left-hand side
  133. // expression, not the computation type, as this is the value the
  134. // LValue on the LHS will bind to.
  135. LHSVal = svalBuilder.conjureSymbolVal(nullptr, B->getRHS(), LCtx, LTy,
  136. currBldrCtx->blockCount());
  137. // However, we need to convert the symbol to the computation type.
  138. Result = svalBuilder.evalCast(LHSVal, CTy, LTy);
  139. }
  140. else {
  141. // The left-hand side may bind to a different value then the
  142. // computation type.
  143. LHSVal = svalBuilder.evalCast(Result, LTy, CTy);
  144. }
  145. // In C++, assignment and compound assignment operators return an
  146. // lvalue.
  147. if (B->isGLValue())
  148. state = state->BindExpr(B, LCtx, location);
  149. else
  150. state = state->BindExpr(B, LCtx, Result);
  151. evalStore(Tmp2, B, LHS, *I, state, location, LHSVal);
  152. }
  153. }
  154. // FIXME: postvisits eventually go in ::Visit()
  155. getCheckerManager().runCheckersForPostStmt(Dst, Tmp2, B, *this);
  156. }
  157. void ExprEngine::VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred,
  158. ExplodedNodeSet &Dst) {
  159. CanQualType T = getContext().getCanonicalType(BE->getType());
  160. const BlockDecl *BD = BE->getBlockDecl();
  161. // Get the value of the block itself.
  162. SVal V = svalBuilder.getBlockPointer(BD, T,
  163. Pred->getLocationContext(),
  164. currBldrCtx->blockCount());
  165. ProgramStateRef State = Pred->getState();
  166. // If we created a new MemRegion for the block, we should explicitly bind
  167. // the captured variables.
  168. if (const BlockDataRegion *BDR =
  169. dyn_cast_or_null<BlockDataRegion>(V.getAsRegion())) {
  170. BlockDataRegion::referenced_vars_iterator I = BDR->referenced_vars_begin(),
  171. E = BDR->referenced_vars_end();
  172. auto CI = BD->capture_begin();
  173. auto CE = BD->capture_end();
  174. for (; I != E; ++I) {
  175. const VarRegion *capturedR = I.getCapturedRegion();
  176. const VarRegion *originalR = I.getOriginalRegion();
  177. // If the capture had a copy expression, use the result of evaluating
  178. // that expression, otherwise use the original value.
  179. // We rely on the invariant that the block declaration's capture variables
  180. // are a prefix of the BlockDataRegion's referenced vars (which may include
  181. // referenced globals, etc.) to enable fast lookup of the capture for a
  182. // given referenced var.
  183. const Expr *copyExpr = nullptr;
  184. if (CI != CE) {
  185. assert(CI->getVariable() == capturedR->getDecl());
  186. copyExpr = CI->getCopyExpr();
  187. CI++;
  188. }
  189. if (capturedR != originalR) {
  190. SVal originalV;
  191. if (copyExpr) {
  192. originalV = State->getSVal(copyExpr, Pred->getLocationContext());
  193. } else {
  194. originalV = State->getSVal(loc::MemRegionVal(originalR));
  195. }
  196. State = State->bindLoc(loc::MemRegionVal(capturedR), originalV);
  197. }
  198. }
  199. }
  200. ExplodedNodeSet Tmp;
  201. StmtNodeBuilder Bldr(Pred, Tmp, *currBldrCtx);
  202. Bldr.generateNode(BE, Pred,
  203. State->BindExpr(BE, Pred->getLocationContext(), V),
  204. nullptr, ProgramPoint::PostLValueKind);
  205. // FIXME: Move all post/pre visits to ::Visit().
  206. getCheckerManager().runCheckersForPostStmt(Dst, Tmp, BE, *this);
  207. }
  208. ProgramStateRef ExprEngine::handleLValueBitCast(
  209. ProgramStateRef state, const Expr* Ex, const LocationContext* LCtx,
  210. QualType T, QualType ExTy, const CastExpr* CastE, StmtNodeBuilder& Bldr,
  211. ExplodedNode* Pred) {
  212. // Delegate to SValBuilder to process.
  213. SVal V = state->getSVal(Ex, LCtx);
  214. V = svalBuilder.evalCast(V, T, ExTy);
  215. // Negate the result if we're treating the boolean as a signed i1
  216. if (CastE->getCastKind() == CK_BooleanToSignedIntegral)
  217. V = evalMinus(V);
  218. state = state->BindExpr(CastE, LCtx, V);
  219. Bldr.generateNode(CastE, Pred, state);
  220. return state;
  221. }
  222. ProgramStateRef ExprEngine::handleLVectorSplat(
  223. ProgramStateRef state, const LocationContext* LCtx, const CastExpr* CastE,
  224. StmtNodeBuilder &Bldr, ExplodedNode* Pred) {
  225. // Recover some path sensitivity by conjuring a new value.
  226. QualType resultType = CastE->getType();
  227. if (CastE->isGLValue())
  228. resultType = getContext().getPointerType(resultType);
  229. SVal result = svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx,
  230. resultType,
  231. currBldrCtx->blockCount());
  232. state = state->BindExpr(CastE, LCtx, result);
  233. Bldr.generateNode(CastE, Pred, state);
  234. return state;
  235. }
  236. void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
  237. ExplodedNode *Pred, ExplodedNodeSet &Dst) {
  238. ExplodedNodeSet dstPreStmt;
  239. getCheckerManager().runCheckersForPreStmt(dstPreStmt, Pred, CastE, *this);
  240. if (CastE->getCastKind() == CK_LValueToRValue) {
  241. for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = dstPreStmt.end();
  242. I!=E; ++I) {
  243. ExplodedNode *subExprNode = *I;
  244. ProgramStateRef state = subExprNode->getState();
  245. const LocationContext *LCtx = subExprNode->getLocationContext();
  246. evalLoad(Dst, CastE, CastE, subExprNode, state, state->getSVal(Ex, LCtx));
  247. }
  248. return;
  249. }
  250. // All other casts.
  251. QualType T = CastE->getType();
  252. QualType ExTy = Ex->getType();
  253. if (const ExplicitCastExpr *ExCast=dyn_cast_or_null<ExplicitCastExpr>(CastE))
  254. T = ExCast->getTypeAsWritten();
  255. StmtNodeBuilder Bldr(dstPreStmt, Dst, *currBldrCtx);
  256. for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = dstPreStmt.end();
  257. I != E; ++I) {
  258. Pred = *I;
  259. ProgramStateRef state = Pred->getState();
  260. const LocationContext *LCtx = Pred->getLocationContext();
  261. switch (CastE->getCastKind()) {
  262. case CK_LValueToRValue:
  263. llvm_unreachable("LValueToRValue casts handled earlier.");
  264. case CK_ToVoid:
  265. continue;
  266. // The analyzer doesn't do anything special with these casts,
  267. // since it understands retain/release semantics already.
  268. case CK_ARCProduceObject:
  269. case CK_ARCConsumeObject:
  270. case CK_ARCReclaimReturnedObject:
  271. case CK_ARCExtendBlockObject: // Fall-through.
  272. case CK_CopyAndAutoreleaseBlockObject:
  273. // The analyser can ignore atomic casts for now, although some future
  274. // checkers may want to make certain that you're not modifying the same
  275. // value through atomic and nonatomic pointers.
  276. case CK_AtomicToNonAtomic:
  277. case CK_NonAtomicToAtomic:
  278. // True no-ops.
  279. case CK_NoOp:
  280. case CK_ConstructorConversion:
  281. case CK_UserDefinedConversion:
  282. case CK_FunctionToPointerDecay:
  283. case CK_BuiltinFnToFnPtr: {
  284. // Copy the SVal of Ex to CastE.
  285. ProgramStateRef state = Pred->getState();
  286. const LocationContext *LCtx = Pred->getLocationContext();
  287. SVal V = state->getSVal(Ex, LCtx);
  288. state = state->BindExpr(CastE, LCtx, V);
  289. Bldr.generateNode(CastE, Pred, state);
  290. continue;
  291. }
  292. case CK_MemberPointerToBoolean:
  293. case CK_PointerToBoolean: {
  294. SVal V = state->getSVal(Ex, LCtx);
  295. auto PTMSV = V.getAs<nonloc::PointerToMember>();
  296. if (PTMSV)
  297. V = svalBuilder.makeTruthVal(!PTMSV->isNullMemberPointer(), ExTy);
  298. if (V.isUndef() || PTMSV) {
  299. state = state->BindExpr(CastE, LCtx, V);
  300. Bldr.generateNode(CastE, Pred, state);
  301. continue;
  302. }
  303. // Explicitly proceed with default handler for this case cascade.
  304. state =
  305. handleLValueBitCast(state, Ex, LCtx, T, ExTy, CastE, Bldr, Pred);
  306. continue;
  307. }
  308. case CK_Dependent:
  309. case CK_ArrayToPointerDecay:
  310. case CK_BitCast:
  311. case CK_AddressSpaceConversion:
  312. case CK_BooleanToSignedIntegral:
  313. case CK_NullToPointer:
  314. case CK_IntegralToPointer:
  315. case CK_PointerToIntegral: {
  316. SVal V = state->getSVal(Ex, LCtx);
  317. if (V.getAs<nonloc::PointerToMember>()) {
  318. state = state->BindExpr(CastE, LCtx, UnknownVal());
  319. Bldr.generateNode(CastE, Pred, state);
  320. continue;
  321. }
  322. // Explicitly proceed with default handler for this case cascade.
  323. state =
  324. handleLValueBitCast(state, Ex, LCtx, T, ExTy, CastE, Bldr, Pred);
  325. continue;
  326. }
  327. case CK_IntegralToBoolean:
  328. case CK_IntegralToFloating:
  329. case CK_FloatingToIntegral:
  330. case CK_FloatingToBoolean:
  331. case CK_FloatingCast:
  332. case CK_FloatingRealToComplex:
  333. case CK_FloatingComplexToReal:
  334. case CK_FloatingComplexToBoolean:
  335. case CK_FloatingComplexCast:
  336. case CK_FloatingComplexToIntegralComplex:
  337. case CK_IntegralRealToComplex:
  338. case CK_IntegralComplexToReal:
  339. case CK_IntegralComplexToBoolean:
  340. case CK_IntegralComplexCast:
  341. case CK_IntegralComplexToFloatingComplex:
  342. case CK_CPointerToObjCPointerCast:
  343. case CK_BlockPointerToObjCPointerCast:
  344. case CK_AnyPointerToBlockPointerCast:
  345. case CK_ObjCObjectLValueCast:
  346. case CK_ZeroToOCLEvent:
  347. case CK_ZeroToOCLQueue:
  348. case CK_IntToOCLSampler:
  349. case CK_LValueBitCast: {
  350. state =
  351. handleLValueBitCast(state, Ex, LCtx, T, ExTy, CastE, Bldr, Pred);
  352. continue;
  353. }
  354. case CK_IntegralCast: {
  355. // Delegate to SValBuilder to process.
  356. SVal V = state->getSVal(Ex, LCtx);
  357. V = svalBuilder.evalIntegralCast(state, V, T, ExTy);
  358. state = state->BindExpr(CastE, LCtx, V);
  359. Bldr.generateNode(CastE, Pred, state);
  360. continue;
  361. }
  362. case CK_DerivedToBase:
  363. case CK_UncheckedDerivedToBase: {
  364. // For DerivedToBase cast, delegate to the store manager.
  365. SVal val = state->getSVal(Ex, LCtx);
  366. val = getStoreManager().evalDerivedToBase(val, CastE);
  367. state = state->BindExpr(CastE, LCtx, val);
  368. Bldr.generateNode(CastE, Pred, state);
  369. continue;
  370. }
  371. // Handle C++ dyn_cast.
  372. case CK_Dynamic: {
  373. SVal val = state->getSVal(Ex, LCtx);
  374. // Compute the type of the result.
  375. QualType resultType = CastE->getType();
  376. if (CastE->isGLValue())
  377. resultType = getContext().getPointerType(resultType);
  378. bool Failed = false;
  379. // Check if the value being cast evaluates to 0.
  380. if (val.isZeroConstant())
  381. Failed = true;
  382. // Else, evaluate the cast.
  383. else
  384. val = getStoreManager().attemptDownCast(val, T, Failed);
  385. if (Failed) {
  386. if (T->isReferenceType()) {
  387. // A bad_cast exception is thrown if input value is a reference.
  388. // Currently, we model this, by generating a sink.
  389. Bldr.generateSink(CastE, Pred, state);
  390. continue;
  391. } else {
  392. // If the cast fails on a pointer, bind to 0.
  393. state = state->BindExpr(CastE, LCtx, svalBuilder.makeNull());
  394. }
  395. } else {
  396. // If we don't know if the cast succeeded, conjure a new symbol.
  397. if (val.isUnknown()) {
  398. DefinedOrUnknownSVal NewSym =
  399. svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx, resultType,
  400. currBldrCtx->blockCount());
  401. state = state->BindExpr(CastE, LCtx, NewSym);
  402. } else
  403. // Else, bind to the derived region value.
  404. state = state->BindExpr(CastE, LCtx, val);
  405. }
  406. Bldr.generateNode(CastE, Pred, state);
  407. continue;
  408. }
  409. case CK_BaseToDerived: {
  410. SVal val = state->getSVal(Ex, LCtx);
  411. QualType resultType = CastE->getType();
  412. if (CastE->isGLValue())
  413. resultType = getContext().getPointerType(resultType);
  414. bool Failed = false;
  415. if (!val.isConstant()) {
  416. val = getStoreManager().attemptDownCast(val, T, Failed);
  417. }
  418. // Failed to cast or the result is unknown, fall back to conservative.
  419. if (Failed || val.isUnknown()) {
  420. val =
  421. svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx, resultType,
  422. currBldrCtx->blockCount());
  423. }
  424. state = state->BindExpr(CastE, LCtx, val);
  425. Bldr.generateNode(CastE, Pred, state);
  426. continue;
  427. }
  428. case CK_NullToMemberPointer: {
  429. SVal V = svalBuilder.getMemberPointer(nullptr);
  430. state = state->BindExpr(CastE, LCtx, V);
  431. Bldr.generateNode(CastE, Pred, state);
  432. continue;
  433. }
  434. case CK_DerivedToBaseMemberPointer:
  435. case CK_BaseToDerivedMemberPointer:
  436. case CK_ReinterpretMemberPointer: {
  437. SVal V = state->getSVal(Ex, LCtx);
  438. if (auto PTMSV = V.getAs<nonloc::PointerToMember>()) {
  439. SVal CastedPTMSV = svalBuilder.makePointerToMember(
  440. getBasicVals().accumCXXBase(
  441. llvm::make_range<CastExpr::path_const_iterator>(
  442. CastE->path_begin(), CastE->path_end()), *PTMSV));
  443. state = state->BindExpr(CastE, LCtx, CastedPTMSV);
  444. Bldr.generateNode(CastE, Pred, state);
  445. continue;
  446. }
  447. // Explicitly proceed with default handler for this case cascade.
  448. state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
  449. continue;
  450. }
  451. // Various C++ casts that are not handled yet.
  452. case CK_ToUnion:
  453. case CK_VectorSplat: {
  454. state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
  455. continue;
  456. }
  457. }
  458. }
  459. }
  460. void ExprEngine::VisitCompoundLiteralExpr(const CompoundLiteralExpr *CL,
  461. ExplodedNode *Pred,
  462. ExplodedNodeSet &Dst) {
  463. StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
  464. ProgramStateRef State = Pred->getState();
  465. const LocationContext *LCtx = Pred->getLocationContext();
  466. const Expr *Init = CL->getInitializer();
  467. SVal V = State->getSVal(CL->getInitializer(), LCtx);
  468. if (isa<CXXConstructExpr>(Init)) {
  469. // No work needed. Just pass the value up to this expression.
  470. } else {
  471. assert(isa<InitListExpr>(Init));
  472. Loc CLLoc = State->getLValue(CL, LCtx);
  473. State = State->bindLoc(CLLoc, V);
  474. if (CL->isGLValue())
  475. V = CLLoc;
  476. }
  477. B.generateNode(CL, Pred, State->BindExpr(CL, LCtx, V));
  478. }
  479. void ExprEngine::VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred,
  480. ExplodedNodeSet &Dst) {
  481. // Assumption: The CFG has one DeclStmt per Decl.
  482. const VarDecl *VD = dyn_cast_or_null<VarDecl>(*DS->decl_begin());
  483. if (!VD) {
  484. //TODO:AZ: remove explicit insertion after refactoring is done.
  485. Dst.insert(Pred);
  486. return;
  487. }
  488. // FIXME: all pre/post visits should eventually be handled by ::Visit().
  489. ExplodedNodeSet dstPreVisit;
  490. getCheckerManager().runCheckersForPreStmt(dstPreVisit, Pred, DS, *this);
  491. ExplodedNodeSet dstEvaluated;
  492. StmtNodeBuilder B(dstPreVisit, dstEvaluated, *currBldrCtx);
  493. for (ExplodedNodeSet::iterator I = dstPreVisit.begin(), E = dstPreVisit.end();
  494. I!=E; ++I) {
  495. ExplodedNode *N = *I;
  496. ProgramStateRef state = N->getState();
  497. const LocationContext *LC = N->getLocationContext();
  498. // Decls without InitExpr are not initialized explicitly.
  499. if (const Expr *InitEx = VD->getInit()) {
  500. // Note in the state that the initialization has occurred.
  501. ExplodedNode *UpdatedN = N;
  502. SVal InitVal = state->getSVal(InitEx, LC);
  503. assert(DS->isSingleDecl());
  504. if (auto *CtorExpr = findDirectConstructorForCurrentCFGElement()) {
  505. assert(InitEx->IgnoreImplicit() == CtorExpr);
  506. (void)CtorExpr;
  507. // We constructed the object directly in the variable.
  508. // No need to bind anything.
  509. B.generateNode(DS, UpdatedN, state);
  510. } else {
  511. // We bound the temp obj region to the CXXConstructExpr. Now recover
  512. // the lazy compound value when the variable is not a reference.
  513. if (AMgr.getLangOpts().CPlusPlus && VD->getType()->isRecordType() &&
  514. !VD->getType()->isReferenceType()) {
  515. if (Optional<loc::MemRegionVal> M =
  516. InitVal.getAs<loc::MemRegionVal>()) {
  517. InitVal = state->getSVal(M->getRegion());
  518. assert(InitVal.getAs<nonloc::LazyCompoundVal>());
  519. }
  520. }
  521. // Recover some path-sensitivity if a scalar value evaluated to
  522. // UnknownVal.
  523. if (InitVal.isUnknown()) {
  524. QualType Ty = InitEx->getType();
  525. if (InitEx->isGLValue()) {
  526. Ty = getContext().getPointerType(Ty);
  527. }
  528. InitVal = svalBuilder.conjureSymbolVal(nullptr, InitEx, LC, Ty,
  529. currBldrCtx->blockCount());
  530. }
  531. B.takeNodes(UpdatedN);
  532. ExplodedNodeSet Dst2;
  533. evalBind(Dst2, DS, UpdatedN, state->getLValue(VD, LC), InitVal, true);
  534. B.addNodes(Dst2);
  535. }
  536. }
  537. else {
  538. B.generateNode(DS, N, state);
  539. }
  540. }
  541. getCheckerManager().runCheckersForPostStmt(Dst, B.getResults(), DS, *this);
  542. }
  543. void ExprEngine::VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
  544. ExplodedNodeSet &Dst) {
  545. assert(B->getOpcode() == BO_LAnd ||
  546. B->getOpcode() == BO_LOr);
  547. StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
  548. ProgramStateRef state = Pred->getState();
  549. ExplodedNode *N = Pred;
  550. while (!N->getLocation().getAs<BlockEntrance>()) {
  551. ProgramPoint P = N->getLocation();
  552. assert(P.getAs<PreStmt>()|| P.getAs<PreStmtPurgeDeadSymbols>());
  553. (void) P;
  554. assert(N->pred_size() == 1);
  555. N = *N->pred_begin();
  556. }
  557. assert(N->pred_size() == 1);
  558. N = *N->pred_begin();
  559. BlockEdge BE = N->getLocation().castAs<BlockEdge>();
  560. SVal X;
  561. // Determine the value of the expression by introspecting how we
  562. // got this location in the CFG. This requires looking at the previous
  563. // block we were in and what kind of control-flow transfer was involved.
  564. const CFGBlock *SrcBlock = BE.getSrc();
  565. // The only terminator (if there is one) that makes sense is a logical op.
  566. CFGTerminator T = SrcBlock->getTerminator();
  567. if (const BinaryOperator *Term = cast_or_null<BinaryOperator>(T.getStmt())) {
  568. (void) Term;
  569. assert(Term->isLogicalOp());
  570. assert(SrcBlock->succ_size() == 2);
  571. // Did we take the true or false branch?
  572. unsigned constant = (*SrcBlock->succ_begin() == BE.getDst()) ? 1 : 0;
  573. X = svalBuilder.makeIntVal(constant, B->getType());
  574. }
  575. else {
  576. // If there is no terminator, by construction the last statement
  577. // in SrcBlock is the value of the enclosing expression.
  578. // However, we still need to constrain that value to be 0 or 1.
  579. assert(!SrcBlock->empty());
  580. CFGStmt Elem = SrcBlock->rbegin()->castAs<CFGStmt>();
  581. const Expr *RHS = cast<Expr>(Elem.getStmt());
  582. SVal RHSVal = N->getState()->getSVal(RHS, Pred->getLocationContext());
  583. if (RHSVal.isUndef()) {
  584. X = RHSVal;
  585. } else {
  586. DefinedOrUnknownSVal DefinedRHS = RHSVal.castAs<DefinedOrUnknownSVal>();
  587. ProgramStateRef StTrue, StFalse;
  588. std::tie(StTrue, StFalse) = N->getState()->assume(DefinedRHS);
  589. if (StTrue) {
  590. if (StFalse) {
  591. // We can't constrain the value to 0 or 1.
  592. // The best we can do is a cast.
  593. X = getSValBuilder().evalCast(RHSVal, B->getType(), RHS->getType());
  594. } else {
  595. // The value is known to be true.
  596. X = getSValBuilder().makeIntVal(1, B->getType());
  597. }
  598. } else {
  599. // The value is known to be false.
  600. assert(StFalse && "Infeasible path!");
  601. X = getSValBuilder().makeIntVal(0, B->getType());
  602. }
  603. }
  604. }
  605. Bldr.generateNode(B, Pred, state->BindExpr(B, Pred->getLocationContext(), X));
  606. }
  607. void ExprEngine::VisitInitListExpr(const InitListExpr *IE,
  608. ExplodedNode *Pred,
  609. ExplodedNodeSet &Dst) {
  610. StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
  611. ProgramStateRef state = Pred->getState();
  612. const LocationContext *LCtx = Pred->getLocationContext();
  613. QualType T = getContext().getCanonicalType(IE->getType());
  614. unsigned NumInitElements = IE->getNumInits();
  615. if (!IE->isGLValue() &&
  616. (T->isArrayType() || T->isRecordType() || T->isVectorType() ||
  617. T->isAnyComplexType())) {
  618. llvm::ImmutableList<SVal> vals = getBasicVals().getEmptySValList();
  619. // Handle base case where the initializer has no elements.
  620. // e.g: static int* myArray[] = {};
  621. if (NumInitElements == 0) {
  622. SVal V = svalBuilder.makeCompoundVal(T, vals);
  623. B.generateNode(IE, Pred, state->BindExpr(IE, LCtx, V));
  624. return;
  625. }
  626. for (InitListExpr::const_reverse_iterator it = IE->rbegin(),
  627. ei = IE->rend(); it != ei; ++it) {
  628. SVal V = state->getSVal(cast<Expr>(*it), LCtx);
  629. vals = getBasicVals().prependSVal(V, vals);
  630. }
  631. B.generateNode(IE, Pred,
  632. state->BindExpr(IE, LCtx,
  633. svalBuilder.makeCompoundVal(T, vals)));
  634. return;
  635. }
  636. // Handle scalars: int{5} and int{} and GLvalues.
  637. // Note, if the InitListExpr is a GLvalue, it means that there is an address
  638. // representing it, so it must have a single init element.
  639. assert(NumInitElements <= 1);
  640. SVal V;
  641. if (NumInitElements == 0)
  642. V = getSValBuilder().makeZeroVal(T);
  643. else
  644. V = state->getSVal(IE->getInit(0), LCtx);
  645. B.generateNode(IE, Pred, state->BindExpr(IE, LCtx, V));
  646. }
  647. void ExprEngine::VisitGuardedExpr(const Expr *Ex,
  648. const Expr *L,
  649. const Expr *R,
  650. ExplodedNode *Pred,
  651. ExplodedNodeSet &Dst) {
  652. assert(L && R);
  653. StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
  654. ProgramStateRef state = Pred->getState();
  655. const LocationContext *LCtx = Pred->getLocationContext();
  656. const CFGBlock *SrcBlock = nullptr;
  657. // Find the predecessor block.
  658. ProgramStateRef SrcState = state;
  659. for (const ExplodedNode *N = Pred ; N ; N = *N->pred_begin()) {
  660. ProgramPoint PP = N->getLocation();
  661. if (PP.getAs<PreStmtPurgeDeadSymbols>() || PP.getAs<BlockEntrance>()) {
  662. assert(N->pred_size() == 1);
  663. continue;
  664. }
  665. SrcBlock = PP.castAs<BlockEdge>().getSrc();
  666. SrcState = N->getState();
  667. break;
  668. }
  669. assert(SrcBlock && "missing function entry");
  670. // Find the last expression in the predecessor block. That is the
  671. // expression that is used for the value of the ternary expression.
  672. bool hasValue = false;
  673. SVal V;
  674. for (CFGElement CE : llvm::reverse(*SrcBlock)) {
  675. if (Optional<CFGStmt> CS = CE.getAs<CFGStmt>()) {
  676. const Expr *ValEx = cast<Expr>(CS->getStmt());
  677. ValEx = ValEx->IgnoreParens();
  678. // For GNU extension '?:' operator, the left hand side will be an
  679. // OpaqueValueExpr, so get the underlying expression.
  680. if (const OpaqueValueExpr *OpaqueEx = dyn_cast<OpaqueValueExpr>(L))
  681. L = OpaqueEx->getSourceExpr();
  682. // If the last expression in the predecessor block matches true or false
  683. // subexpression, get its the value.
  684. if (ValEx == L->IgnoreParens() || ValEx == R->IgnoreParens()) {
  685. hasValue = true;
  686. V = SrcState->getSVal(ValEx, LCtx);
  687. }
  688. break;
  689. }
  690. }
  691. if (!hasValue)
  692. V = svalBuilder.conjureSymbolVal(nullptr, Ex, LCtx,
  693. currBldrCtx->blockCount());
  694. // Generate a new node with the binding from the appropriate path.
  695. B.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V, true));
  696. }
  697. void ExprEngine::
  698. VisitOffsetOfExpr(const OffsetOfExpr *OOE,
  699. ExplodedNode *Pred, ExplodedNodeSet &Dst) {
  700. StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
  701. APSInt IV;
  702. if (OOE->EvaluateAsInt(IV, getContext())) {
  703. assert(IV.getBitWidth() == getContext().getTypeSize(OOE->getType()));
  704. assert(OOE->getType()->isBuiltinType());
  705. assert(OOE->getType()->getAs<BuiltinType>()->isInteger());
  706. assert(IV.isSigned() == OOE->getType()->isSignedIntegerType());
  707. SVal X = svalBuilder.makeIntVal(IV);
  708. B.generateNode(OOE, Pred,
  709. Pred->getState()->BindExpr(OOE, Pred->getLocationContext(),
  710. X));
  711. }
  712. // FIXME: Handle the case where __builtin_offsetof is not a constant.
  713. }
  714. void ExprEngine::
  715. VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Ex,
  716. ExplodedNode *Pred,
  717. ExplodedNodeSet &Dst) {
  718. // FIXME: Prechecks eventually go in ::Visit().
  719. ExplodedNodeSet CheckedSet;
  720. getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, Ex, *this);
  721. ExplodedNodeSet EvalSet;
  722. StmtNodeBuilder Bldr(CheckedSet, EvalSet, *currBldrCtx);
  723. QualType T = Ex->getTypeOfArgument();
  724. for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
  725. I != E; ++I) {
  726. if (Ex->getKind() == UETT_SizeOf) {
  727. if (!T->isIncompleteType() && !T->isConstantSizeType()) {
  728. assert(T->isVariableArrayType() && "Unknown non-constant-sized type.");
  729. // FIXME: Add support for VLA type arguments and VLA expressions.
  730. // When that happens, we should probably refactor VLASizeChecker's code.
  731. continue;
  732. } else if (T->getAs<ObjCObjectType>()) {
  733. // Some code tries to take the sizeof an ObjCObjectType, relying that
  734. // the compiler has laid out its representation. Just report Unknown
  735. // for these.
  736. continue;
  737. }
  738. }
  739. APSInt Value = Ex->EvaluateKnownConstInt(getContext());
  740. CharUnits amt = CharUnits::fromQuantity(Value.getZExtValue());
  741. ProgramStateRef state = (*I)->getState();
  742. state = state->BindExpr(Ex, (*I)->getLocationContext(),
  743. svalBuilder.makeIntVal(amt.getQuantity(),
  744. Ex->getType()));
  745. Bldr.generateNode(Ex, *I, state);
  746. }
  747. getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, Ex, *this);
  748. }
  749. void ExprEngine::handleUOExtension(ExplodedNodeSet::iterator I,
  750. const UnaryOperator *U,
  751. StmtNodeBuilder &Bldr) {
  752. // FIXME: We can probably just have some magic in Environment::getSVal()
  753. // that propagates values, instead of creating a new node here.
  754. //
  755. // Unary "+" is a no-op, similar to a parentheses. We still have places
  756. // where it may be a block-level expression, so we need to
  757. // generate an extra node that just propagates the value of the
  758. // subexpression.
  759. const Expr *Ex = U->getSubExpr()->IgnoreParens();
  760. ProgramStateRef state = (*I)->getState();
  761. const LocationContext *LCtx = (*I)->getLocationContext();
  762. Bldr.generateNode(U, *I, state->BindExpr(U, LCtx,
  763. state->getSVal(Ex, LCtx)));
  764. }
  765. void ExprEngine::VisitUnaryOperator(const UnaryOperator* U, ExplodedNode *Pred,
  766. ExplodedNodeSet &Dst) {
  767. // FIXME: Prechecks eventually go in ::Visit().
  768. ExplodedNodeSet CheckedSet;
  769. getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, U, *this);
  770. ExplodedNodeSet EvalSet;
  771. StmtNodeBuilder Bldr(CheckedSet, EvalSet, *currBldrCtx);
  772. for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
  773. I != E; ++I) {
  774. switch (U->getOpcode()) {
  775. default: {
  776. Bldr.takeNodes(*I);
  777. ExplodedNodeSet Tmp;
  778. VisitIncrementDecrementOperator(U, *I, Tmp);
  779. Bldr.addNodes(Tmp);
  780. break;
  781. }
  782. case UO_Real: {
  783. const Expr *Ex = U->getSubExpr()->IgnoreParens();
  784. // FIXME: We don't have complex SValues yet.
  785. if (Ex->getType()->isAnyComplexType()) {
  786. // Just report "Unknown."
  787. break;
  788. }
  789. // For all other types, UO_Real is an identity operation.
  790. assert (U->getType() == Ex->getType());
  791. ProgramStateRef state = (*I)->getState();
  792. const LocationContext *LCtx = (*I)->getLocationContext();
  793. Bldr.generateNode(U, *I, state->BindExpr(U, LCtx,
  794. state->getSVal(Ex, LCtx)));
  795. break;
  796. }
  797. case UO_Imag: {
  798. const Expr *Ex = U->getSubExpr()->IgnoreParens();
  799. // FIXME: We don't have complex SValues yet.
  800. if (Ex->getType()->isAnyComplexType()) {
  801. // Just report "Unknown."
  802. break;
  803. }
  804. // For all other types, UO_Imag returns 0.
  805. ProgramStateRef state = (*I)->getState();
  806. const LocationContext *LCtx = (*I)->getLocationContext();
  807. SVal X = svalBuilder.makeZeroVal(Ex->getType());
  808. Bldr.generateNode(U, *I, state->BindExpr(U, LCtx, X));
  809. break;
  810. }
  811. case UO_AddrOf: {
  812. // Process pointer-to-member address operation.
  813. const Expr *Ex = U->getSubExpr()->IgnoreParens();
  814. if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Ex)) {
  815. const ValueDecl *VD = DRE->getDecl();
  816. if (isa<CXXMethodDecl>(VD) || isa<FieldDecl>(VD)) {
  817. ProgramStateRef State = (*I)->getState();
  818. const LocationContext *LCtx = (*I)->getLocationContext();
  819. SVal SV = svalBuilder.getMemberPointer(cast<DeclaratorDecl>(VD));
  820. Bldr.generateNode(U, *I, State->BindExpr(U, LCtx, SV));
  821. break;
  822. }
  823. }
  824. // Explicitly proceed with default handler for this case cascade.
  825. handleUOExtension(I, U, Bldr);
  826. break;
  827. }
  828. case UO_Plus:
  829. assert(!U->isGLValue());
  830. // FALL-THROUGH.
  831. case UO_Deref:
  832. case UO_Extension: {
  833. handleUOExtension(I, U, Bldr);
  834. break;
  835. }
  836. case UO_LNot:
  837. case UO_Minus:
  838. case UO_Not: {
  839. assert (!U->isGLValue());
  840. const Expr *Ex = U->getSubExpr()->IgnoreParens();
  841. ProgramStateRef state = (*I)->getState();
  842. const LocationContext *LCtx = (*I)->getLocationContext();
  843. // Get the value of the subexpression.
  844. SVal V = state->getSVal(Ex, LCtx);
  845. if (V.isUnknownOrUndef()) {
  846. Bldr.generateNode(U, *I, state->BindExpr(U, LCtx, V));
  847. break;
  848. }
  849. switch (U->getOpcode()) {
  850. default:
  851. llvm_unreachable("Invalid Opcode.");
  852. case UO_Not:
  853. // FIXME: Do we need to handle promotions?
  854. state = state->BindExpr(U, LCtx, evalComplement(V.castAs<NonLoc>()));
  855. break;
  856. case UO_Minus:
  857. // FIXME: Do we need to handle promotions?
  858. state = state->BindExpr(U, LCtx, evalMinus(V.castAs<NonLoc>()));
  859. break;
  860. case UO_LNot:
  861. // C99 6.5.3.3: "The expression !E is equivalent to (0==E)."
  862. //
  863. // Note: technically we do "E == 0", but this is the same in the
  864. // transfer functions as "0 == E".
  865. SVal Result;
  866. if (Optional<Loc> LV = V.getAs<Loc>()) {
  867. Loc X = svalBuilder.makeNull();
  868. Result = evalBinOp(state, BO_EQ, *LV, X, U->getType());
  869. }
  870. else if (Ex->getType()->isFloatingType()) {
  871. // FIXME: handle floating point types.
  872. Result = UnknownVal();
  873. } else {
  874. nonloc::ConcreteInt X(getBasicVals().getValue(0, Ex->getType()));
  875. Result = evalBinOp(state, BO_EQ, V.castAs<NonLoc>(), X,
  876. U->getType());
  877. }
  878. state = state->BindExpr(U, LCtx, Result);
  879. break;
  880. }
  881. Bldr.generateNode(U, *I, state);
  882. break;
  883. }
  884. }
  885. }
  886. getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, U, *this);
  887. }
  888. void ExprEngine::VisitIncrementDecrementOperator(const UnaryOperator* U,
  889. ExplodedNode *Pred,
  890. ExplodedNodeSet &Dst) {
  891. // Handle ++ and -- (both pre- and post-increment).
  892. assert (U->isIncrementDecrementOp());
  893. const Expr *Ex = U->getSubExpr()->IgnoreParens();
  894. const LocationContext *LCtx = Pred->getLocationContext();
  895. ProgramStateRef state = Pred->getState();
  896. SVal loc = state->getSVal(Ex, LCtx);
  897. // Perform a load.
  898. ExplodedNodeSet Tmp;
  899. evalLoad(Tmp, U, Ex, Pred, state, loc);
  900. ExplodedNodeSet Dst2;
  901. StmtNodeBuilder Bldr(Tmp, Dst2, *currBldrCtx);
  902. for (ExplodedNodeSet::iterator I=Tmp.begin(), E=Tmp.end();I!=E;++I) {
  903. state = (*I)->getState();
  904. assert(LCtx == (*I)->getLocationContext());
  905. SVal V2_untested = state->getSVal(Ex, LCtx);
  906. // Propagate unknown and undefined values.
  907. if (V2_untested.isUnknownOrUndef()) {
  908. Bldr.generateNode(U, *I, state->BindExpr(U, LCtx, V2_untested));
  909. continue;
  910. }
  911. DefinedSVal V2 = V2_untested.castAs<DefinedSVal>();
  912. // Handle all other values.
  913. BinaryOperator::Opcode Op = U->isIncrementOp() ? BO_Add : BO_Sub;
  914. // If the UnaryOperator has non-location type, use its type to create the
  915. // constant value. If the UnaryOperator has location type, create the
  916. // constant with int type and pointer width.
  917. SVal RHS;
  918. if (U->getType()->isAnyPointerType())
  919. RHS = svalBuilder.makeArrayIndex(1);
  920. else if (U->getType()->isIntegralOrEnumerationType())
  921. RHS = svalBuilder.makeIntVal(1, U->getType());
  922. else
  923. RHS = UnknownVal();
  924. SVal Result = evalBinOp(state, Op, V2, RHS, U->getType());
  925. // Conjure a new symbol if necessary to recover precision.
  926. if (Result.isUnknown()){
  927. DefinedOrUnknownSVal SymVal =
  928. svalBuilder.conjureSymbolVal(nullptr, Ex, LCtx,
  929. currBldrCtx->blockCount());
  930. Result = SymVal;
  931. // If the value is a location, ++/-- should always preserve
  932. // non-nullness. Check if the original value was non-null, and if so
  933. // propagate that constraint.
  934. if (Loc::isLocType(U->getType())) {
  935. DefinedOrUnknownSVal Constraint =
  936. svalBuilder.evalEQ(state, V2,svalBuilder.makeZeroVal(U->getType()));
  937. if (!state->assume(Constraint, true)) {
  938. // It isn't feasible for the original value to be null.
  939. // Propagate this constraint.
  940. Constraint = svalBuilder.evalEQ(state, SymVal,
  941. svalBuilder.makeZeroVal(U->getType()));
  942. state = state->assume(Constraint, false);
  943. assert(state);
  944. }
  945. }
  946. }
  947. // Since the lvalue-to-rvalue conversion is explicit in the AST,
  948. // we bind an l-value if the operator is prefix and an lvalue (in C++).
  949. if (U->isGLValue())
  950. state = state->BindExpr(U, LCtx, loc);
  951. else
  952. state = state->BindExpr(U, LCtx, U->isPostfix() ? V2 : Result);
  953. // Perform the store.
  954. Bldr.takeNodes(*I);
  955. ExplodedNodeSet Dst3;
  956. evalStore(Dst3, U, U, *I, state, loc, Result);
  957. Bldr.addNodes(Dst3);
  958. }
  959. Dst.insert(Dst2);
  960. }