clang  8.0.0svn
ExprEngineC.cpp
Go to the documentation of this file.
1 //=-- ExprEngineC.cpp - ExprEngine support for C expressions ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines ExprEngine's support for C expressions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ExprCXX.h"
15 #include "clang/AST/DeclCXX.h"
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.
30  SVal Symbol, SVal Other, Expr* Expression, SValBuilder &svalBuilder,
31  unsigned Count, const LocationContext *LCtx) {
32  QualType Ty = Expression->getType();
33  if (Other.getAs<Loc>() &&
35  Symbol.isUnknown()) {
36  return svalBuilder.conjureSymbolVal(Expression, LCtx, Ty, Count);
37  }
38  return Symbol;
39 }
40 
42  ExplodedNode *Pred,
43  ExplodedNodeSet &Dst) {
44 
45  Expr *LHS = B->getLHS()->IgnoreParens();
46  Expr *RHS = B->getRHS()->IgnoreParens();
47 
48  // FIXME: Prechecks eventually go in ::Visit().
49  ExplodedNodeSet CheckedSet;
50  ExplodedNodeSet Tmp2;
51  getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, B, *this);
52 
53  // With both the LHS and RHS evaluated, process the operation itself.
54  for (ExplodedNodeSet::iterator it=CheckedSet.begin(), ei=CheckedSet.end();
55  it != ei; ++it) {
56 
57  ProgramStateRef state = (*it)->getState();
58  const LocationContext *LCtx = (*it)->getLocationContext();
59  SVal LeftV = state->getSVal(LHS, LCtx);
60  SVal RightV = state->getSVal(RHS, LCtx);
61 
63 
64  if (Op == BO_Assign) {
65  // EXPERIMENTAL: "Conjured" symbols.
66  // FIXME: Handle structs.
67  if (RightV.isUnknown()) {
68  unsigned Count = currBldrCtx->blockCount();
69  RightV = svalBuilder.conjureSymbolVal(nullptr, B->getRHS(), LCtx,
70  Count);
71  }
72  // Simulate the effects of a "store": bind the value of the RHS
73  // to the L-Value represented by the LHS.
74  SVal ExprVal = B->isGLValue() ? LeftV : RightV;
75  evalStore(Tmp2, B, LHS, *it, state->BindExpr(B, LCtx, ExprVal),
76  LeftV, RightV);
77  continue;
78  }
79 
80  if (!B->isAssignmentOp()) {
81  StmtNodeBuilder Bldr(*it, Tmp2, *currBldrCtx);
82 
83  if (B->isAdditiveOp()) {
84  // TODO: This can be removed after we enable history tracking with
85  // SymSymExpr.
86  unsigned Count = currBldrCtx->blockCount();
88  RightV, LeftV, RHS, svalBuilder, Count, LCtx);
90  LeftV, RightV, LHS, svalBuilder, Count, LCtx);
91  }
92 
93  // Although we don't yet model pointers-to-members, we do need to make
94  // sure that the members of temporaries have a valid 'this' pointer for
95  // other checks.
96  if (B->getOpcode() == BO_PtrMemD)
97  state = createTemporaryRegionIfNeeded(state, LCtx, LHS);
98 
99  // Process non-assignments except commas or short-circuited
100  // logical expressions (LAnd and LOr).
101  SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
102  if (!Result.isUnknown()) {
103  state = state->BindExpr(B, LCtx, Result);
104  }
105 
106  Bldr.generateNode(B, *it, state);
107  continue;
108  }
109 
110  assert (B->isCompoundAssignmentOp());
111 
112  switch (Op) {
113  default:
114  llvm_unreachable("Invalid opcode for compound assignment.");
115  case BO_MulAssign: Op = BO_Mul; break;
116  case BO_DivAssign: Op = BO_Div; break;
117  case BO_RemAssign: Op = BO_Rem; break;
118  case BO_AddAssign: Op = BO_Add; break;
119  case BO_SubAssign: Op = BO_Sub; break;
120  case BO_ShlAssign: Op = BO_Shl; break;
121  case BO_ShrAssign: Op = BO_Shr; break;
122  case BO_AndAssign: Op = BO_And; break;
123  case BO_XorAssign: Op = BO_Xor; break;
124  case BO_OrAssign: Op = BO_Or; break;
125  }
126 
127  // Perform a load (the LHS). This performs the checks for
128  // null dereferences, and so on.
129  ExplodedNodeSet Tmp;
130  SVal location = LeftV;
131  evalLoad(Tmp, B, LHS, *it, state, location);
132 
133  for (ExplodedNodeSet::iterator I = Tmp.begin(), E = Tmp.end(); I != E;
134  ++I) {
135 
136  state = (*I)->getState();
137  const LocationContext *LCtx = (*I)->getLocationContext();
138  SVal V = state->getSVal(LHS, LCtx);
139 
140  // Get the computation type.
141  QualType CTy =
142  cast<CompoundAssignOperator>(B)->getComputationResultType();
143  CTy = getContext().getCanonicalType(CTy);
144 
145  QualType CLHSTy =
146  cast<CompoundAssignOperator>(B)->getComputationLHSType();
147  CLHSTy = getContext().getCanonicalType(CLHSTy);
148 
150 
151  // Promote LHS.
152  V = svalBuilder.evalCast(V, CLHSTy, LTy);
153 
154  // Compute the result of the operation.
155  SVal Result = svalBuilder.evalCast(evalBinOp(state, Op, V, RightV, CTy),
156  B->getType(), CTy);
157 
158  // EXPERIMENTAL: "Conjured" symbols.
159  // FIXME: Handle structs.
160 
161  SVal LHSVal;
162 
163  if (Result.isUnknown()) {
164  // The symbolic value is actually for the type of the left-hand side
165  // expression, not the computation type, as this is the value the
166  // LValue on the LHS will bind to.
167  LHSVal = svalBuilder.conjureSymbolVal(nullptr, B->getRHS(), LCtx, LTy,
168  currBldrCtx->blockCount());
169  // However, we need to convert the symbol to the computation type.
170  Result = svalBuilder.evalCast(LHSVal, CTy, LTy);
171  }
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, *I, state, location, LHSVal);
186  }
187  }
188 
189  // FIXME: postvisits eventually go in ::Visit()
190  getCheckerManager().runCheckersForPostStmt(Dst, Tmp2, B, *this);
191 }
192 
194  ExplodedNodeSet &Dst) {
195 
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  BlockDataRegion::referenced_vars_iterator I = BDR->referenced_vars_begin(),
212  E = BDR->referenced_vars_end();
213 
214  auto CI = BD->capture_begin();
215  auto CE = BD->capture_end();
216  for (; I != E; ++I) {
217  const VarRegion *capturedR = I.getCapturedRegion();
218  const VarRegion *originalR = I.getOriginalRegion();
219 
220  // If the capture had a copy expression, use the result of evaluating
221  // that expression, otherwise use the original value.
222  // We rely on the invariant that the block declaration's capture variables
223  // are a prefix of the BlockDataRegion's referenced vars (which may include
224  // referenced globals, etc.) to enable fast lookup of the capture for a
225  // given referenced var.
226  const Expr *copyExpr = nullptr;
227  if (CI != CE) {
228  assert(CI->getVariable() == capturedR->getDecl());
229  copyExpr = CI->getCopyExpr();
230  CI++;
231  }
232 
233  if (capturedR != originalR) {
234  SVal originalV;
235  const LocationContext *LCtx = Pred->getLocationContext();
236  if (copyExpr) {
237  originalV = State->getSVal(copyExpr, LCtx);
238  } else {
239  originalV = State->getSVal(loc::MemRegionVal(originalR));
240  }
241  State = State->bindLoc(loc::MemRegionVal(capturedR), originalV, LCtx);
242  }
243  }
244  }
245 
246  ExplodedNodeSet Tmp;
247  StmtNodeBuilder Bldr(Pred, Tmp, *currBldrCtx);
248  Bldr.generateNode(BE, Pred,
249  State->BindExpr(BE, Pred->getLocationContext(), V),
251 
252  // FIXME: Move all post/pre visits to ::Visit().
253  getCheckerManager().runCheckersForPostStmt(Dst, Tmp, BE, *this);
254 }
255 
257  ProgramStateRef state, const Expr* Ex, const LocationContext* LCtx,
258  QualType T, QualType ExTy, const CastExpr* CastE, StmtNodeBuilder& Bldr,
259  ExplodedNode* Pred) {
260  if (T->isLValueReferenceType()) {
261  assert(!CastE->getType()->isLValueReferenceType());
262  ExTy = getContext().getLValueReferenceType(ExTy);
263  } else if (T->isRValueReferenceType()) {
264  assert(!CastE->getType()->isRValueReferenceType());
265  ExTy = getContext().getRValueReferenceType(ExTy);
266  }
267  // Delegate to SValBuilder to process.
268  SVal OrigV = state->getSVal(Ex, LCtx);
269  SVal V = svalBuilder.evalCast(OrigV, T, ExTy);
270  // Negate the result if we're treating the boolean as a signed i1
271  if (CastE->getCastKind() == CK_BooleanToSignedIntegral)
272  V = evalMinus(V);
273  state = state->BindExpr(CastE, LCtx, V);
274  if (V.isUnknown() && !OrigV.isUnknown()) {
275  state = escapeValue(state, OrigV, PSK_EscapeOther);
276  }
277  Bldr.generateNode(CastE, Pred, state);
278 
279  return state;
280 }
281 
283  ProgramStateRef state, const LocationContext* LCtx, const CastExpr* CastE,
284  StmtNodeBuilder &Bldr, ExplodedNode* Pred) {
285  // Recover some path sensitivity by conjuring a new value.
286  QualType resultType = CastE->getType();
287  if (CastE->isGLValue())
288  resultType = getContext().getPointerType(resultType);
289  SVal result = svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx,
290  resultType,
291  currBldrCtx->blockCount());
292  state = state->BindExpr(CastE, LCtx, result);
293  Bldr.generateNode(CastE, Pred, state);
294 
295  return state;
296 }
297 
298 void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
299  ExplodedNode *Pred, ExplodedNodeSet &Dst) {
300 
301  ExplodedNodeSet dstPreStmt;
302  getCheckerManager().runCheckersForPreStmt(dstPreStmt, Pred, CastE, *this);
303 
304  if (CastE->getCastKind() == CK_LValueToRValue) {
305  for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = dstPreStmt.end();
306  I!=E; ++I) {
307  ExplodedNode *subExprNode = *I;
308  ProgramStateRef state = subExprNode->getState();
309  const LocationContext *LCtx = subExprNode->getLocationContext();
310  evalLoad(Dst, CastE, CastE, subExprNode, state, state->getSVal(Ex, LCtx));
311  }
312  return;
313  }
314 
315  // All other casts.
316  QualType T = CastE->getType();
317  QualType ExTy = Ex->getType();
318 
319  if (const ExplicitCastExpr *ExCast=dyn_cast_or_null<ExplicitCastExpr>(CastE))
320  T = ExCast->getTypeAsWritten();
321 
322  StmtNodeBuilder Bldr(dstPreStmt, Dst, *currBldrCtx);
323  for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = dstPreStmt.end();
324  I != E; ++I) {
325 
326  Pred = *I;
327  ProgramStateRef state = Pred->getState();
328  const LocationContext *LCtx = Pred->getLocationContext();
329 
330  switch (CastE->getCastKind()) {
331  case CK_LValueToRValue:
332  llvm_unreachable("LValueToRValue casts handled earlier.");
333  case CK_ToVoid:
334  continue;
335  // The analyzer doesn't do anything special with these casts,
336  // since it understands retain/release semantics already.
337  case CK_ARCProduceObject:
338  case CK_ARCConsumeObject:
339  case CK_ARCReclaimReturnedObject:
340  case CK_ARCExtendBlockObject: // Fall-through.
341  case CK_CopyAndAutoreleaseBlockObject:
342  // The analyser can ignore atomic casts for now, although some future
343  // checkers may want to make certain that you're not modifying the same
344  // value through atomic and nonatomic pointers.
345  case CK_AtomicToNonAtomic:
346  case CK_NonAtomicToAtomic:
347  // True no-ops.
348  case CK_NoOp:
349  case CK_ConstructorConversion:
350  case CK_UserDefinedConversion:
351  case CK_FunctionToPointerDecay:
352  case CK_BuiltinFnToFnPtr: {
353  // Copy the SVal of Ex to CastE.
354  ProgramStateRef state = Pred->getState();
355  const LocationContext *LCtx = Pred->getLocationContext();
356  SVal V = state->getSVal(Ex, LCtx);
357  state = state->BindExpr(CastE, LCtx, V);
358  Bldr.generateNode(CastE, Pred, state);
359  continue;
360  }
361  case CK_MemberPointerToBoolean:
362  case CK_PointerToBoolean: {
363  SVal V = state->getSVal(Ex, LCtx);
364  auto PTMSV = V.getAs<nonloc::PointerToMember>();
365  if (PTMSV)
366  V = svalBuilder.makeTruthVal(!PTMSV->isNullMemberPointer(), ExTy);
367  if (V.isUndef() || PTMSV) {
368  state = state->BindExpr(CastE, LCtx, V);
369  Bldr.generateNode(CastE, Pred, state);
370  continue;
371  }
372  // Explicitly proceed with default handler for this case cascade.
373  state =
374  handleLValueBitCast(state, Ex, LCtx, T, ExTy, CastE, Bldr, Pred);
375  continue;
376  }
377  case CK_Dependent:
378  case CK_ArrayToPointerDecay:
379  case CK_BitCast:
380  case CK_AddressSpaceConversion:
381  case CK_BooleanToSignedIntegral:
382  case CK_NullToPointer:
383  case CK_IntegralToPointer:
384  case CK_PointerToIntegral: {
385  SVal V = state->getSVal(Ex, LCtx);
386  if (V.getAs<nonloc::PointerToMember>()) {
387  state = state->BindExpr(CastE, LCtx, UnknownVal());
388  Bldr.generateNode(CastE, Pred, state);
389  continue;
390  }
391  // Explicitly proceed with default handler for this case cascade.
392  state =
393  handleLValueBitCast(state, Ex, LCtx, T, ExTy, CastE, Bldr, Pred);
394  continue;
395  }
396  case CK_IntegralToBoolean:
397  case CK_IntegralToFloating:
398  case CK_FloatingToIntegral:
399  case CK_FloatingToBoolean:
400  case CK_FloatingCast:
401  case CK_FloatingRealToComplex:
402  case CK_FloatingComplexToReal:
403  case CK_FloatingComplexToBoolean:
404  case CK_FloatingComplexCast:
405  case CK_FloatingComplexToIntegralComplex:
406  case CK_IntegralRealToComplex:
407  case CK_IntegralComplexToReal:
408  case CK_IntegralComplexToBoolean:
409  case CK_IntegralComplexCast:
410  case CK_IntegralComplexToFloatingComplex:
411  case CK_CPointerToObjCPointerCast:
412  case CK_BlockPointerToObjCPointerCast:
413  case CK_AnyPointerToBlockPointerCast:
414  case CK_ObjCObjectLValueCast:
415  case CK_ZeroToOCLOpaqueType:
416  case CK_IntToOCLSampler:
417  case CK_LValueBitCast:
418  case CK_FixedPointCast:
419  case CK_FixedPointToBoolean: {
420  state =
421  handleLValueBitCast(state, Ex, LCtx, T, ExTy, CastE, Bldr, Pred);
422  continue;
423  }
424  case CK_IntegralCast: {
425  // Delegate to SValBuilder to process.
426  SVal V = state->getSVal(Ex, LCtx);
427  V = svalBuilder.evalIntegralCast(state, V, T, ExTy);
428  state = state->BindExpr(CastE, LCtx, V);
429  Bldr.generateNode(CastE, Pred, state);
430  continue;
431  }
432  case CK_DerivedToBase:
433  case CK_UncheckedDerivedToBase: {
434  // For DerivedToBase cast, delegate to the store manager.
435  SVal val = state->getSVal(Ex, LCtx);
436  val = getStoreManager().evalDerivedToBase(val, CastE);
437  state = state->BindExpr(CastE, LCtx, val);
438  Bldr.generateNode(CastE, Pred, state);
439  continue;
440  }
441  // Handle C++ dyn_cast.
442  case CK_Dynamic: {
443  SVal val = state->getSVal(Ex, LCtx);
444 
445  // Compute the type of the result.
446  QualType resultType = CastE->getType();
447  if (CastE->isGLValue())
448  resultType = getContext().getPointerType(resultType);
449 
450  bool Failed = false;
451 
452  // Check if the value being cast evaluates to 0.
453  if (val.isZeroConstant())
454  Failed = true;
455  // Else, evaluate the cast.
456  else
457  val = getStoreManager().attemptDownCast(val, T, Failed);
458 
459  if (Failed) {
460  if (T->isReferenceType()) {
461  // A bad_cast exception is thrown if input value is a reference.
462  // Currently, we model this, by generating a sink.
463  Bldr.generateSink(CastE, Pred, state);
464  continue;
465  } else {
466  // If the cast fails on a pointer, bind to 0.
467  state = state->BindExpr(CastE, LCtx, svalBuilder.makeNull());
468  }
469  } else {
470  // If we don't know if the cast succeeded, conjure a new symbol.
471  if (val.isUnknown()) {
472  DefinedOrUnknownSVal NewSym =
473  svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx, resultType,
474  currBldrCtx->blockCount());
475  state = state->BindExpr(CastE, LCtx, NewSym);
476  } else
477  // Else, bind to the derived region value.
478  state = state->BindExpr(CastE, LCtx, val);
479  }
480  Bldr.generateNode(CastE, Pred, state);
481  continue;
482  }
483  case CK_BaseToDerived: {
484  SVal val = state->getSVal(Ex, LCtx);
485  QualType resultType = CastE->getType();
486  if (CastE->isGLValue())
487  resultType = getContext().getPointerType(resultType);
488 
489  bool Failed = false;
490 
491  if (!val.isConstant()) {
492  val = getStoreManager().attemptDownCast(val, T, Failed);
493  }
494 
495  // Failed to cast or the result is unknown, fall back to conservative.
496  if (Failed || val.isUnknown()) {
497  val =
498  svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx, resultType,
499  currBldrCtx->blockCount());
500  }
501  state = state->BindExpr(CastE, LCtx, val);
502  Bldr.generateNode(CastE, Pred, state);
503  continue;
504  }
505  case CK_NullToMemberPointer: {
506  SVal V = svalBuilder.getMemberPointer(nullptr);
507  state = state->BindExpr(CastE, LCtx, V);
508  Bldr.generateNode(CastE, Pred, state);
509  continue;
510  }
511  case CK_DerivedToBaseMemberPointer:
512  case CK_BaseToDerivedMemberPointer:
513  case CK_ReinterpretMemberPointer: {
514  SVal V = state->getSVal(Ex, LCtx);
515  if (auto PTMSV = V.getAs<nonloc::PointerToMember>()) {
516  SVal CastedPTMSV = svalBuilder.makePointerToMember(
517  getBasicVals().accumCXXBase(
518  llvm::make_range<CastExpr::path_const_iterator>(
519  CastE->path_begin(), CastE->path_end()), *PTMSV));
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  state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
526  continue;
527  }
528  // Various C++ casts that are not handled yet.
529  case CK_ToUnion:
530  case CK_VectorSplat: {
531  state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
532  continue;
533  }
534  }
535  }
536 }
537 
539  ExplodedNode *Pred,
540  ExplodedNodeSet &Dst) {
541  StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
542 
543  ProgramStateRef State = Pred->getState();
544  const LocationContext *LCtx = Pred->getLocationContext();
545 
546  const Expr *Init = CL->getInitializer();
547  SVal V = State->getSVal(CL->getInitializer(), LCtx);
548 
549  if (isa<CXXConstructExpr>(Init) || isa<CXXStdInitializerListExpr>(Init)) {
550  // No work needed. Just pass the value up to this expression.
551  } else {
552  assert(isa<InitListExpr>(Init));
553  Loc CLLoc = State->getLValue(CL, LCtx);
554  State = State->bindLoc(CLLoc, V, LCtx);
555 
556  if (CL->isGLValue())
557  V = CLLoc;
558  }
559 
560  B.generateNode(CL, Pred, State->BindExpr(CL, LCtx, V));
561 }
562 
564  ExplodedNodeSet &Dst) {
565  // Assumption: The CFG has one DeclStmt per Decl.
566  const VarDecl *VD = dyn_cast_or_null<VarDecl>(*DS->decl_begin());
567 
568  if (!VD) {
569  //TODO:AZ: remove explicit insertion after refactoring is done.
570  Dst.insert(Pred);
571  return;
572  }
573 
574  // FIXME: all pre/post visits should eventually be handled by ::Visit().
575  ExplodedNodeSet dstPreVisit;
576  getCheckerManager().runCheckersForPreStmt(dstPreVisit, Pred, DS, *this);
577 
578  ExplodedNodeSet dstEvaluated;
579  StmtNodeBuilder B(dstPreVisit, dstEvaluated, *currBldrCtx);
580  for (ExplodedNodeSet::iterator I = dstPreVisit.begin(), E = dstPreVisit.end();
581  I!=E; ++I) {
582  ExplodedNode *N = *I;
584  const LocationContext *LC = N->getLocationContext();
585 
586  // Decls without InitExpr are not initialized explicitly.
587  if (const Expr *InitEx = VD->getInit()) {
588 
589  // Note in the state that the initialization has occurred.
590  ExplodedNode *UpdatedN = N;
591  SVal InitVal = state->getSVal(InitEx, LC);
592 
593  assert(DS->isSingleDecl());
594  if (getObjectUnderConstruction(state, DS, LC)) {
595  state = finishObjectConstruction(state, DS, LC);
596  // We constructed the object directly in the variable.
597  // No need to bind anything.
598  B.generateNode(DS, UpdatedN, state);
599  } else {
600  // Recover some path-sensitivity if a scalar value evaluated to
601  // UnknownVal.
602  if (InitVal.isUnknown()) {
603  QualType Ty = InitEx->getType();
604  if (InitEx->isGLValue()) {
605  Ty = getContext().getPointerType(Ty);
606  }
607 
608  InitVal = svalBuilder.conjureSymbolVal(nullptr, InitEx, LC, Ty,
609  currBldrCtx->blockCount());
610  }
611 
612 
613  B.takeNodes(UpdatedN);
614  ExplodedNodeSet Dst2;
615  evalBind(Dst2, DS, UpdatedN, state->getLValue(VD, LC), InitVal, true);
616  B.addNodes(Dst2);
617  }
618  }
619  else {
620  B.generateNode(DS, N, state);
621  }
622  }
623 
624  getCheckerManager().runCheckersForPostStmt(Dst, B.getResults(), DS, *this);
625 }
626 
628  ExplodedNodeSet &Dst) {
629  assert(B->getOpcode() == BO_LAnd ||
630  B->getOpcode() == BO_LOr);
631 
632  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
633  ProgramStateRef state = Pred->getState();
634 
635  if (B->getType()->isVectorType()) {
636  // FIXME: We do not model vector arithmetic yet. When adding support for
637  // that, note that the CFG-based reasoning below does not apply, because
638  // logical operators on vectors are not short-circuit. Currently they are
639  // modeled as short-circuit in Clang CFG but this is incorrect.
640  // Do not set the value for the expression. It'd be UnknownVal by default.
641  Bldr.generateNode(B, Pred, state);
642  return;
643  }
644 
645  ExplodedNode *N = Pred;
646  while (!N->getLocation().getAs<BlockEntrance>()) {
647  ProgramPoint P = N->getLocation();
648  assert(P.getAs<PreStmt>()|| P.getAs<PreStmtPurgeDeadSymbols>());
649  (void) P;
650  assert(N->pred_size() == 1);
651  N = *N->pred_begin();
652  }
653  assert(N->pred_size() == 1);
654  N = *N->pred_begin();
655  BlockEdge BE = N->getLocation().castAs<BlockEdge>();
656  SVal X;
657 
658  // Determine the value of the expression by introspecting how we
659  // got this location in the CFG. This requires looking at the previous
660  // block we were in and what kind of control-flow transfer was involved.
661  const CFGBlock *SrcBlock = BE.getSrc();
662  // The only terminator (if there is one) that makes sense is a logical op.
663  CFGTerminator T = SrcBlock->getTerminator();
664  if (const BinaryOperator *Term = cast_or_null<BinaryOperator>(T.getStmt())) {
665  (void) Term;
666  assert(Term->isLogicalOp());
667  assert(SrcBlock->succ_size() == 2);
668  // Did we take the true or false branch?
669  unsigned constant = (*SrcBlock->succ_begin() == BE.getDst()) ? 1 : 0;
670  X = svalBuilder.makeIntVal(constant, B->getType());
671  }
672  else {
673  // If there is no terminator, by construction the last statement
674  // in SrcBlock is the value of the enclosing expression.
675  // However, we still need to constrain that value to be 0 or 1.
676  assert(!SrcBlock->empty());
677  CFGStmt Elem = SrcBlock->rbegin()->castAs<CFGStmt>();
678  const Expr *RHS = cast<Expr>(Elem.getStmt());
679  SVal RHSVal = N->getState()->getSVal(RHS, Pred->getLocationContext());
680 
681  if (RHSVal.isUndef()) {
682  X = RHSVal;
683  } else {
684  // We evaluate "RHSVal != 0" expression which result in 0 if the value is
685  // known to be false, 1 if the value is known to be true and a new symbol
686  // when the assumption is unknown.
688  X = evalBinOp(N->getState(), BO_NE,
689  svalBuilder.evalCast(RHSVal, B->getType(), RHS->getType()),
690  Zero, B->getType());
691  }
692  }
693  Bldr.generateNode(B, Pred, state->BindExpr(B, Pred->getLocationContext(), X));
694 }
695 
697  ExplodedNode *Pred,
698  ExplodedNodeSet &Dst) {
699  StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
700 
701  ProgramStateRef state = Pred->getState();
702  const LocationContext *LCtx = Pred->getLocationContext();
704  unsigned NumInitElements = IE->getNumInits();
705 
706  if (!IE->isGLValue() &&
707  (T->isArrayType() || T->isRecordType() || T->isVectorType() ||
708  T->isAnyComplexType())) {
709  llvm::ImmutableList<SVal> vals = getBasicVals().getEmptySValList();
710 
711  // Handle base case where the initializer has no elements.
712  // e.g: static int* myArray[] = {};
713  if (NumInitElements == 0) {
714  SVal V = svalBuilder.makeCompoundVal(T, vals);
715  B.generateNode(IE, Pred, state->BindExpr(IE, LCtx, V));
716  return;
717  }
718 
720  ei = IE->rend(); it != ei; ++it) {
721  SVal V = state->getSVal(cast<Expr>(*it), LCtx);
722  vals = getBasicVals().prependSVal(V, vals);
723  }
724 
725  B.generateNode(IE, Pred,
726  state->BindExpr(IE, LCtx,
727  svalBuilder.makeCompoundVal(T, vals)));
728  return;
729  }
730 
731  // Handle scalars: int{5} and int{} and GLvalues.
732  // Note, if the InitListExpr is a GLvalue, it means that there is an address
733  // representing it, so it must have a single init element.
734  assert(NumInitElements <= 1);
735 
736  SVal V;
737  if (NumInitElements == 0)
738  V = getSValBuilder().makeZeroVal(T);
739  else
740  V = state->getSVal(IE->getInit(0), LCtx);
741 
742  B.generateNode(IE, Pred, state->BindExpr(IE, LCtx, V));
743 }
744 
746  const Expr *L,
747  const Expr *R,
748  ExplodedNode *Pred,
749  ExplodedNodeSet &Dst) {
750  assert(L && R);
751 
752  StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
753  ProgramStateRef state = Pred->getState();
754  const LocationContext *LCtx = Pred->getLocationContext();
755  const CFGBlock *SrcBlock = nullptr;
756 
757  // Find the predecessor block.
758  ProgramStateRef SrcState = state;
759  for (const ExplodedNode *N = Pred ; N ; N = *N->pred_begin()) {
760  ProgramPoint PP = N->getLocation();
761  if (PP.getAs<PreStmtPurgeDeadSymbols>() || PP.getAs<BlockEntrance>()) {
762  // If the state N has multiple predecessors P, it means that successors
763  // of P are all equivalent.
764  // In turn, that means that all nodes at P are equivalent in terms
765  // of observable behavior at N, and we can follow any of them.
766  // FIXME: a more robust solution which does not walk up the tree.
767  continue;
768  }
769  SrcBlock = PP.castAs<BlockEdge>().getSrc();
770  SrcState = N->getState();
771  break;
772  }
773 
774  assert(SrcBlock && "missing function entry");
775 
776  // Find the last expression in the predecessor block. That is the
777  // expression that is used for the value of the ternary expression.
778  bool hasValue = false;
779  SVal V;
780 
781  for (CFGElement CE : llvm::reverse(*SrcBlock)) {
782  if (Optional<CFGStmt> CS = CE.getAs<CFGStmt>()) {
783  const Expr *ValEx = cast<Expr>(CS->getStmt());
784  ValEx = ValEx->IgnoreParens();
785 
786  // For GNU extension '?:' operator, the left hand side will be an
787  // OpaqueValueExpr, so get the underlying expression.
788  if (const OpaqueValueExpr *OpaqueEx = dyn_cast<OpaqueValueExpr>(L))
789  L = OpaqueEx->getSourceExpr();
790 
791  // If the last expression in the predecessor block matches true or false
792  // subexpression, get its the value.
793  if (ValEx == L->IgnoreParens() || ValEx == R->IgnoreParens()) {
794  hasValue = true;
795  V = SrcState->getSVal(ValEx, LCtx);
796  }
797  break;
798  }
799  }
800 
801  if (!hasValue)
802  V = svalBuilder.conjureSymbolVal(nullptr, Ex, LCtx,
803  currBldrCtx->blockCount());
804 
805  // Generate a new node with the binding from the appropriate path.
806  B.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V, true));
807 }
808 
809 void ExprEngine::
811  ExplodedNode *Pred, ExplodedNodeSet &Dst) {
812  StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
813  APSInt IV;
814  if (OOE->EvaluateAsInt(IV, getContext())) {
815  assert(IV.getBitWidth() == getContext().getTypeSize(OOE->getType()));
816  assert(OOE->getType()->isBuiltinType());
817  assert(OOE->getType()->getAs<BuiltinType>()->isInteger());
818  assert(IV.isSigned() == OOE->getType()->isSignedIntegerType());
819  SVal X = svalBuilder.makeIntVal(IV);
820  B.generateNode(OOE, Pred,
821  Pred->getState()->BindExpr(OOE, Pred->getLocationContext(),
822  X));
823  }
824  // FIXME: Handle the case where __builtin_offsetof is not a constant.
825 }
826 
827 
828 void ExprEngine::
830  ExplodedNode *Pred,
831  ExplodedNodeSet &Dst) {
832  // FIXME: Prechecks eventually go in ::Visit().
833  ExplodedNodeSet CheckedSet;
834  getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, Ex, *this);
835 
836  ExplodedNodeSet EvalSet;
837  StmtNodeBuilder Bldr(CheckedSet, EvalSet, *currBldrCtx);
838 
839  QualType T = Ex->getTypeOfArgument();
840 
841  for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
842  I != E; ++I) {
843  if (Ex->getKind() == UETT_SizeOf) {
844  if (!T->isIncompleteType() && !T->isConstantSizeType()) {
845  assert(T->isVariableArrayType() && "Unknown non-constant-sized type.");
846 
847  // FIXME: Add support for VLA type arguments and VLA expressions.
848  // When that happens, we should probably refactor VLASizeChecker's code.
849  continue;
850  } else if (T->getAs<ObjCObjectType>()) {
851  // Some code tries to take the sizeof an ObjCObjectType, relying that
852  // the compiler has laid out its representation. Just report Unknown
853  // for these.
854  continue;
855  }
856  }
857 
858  APSInt Value = Ex->EvaluateKnownConstInt(getContext());
859  CharUnits amt = CharUnits::fromQuantity(Value.getZExtValue());
860 
861  ProgramStateRef state = (*I)->getState();
862  state = state->BindExpr(Ex, (*I)->getLocationContext(),
863  svalBuilder.makeIntVal(amt.getQuantity(),
864  Ex->getType()));
865  Bldr.generateNode(Ex, *I, state);
866  }
867 
868  getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, Ex, *this);
869 }
870 
872  const UnaryOperator *U,
873  StmtNodeBuilder &Bldr) {
874  // FIXME: We can probably just have some magic in Environment::getSVal()
875  // that propagates values, instead of creating a new node here.
876  //
877  // Unary "+" is a no-op, similar to a parentheses. We still have places
878  // where it may be a block-level expression, so we need to
879  // generate an extra node that just propagates the value of the
880  // subexpression.
881  const Expr *Ex = U->getSubExpr()->IgnoreParens();
882  ProgramStateRef state = (*I)->getState();
883  const LocationContext *LCtx = (*I)->getLocationContext();
884  Bldr.generateNode(U, *I, state->BindExpr(U, LCtx,
885  state->getSVal(Ex, LCtx)));
886 }
887 
889  ExplodedNodeSet &Dst) {
890  // FIXME: Prechecks eventually go in ::Visit().
891  ExplodedNodeSet CheckedSet;
892  getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, U, *this);
893 
894  ExplodedNodeSet EvalSet;
895  StmtNodeBuilder Bldr(CheckedSet, EvalSet, *currBldrCtx);
896 
897  for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
898  I != E; ++I) {
899  switch (U->getOpcode()) {
900  default: {
901  Bldr.takeNodes(*I);
902  ExplodedNodeSet Tmp;
904  Bldr.addNodes(Tmp);
905  break;
906  }
907  case UO_Real: {
908  const Expr *Ex = U->getSubExpr()->IgnoreParens();
909 
910  // FIXME: We don't have complex SValues yet.
911  if (Ex->getType()->isAnyComplexType()) {
912  // Just report "Unknown."
913  break;
914  }
915 
916  // For all other types, UO_Real is an identity operation.
917  assert (U->getType() == Ex->getType());
918  ProgramStateRef state = (*I)->getState();
919  const LocationContext *LCtx = (*I)->getLocationContext();
920  Bldr.generateNode(U, *I, state->BindExpr(U, LCtx,
921  state->getSVal(Ex, LCtx)));
922  break;
923  }
924 
925  case UO_Imag: {
926  const Expr *Ex = U->getSubExpr()->IgnoreParens();
927  // FIXME: We don't have complex SValues yet.
928  if (Ex->getType()->isAnyComplexType()) {
929  // Just report "Unknown."
930  break;
931  }
932  // For all other types, UO_Imag returns 0.
933  ProgramStateRef state = (*I)->getState();
934  const LocationContext *LCtx = (*I)->getLocationContext();
935  SVal X = svalBuilder.makeZeroVal(Ex->getType());
936  Bldr.generateNode(U, *I, state->BindExpr(U, LCtx, X));
937  break;
938  }
939 
940  case UO_AddrOf: {
941  // Process pointer-to-member address operation.
942  const Expr *Ex = U->getSubExpr()->IgnoreParens();
943  if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Ex)) {
944  const ValueDecl *VD = DRE->getDecl();
945 
946  if (isa<CXXMethodDecl>(VD) || isa<FieldDecl>(VD)) {
947  ProgramStateRef State = (*I)->getState();
948  const LocationContext *LCtx = (*I)->getLocationContext();
949  SVal SV = svalBuilder.getMemberPointer(cast<DeclaratorDecl>(VD));
950  Bldr.generateNode(U, *I, State->BindExpr(U, LCtx, SV));
951  break;
952  }
953  }
954  // Explicitly proceed with default handler for this case cascade.
955  handleUOExtension(I, U, Bldr);
956  break;
957  }
958  case UO_Plus:
959  assert(!U->isGLValue());
960  LLVM_FALLTHROUGH;
961  case UO_Deref:
962  case UO_Extension: {
963  handleUOExtension(I, U, Bldr);
964  break;
965  }
966 
967  case UO_LNot:
968  case UO_Minus:
969  case UO_Not: {
970  assert (!U->isGLValue());
971  const Expr *Ex = U->getSubExpr()->IgnoreParens();
972  ProgramStateRef state = (*I)->getState();
973  const LocationContext *LCtx = (*I)->getLocationContext();
974 
975  // Get the value of the subexpression.
976  SVal V = state->getSVal(Ex, LCtx);
977 
978  if (V.isUnknownOrUndef()) {
979  Bldr.generateNode(U, *I, state->BindExpr(U, LCtx, V));
980  break;
981  }
982 
983  switch (U->getOpcode()) {
984  default:
985  llvm_unreachable("Invalid Opcode.");
986  case UO_Not:
987  // FIXME: Do we need to handle promotions?
988  state = state->BindExpr(U, LCtx, evalComplement(V.castAs<NonLoc>()));
989  break;
990  case UO_Minus:
991  // FIXME: Do we need to handle promotions?
992  state = state->BindExpr(U, LCtx, evalMinus(V.castAs<NonLoc>()));
993  break;
994  case UO_LNot:
995  // C99 6.5.3.3: "The expression !E is equivalent to (0==E)."
996  //
997  // Note: technically we do "E == 0", but this is the same in the
998  // transfer functions as "0 == E".
999  SVal Result;
1000  if (Optional<Loc> LV = V.getAs<Loc>()) {
1001  Loc X = svalBuilder.makeNullWithType(Ex->getType());
1002  Result = evalBinOp(state, BO_EQ, *LV, X, U->getType());
1003  } else if (Ex->getType()->isFloatingType()) {
1004  // FIXME: handle floating point types.
1005  Result = UnknownVal();
1006  } else {
1007  nonloc::ConcreteInt X(getBasicVals().getValue(0, Ex->getType()));
1008  Result = evalBinOp(state, BO_EQ, V.castAs<NonLoc>(), X,
1009  U->getType());
1010  }
1011 
1012  state = state->BindExpr(U, LCtx, Result);
1013  break;
1014  }
1015  Bldr.generateNode(U, *I, state);
1016  break;
1017  }
1018  }
1019  }
1020 
1021  getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, U, *this);
1022 }
1023 
1025  ExplodedNode *Pred,
1026  ExplodedNodeSet &Dst) {
1027  // Handle ++ and -- (both pre- and post-increment).
1028  assert (U->isIncrementDecrementOp());
1029  const Expr *Ex = U->getSubExpr()->IgnoreParens();
1030 
1031  const LocationContext *LCtx = Pred->getLocationContext();
1032  ProgramStateRef state = Pred->getState();
1033  SVal loc = state->getSVal(Ex, LCtx);
1034 
1035  // Perform a load.
1036  ExplodedNodeSet Tmp;
1037  evalLoad(Tmp, U, Ex, Pred, state, loc);
1038 
1039  ExplodedNodeSet Dst2;
1040  StmtNodeBuilder Bldr(Tmp, Dst2, *currBldrCtx);
1041  for (ExplodedNodeSet::iterator I=Tmp.begin(), E=Tmp.end();I!=E;++I) {
1042 
1043  state = (*I)->getState();
1044  assert(LCtx == (*I)->getLocationContext());
1045  SVal V2_untested = state->getSVal(Ex, LCtx);
1046 
1047  // Propagate unknown and undefined values.
1048  if (V2_untested.isUnknownOrUndef()) {
1049  state = state->BindExpr(U, LCtx, V2_untested);
1050 
1051  // Perform the store, so that the uninitialized value detection happens.
1052  Bldr.takeNodes(*I);
1053  ExplodedNodeSet Dst3;
1054  evalStore(Dst3, U, U, *I, state, loc, V2_untested);
1055  Bldr.addNodes(Dst3);
1056 
1057  continue;
1058  }
1059  DefinedSVal V2 = V2_untested.castAs<DefinedSVal>();
1060 
1061  // Handle all other values.
1062  BinaryOperator::Opcode Op = U->isIncrementOp() ? BO_Add : BO_Sub;
1063 
1064  // If the UnaryOperator has non-location type, use its type to create the
1065  // constant value. If the UnaryOperator has location type, create the
1066  // constant with int type and pointer width.
1067  SVal RHS;
1068  SVal Result;
1069 
1070  if (U->getType()->isAnyPointerType())
1071  RHS = svalBuilder.makeArrayIndex(1);
1072  else if (U->getType()->isIntegralOrEnumerationType())
1073  RHS = svalBuilder.makeIntVal(1, U->getType());
1074  else
1075  RHS = UnknownVal();
1076 
1077  // The use of an operand of type bool with the ++ operators is deprecated
1078  // but valid until C++17. And if the operand of the ++ operator is of type
1079  // bool, it is set to true until C++17. Note that for '_Bool', it is also
1080  // set to true when it encounters ++ operator.
1081  if (U->getType()->isBooleanType() && U->isIncrementOp())
1082  Result = svalBuilder.makeTruthVal(true, U->getType());
1083  else
1084  Result = evalBinOp(state, Op, V2, RHS, U->getType());
1085 
1086  // Conjure a new symbol if necessary to recover precision.
1087  if (Result.isUnknown()){
1088  DefinedOrUnknownSVal SymVal =
1089  svalBuilder.conjureSymbolVal(nullptr, U, LCtx,
1090  currBldrCtx->blockCount());
1091  Result = SymVal;
1092 
1093  // If the value is a location, ++/-- should always preserve
1094  // non-nullness. Check if the original value was non-null, and if so
1095  // propagate that constraint.
1096  if (Loc::isLocType(U->getType())) {
1097  DefinedOrUnknownSVal Constraint =
1098  svalBuilder.evalEQ(state, V2,svalBuilder.makeZeroVal(U->getType()));
1099 
1100  if (!state->assume(Constraint, true)) {
1101  // It isn't feasible for the original value to be null.
1102  // Propagate this constraint.
1103  Constraint = svalBuilder.evalEQ(state, SymVal,
1104  svalBuilder.makeZeroVal(U->getType()));
1105 
1106  state = state->assume(Constraint, false);
1107  assert(state);
1108  }
1109  }
1110  }
1111 
1112  // Since the lvalue-to-rvalue conversion is explicit in the AST,
1113  // we bind an l-value if the operator is prefix and an lvalue (in C++).
1114  if (U->isGLValue())
1115  state = state->BindExpr(U, LCtx, loc);
1116  else
1117  state = state->BindExpr(U, LCtx, U->isPostfix() ? V2 : Result);
1118 
1119  // Perform the store.
1120  Bldr.takeNodes(*I);
1121  ExplodedNodeSet Dst3;
1122  evalStore(Dst3, U, U, *I, state, loc, Result);
1123  Bldr.addNodes(Dst3);
1124  }
1125  Dst.insert(Dst2);
1126 }
SVal attemptDownCast(SVal Base, QualType DerivedPtrType, bool &Failed)
Attempts to do a down cast.
Definition: Store.cpp:315
const BlockDecl * getBlockDecl() const
Definition: Expr.h:5110
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
Definition: SValBuilder.h:279
DefinedSVal getBlockPointer(const BlockDecl *block, CanQualType locTy, const LocationContext *locContext, unsigned blockCount)
reverse_iterator rbegin()
Definition: Expr.h:4322
SVal evalDerivedToBase(SVal Derived, const CastExpr *Cast)
Evaluates a chain of derived-to-base casts through the path specified in Cast.
Definition: Store.cpp:249
bool empty() const
Definition: CFG.h:714
A (possibly-)qualified type.
Definition: Type.h:642
bool isArrayType() const
Definition: Type.h:6331
succ_iterator succ_begin()
Definition: CFG.h:751
capture_const_iterator capture_begin() const
Definition: Decl.h:3983
const Expr * getInit(unsigned Init) const
Definition: Expr.h:4165
unsigned blockCount() const
Returns the number of times the current basic block has been visited on the exploded graph path...
Definition: CoreEngine.h:212
This builder class is useful for generating nodes that resulted from visiting a statement.
Definition: CoreEngine.h:370
bool isRecordType() const
Definition: Type.h:6355
const CFGBlock * getSrc() const
Definition: ProgramPoint.h:513
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
Opcode getOpcode() const
Definition: Expr.h:3254
StringRef P
SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, NonLoc L, NonLoc R, QualType T)
Definition: ExprEngine.h:575
Represents a point after we ran remove dead bindings BEFORE processing the given statement.
Definition: ProgramPoint.h:475
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type...
Definition: CFG.h:99
const ProgramStateRef & getState() const
SVal evalCast(SVal val, QualType castTy, QualType originalType)
Value representing integer constant.
Definition: SVals.h:377
capture_const_iterator capture_end() const
Definition: Decl.h:3984
unsigned succ_size() const
Definition: CFG.h:769
void VisitUnaryOperator(const UnaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitUnaryOperator - Transfer function logic for unary operators.
void takeNodes(const ExplodedNodeSet &S)
Definition: CoreEngine.h:321
bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
void handleUOExtension(ExplodedNodeSet::iterator I, const UnaryOperator *U, StmtNodeBuilder &Bldr)
Represents a variable declaration or definition.
Definition: Decl.h:812
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:2830
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6716
NonLoc makeArrayIndex(uint64_t idx)
Definition: SValBuilder.h:273
static Optional< SVal > getObjectUnderConstruction(ProgramStateRef State, const ConstructionContextItem &Item, const LocationContext *LC)
By looking at a certain item that may be potentially part of an object&#39;s ConstructionContext, retrieve such object&#39;s location.
Definition: ExprEngine.cpp:453
void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE, ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val, const ProgramPointTag *tag=nullptr)
evalStore - Handle the semantics of a store via an assignment.
static bool isAssignmentOp(Opcode Opc)
Definition: Expr.h:3342
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isVariableArrayType() const
Definition: Type.h:6343
InitExprsTy::const_reverse_iterator const_reverse_iterator
Definition: Expr.h:4316
Represents a class type in Objective C.
Definition: Type.h:5524
Value representing pointer-to-member.
Definition: SVals.h:522
LineState State
SVal evalIntegralCast(ProgramStateRef state, SVal val, QualType castTy, QualType originalType)
Loc makeNullWithType(QualType type)
Create NULL pointer, with proper pointer bit-width for given address space.
Definition: SValBuilder.h:346
static bool isIncrementDecrementOp(Opcode Op)
Definition: Expr.h:1974
bool isReferenceType() const
Definition: Type.h:6294
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:6630
llvm::ImmutableList< SVal > prependSVal(SVal X, llvm::ImmutableList< SVal > L)
static bool isLocType(QualType T)
Definition: SVals.h:327
bool isGLValue() const
Definition: Expr.h:252
Describes an C or C++ initializer list.
Definition: Expr.h:4117
void VisitOffsetOfExpr(const OffsetOfExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitOffsetOfExpr - Transfer function for offsetof.
BinaryOperatorKind
BlockDataRegion - A region that represents a block instance.
Definition: MemRegion.h:668
ExplodedNode * generateSink(const Stmt *S, ExplodedNode *Pred, ProgramStateRef St, const ProgramPointTag *tag=nullptr, ProgramPoint::Kind K=ProgramPoint::PostStmtKind)
Definition: CoreEngine.h:409
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
path_iterator path_begin()
Definition: Expr.h:2992
const LocationContext * getLocationContext() const
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3219
bool isUnknown() const
Definition: SVals.h:137
NonLoc makePointerToMember(const DeclaratorDecl *DD)
Definition: SValBuilder.h:261
static bool isPostfix(Opcode Op)
isPostfix - Return true if this is a postfix operation, like x++.
Definition: Expr.h:1948
bool isRValueReferenceType() const
Definition: Type.h:6302
NonLoc makeCompoundVal(QualType type, llvm::ImmutableList< SVal > vals)
Definition: SValBuilder.h:251
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:2903
SVal evalComplement(SVal X)
Definition: ExprEngine.h:554
void VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitDeclStmt - Transfer function logic for DeclStmts.
unsigned pred_size() const
bool isConstant() const
Definition: SVals.cpp:218
void evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE, ExplodedNode *Pred, SVal location, SVal Val, bool atDeclInit=false, const ProgramPoint *PP=nullptr)
evalBind - Handle the semantics of binding a value to a specific location.
CheckerManager & getCheckerManager() const
Definition: ExprEngine.h:183
void VisitLogicalExpr(const BinaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitLogicalExpr - Transfer function logic for &#39;&&&#39;, &#39;||&#39;.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand...
Definition: Expr.h:2227
Represents a single basic block in a source-level CFG.
Definition: CFG.h:552
void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
void runCheckersForPostStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting Stmts.
DefinedOrUnknownSVal makeZeroVal(QualType type)
Construct an SVal representing &#39;0&#39; for the specified type.
Definition: SValBuilder.cpp:53
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:3854
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
This represents one expression.
Definition: Expr.h:106
static SVal conjureOffsetSymbolOnLocation(SVal Symbol, SVal Other, Expr *Expression, SValBuilder &svalBuilder, unsigned Count, const LocationContext *LCtx)
Optionally conjure and return a symbol for offset when processing an expression Expression.
Definition: ExprEngineC.cpp:29
void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCast - Transfer function logic for all casts (implicit and explicit).
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:5096
unsigned getNumInits() const
Definition: Expr.h:4147
const ExplodedNodeSet & getResults()
Definition: CoreEngine.h:298
bool isAnyComplexType() const
Definition: Type.h:6363
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
static SVal getValue(SVal val, SValBuilder &svalBuilder)
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
Definition: Type.cpp:1836
const CFGBlock * getDst() const
Definition: ProgramPoint.h:517
QualType getType() const
Definition: Expr.h:128
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
Definition: Expr.h:2290
The reason for pointer escape is unknown.
ASTContext & getContext() const
getContext - Return the ASTContext associated with this analysis.
Definition: ExprEngine.h:179
UnaryOperator - This represents the unary-expression&#39;s (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1901
void evalLoad(ExplodedNodeSet &Dst, const Expr *NodeEx, const Expr *BoundExpr, ExplodedNode *Pred, ProgramStateRef St, SVal location, const ProgramPointTag *tag=nullptr, QualType LoadTy=QualType())
Simulate a read of the result of Ex.
reverse_iterator rbegin()
Definition: CFG.h:708
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
Definition: SVals.h:112
const VarDecl * getDecl() const
Definition: MemRegion.h:948
CFGTerminator getTerminator()
Definition: CFG.h:840
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Definition: Expr.h:939
bool isBuiltinType() const
Helper methods to distinguish type categories.
Definition: Type.h:6351
void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitGuardedExpr - Transfer function logic for ?, __builtin_choose.
DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, const Expr *expr, const LocationContext *LCtx, unsigned count)
Create a new symbol with a unique &#39;name&#39;.
Expr * getSubExpr() const
Definition: Expr.h:1931
T castAs() const
Convert to the specified ProgramPoint type, asserting that this ProgramPoint is of the desired type...
Definition: ProgramPoint.h:142
CastKind getCastKind() const
Definition: Expr.h:2962
const MemRegion * getAsRegion() const
Definition: SVals.cpp:151
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:841
void VisitCompoundLiteralExpr(const CompoundLiteralExpr *CL, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCompoundLiteralExpr - Transfer function logic for compound literals.
ProgramStateRef handleLVectorSplat(ProgramStateRef state, const LocationContext *LCtx, const CastExpr *CastE, StmtNodeBuilder &Bldr, ExplodedNode *Pred)
ProgramPoint getLocation() const
getLocation - Returns the edge associated with the given node.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Definition: SVals.h:76
UnaryExprOrTypeTrait getKind() const
Definition: Expr.h:2258
decl_iterator decl_begin()
Definition: Stmt.h:890
void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
bool isAnyPointerType() const
Definition: Type.h:6286
BasicValueFactory & getBasicVals()
Definition: ExprEngine.h:386
void runCheckersForPreStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng)
Run checkers for pre-visiting Stmts.
bool isVectorType() const
Definition: Type.h:6367
void insert(const ExplodedNodeSet &S)
const Expr * getInitializer() const
Definition: Expr.h:2856
Expr * getLHS() const
Definition: Expr.h:3259
Dataflow Directional Tag Classes.
void VisitIncrementDecrementOperator(const UnaryOperator *U, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Handle ++ and – (both pre- and post-increment).
SValBuilder & getSValBuilder()
Definition: ExprEngine.h:187
void addNodes(const ExplodedNodeSet &S)
Definition: CoreEngine.h:327
StoreManager & getStoreManager()
Definition: ExprEngine.h:379
bool isZeroConstant() const
Definition: SVals.cpp:230
const Expr * getInit() const
Definition: Decl.h:1219
bool isBooleanType() const
Definition: Type.h:6643
SVal evalEQ(ProgramStateRef state, SVal lhs, SVal rhs)
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3117
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl. ...
Definition: Stmt.h:854
Stmt * getStmt()
Definition: CFG.h:510
path_iterator path_end()
Definition: Expr.h:2993
ProgramStateRef handleLValueBitCast(ProgramStateRef state, const Expr *Ex, const LocationContext *LCtx, QualType T, QualType ExTy, const CastExpr *CastE, StmtNodeBuilder &Bldr, ExplodedNode *Pred)
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition: SVals.h:104
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6.7.5p3.
Definition: Type.cpp:2013
SVal evalMinus(SVal X)
Definition: ExprEngine.h:550
DefinedSVal getMemberPointer(const DeclaratorDecl *DD)
Opcode getOpcode() const
Definition: Expr.h:1926
static bool isAdditiveOp(Opcode Opc)
Definition: Expr.h:3295
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2069
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
Definition: Type.cpp:2023
static bool isIncrementOp(Opcode Op)
Definition: Expr.h:1960
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2252
bool isLValueReferenceType() const
Definition: Type.h:6298
reverse_iterator rend()
Definition: Expr.h:4324
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:13853
void VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitBlockExpr - Transfer function logic for BlockExprs.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
static bool isCompoundAssignmentOp(Opcode Opc)
Definition: Expr.h:3347
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
pred_iterator pred_begin()
Represents a top-level expression in a basic block.
Definition: CFG.h:56
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
This class is used for builtin types like &#39;int&#39;.
Definition: Type.h:2397
Represents CFGBlock terminator statement.
Definition: CFG.h:502
ExplodedNode * generateNode(const Stmt *S, ExplodedNode *Pred, ProgramStateRef St, const ProgramPointTag *tag=nullptr, ProgramPoint::Kind K=ProgramPoint::PostStmtKind)
Definition: CoreEngine.h:399
bool isUndef() const
Definition: SVals.h:141
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1036
Expr * getRHS() const
Definition: Expr.h:3261
nonloc::ConcreteInt makeTruthVal(bool b, QualType type)
Definition: SValBuilder.h:335
ProgramStateRef escapeValue(ProgramStateRef State, SVal V, PointerEscapeKind K) const
A simple wrapper when you only need to notify checkers of pointer-escape of a single value...
Optional< T > getAs() const
Convert to the specified ProgramPoint type, returning None if this ProgramPoint is not of the desired...
Definition: ProgramPoint.h:153
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type, member-designator).
Definition: Expr.h:2122
void VisitBinaryOperator(const BinaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitBinaryOperator - Transfer function logic for binary operators.
Definition: ExprEngineC.cpp:41
bool isUnknownOrUndef() const
Definition: SVals.h:145
llvm::ImmutableList< SVal > getEmptySValList()
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Definition: Expr.cpp:2548