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