ExprEngineC.cpp 40 KB

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