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