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