ExprEngineC.cpp 39 KB

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