clang  7.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 /// \brief 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  // Delegate to SValBuilder to process.
261  SVal V = state->getSVal(Ex, LCtx);
262  V = svalBuilder.evalCast(V, T, ExTy);
263  // Negate the result if we're treating the boolean as a signed i1
264  if (CastE->getCastKind() == CK_BooleanToSignedIntegral)
265  V = evalMinus(V);
266  state = state->BindExpr(CastE, LCtx, V);
267  Bldr.generateNode(CastE, Pred, state);
268 
269  return state;
270 }
271 
273  ProgramStateRef state, const LocationContext* LCtx, const CastExpr* CastE,
274  StmtNodeBuilder &Bldr, ExplodedNode* Pred) {
275  // Recover some path sensitivity by conjuring a new value.
276  QualType resultType = CastE->getType();
277  if (CastE->isGLValue())
278  resultType = getContext().getPointerType(resultType);
279  SVal result = svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx,
280  resultType,
281  currBldrCtx->blockCount());
282  state = state->BindExpr(CastE, LCtx, result);
283  Bldr.generateNode(CastE, Pred, state);
284 
285  return state;
286 }
287 
288 void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
289  ExplodedNode *Pred, ExplodedNodeSet &Dst) {
290 
291  ExplodedNodeSet dstPreStmt;
292  getCheckerManager().runCheckersForPreStmt(dstPreStmt, Pred, CastE, *this);
293 
294  if (CastE->getCastKind() == CK_LValueToRValue) {
295  for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = dstPreStmt.end();
296  I!=E; ++I) {
297  ExplodedNode *subExprNode = *I;
298  ProgramStateRef state = subExprNode->getState();
299  const LocationContext *LCtx = subExprNode->getLocationContext();
300  evalLoad(Dst, CastE, CastE, subExprNode, state, state->getSVal(Ex, LCtx));
301  }
302  return;
303  }
304 
305  // All other casts.
306  QualType T = CastE->getType();
307  QualType ExTy = Ex->getType();
308 
309  if (const ExplicitCastExpr *ExCast=dyn_cast_or_null<ExplicitCastExpr>(CastE))
310  T = ExCast->getTypeAsWritten();
311 
312  StmtNodeBuilder Bldr(dstPreStmt, Dst, *currBldrCtx);
313  for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = dstPreStmt.end();
314  I != E; ++I) {
315 
316  Pred = *I;
317  ProgramStateRef state = Pred->getState();
318  const LocationContext *LCtx = Pred->getLocationContext();
319 
320  switch (CastE->getCastKind()) {
321  case CK_LValueToRValue:
322  llvm_unreachable("LValueToRValue casts handled earlier.");
323  case CK_ToVoid:
324  continue;
325  // The analyzer doesn't do anything special with these casts,
326  // since it understands retain/release semantics already.
327  case CK_ARCProduceObject:
328  case CK_ARCConsumeObject:
329  case CK_ARCReclaimReturnedObject:
330  case CK_ARCExtendBlockObject: // Fall-through.
331  case CK_CopyAndAutoreleaseBlockObject:
332  // The analyser can ignore atomic casts for now, although some future
333  // checkers may want to make certain that you're not modifying the same
334  // value through atomic and nonatomic pointers.
335  case CK_AtomicToNonAtomic:
336  case CK_NonAtomicToAtomic:
337  // True no-ops.
338  case CK_NoOp:
339  case CK_ConstructorConversion:
340  case CK_UserDefinedConversion:
341  case CK_FunctionToPointerDecay:
342  case CK_BuiltinFnToFnPtr: {
343  // Copy the SVal of Ex to CastE.
344  ProgramStateRef state = Pred->getState();
345  const LocationContext *LCtx = Pred->getLocationContext();
346  SVal V = state->getSVal(Ex, LCtx);
347  state = state->BindExpr(CastE, LCtx, V);
348  Bldr.generateNode(CastE, Pred, state);
349  continue;
350  }
351  case CK_MemberPointerToBoolean:
352  case CK_PointerToBoolean: {
353  SVal V = state->getSVal(Ex, LCtx);
354  auto PTMSV = V.getAs<nonloc::PointerToMember>();
355  if (PTMSV)
356  V = svalBuilder.makeTruthVal(!PTMSV->isNullMemberPointer(), ExTy);
357  if (V.isUndef() || PTMSV) {
358  state = state->BindExpr(CastE, LCtx, V);
359  Bldr.generateNode(CastE, Pred, state);
360  continue;
361  }
362  // Explicitly proceed with default handler for this case cascade.
363  state =
364  handleLValueBitCast(state, Ex, LCtx, T, ExTy, CastE, Bldr, Pred);
365  continue;
366  }
367  case CK_Dependent:
368  case CK_ArrayToPointerDecay:
369  case CK_BitCast:
370  case CK_AddressSpaceConversion:
371  case CK_BooleanToSignedIntegral:
372  case CK_NullToPointer:
373  case CK_IntegralToPointer:
374  case CK_PointerToIntegral: {
375  SVal V = state->getSVal(Ex, LCtx);
376  if (V.getAs<nonloc::PointerToMember>()) {
377  state = state->BindExpr(CastE, LCtx, UnknownVal());
378  Bldr.generateNode(CastE, Pred, state);
379  continue;
380  }
381  // Explicitly proceed with default handler for this case cascade.
382  state =
383  handleLValueBitCast(state, Ex, LCtx, T, ExTy, CastE, Bldr, Pred);
384  continue;
385  }
386  case CK_IntegralToBoolean:
387  case CK_IntegralToFloating:
388  case CK_FloatingToIntegral:
389  case CK_FloatingToBoolean:
390  case CK_FloatingCast:
391  case CK_FloatingRealToComplex:
392  case CK_FloatingComplexToReal:
393  case CK_FloatingComplexToBoolean:
394  case CK_FloatingComplexCast:
395  case CK_FloatingComplexToIntegralComplex:
396  case CK_IntegralRealToComplex:
397  case CK_IntegralComplexToReal:
398  case CK_IntegralComplexToBoolean:
399  case CK_IntegralComplexCast:
400  case CK_IntegralComplexToFloatingComplex:
401  case CK_CPointerToObjCPointerCast:
402  case CK_BlockPointerToObjCPointerCast:
403  case CK_AnyPointerToBlockPointerCast:
404  case CK_ObjCObjectLValueCast:
405  case CK_ZeroToOCLEvent:
406  case CK_ZeroToOCLQueue:
407  case CK_IntToOCLSampler:
408  case CK_LValueBitCast: {
409  state =
410  handleLValueBitCast(state, Ex, LCtx, T, ExTy, CastE, Bldr, Pred);
411  continue;
412  }
413  case CK_IntegralCast: {
414  // Delegate to SValBuilder to process.
415  SVal V = state->getSVal(Ex, LCtx);
416  V = svalBuilder.evalIntegralCast(state, V, T, ExTy);
417  state = state->BindExpr(CastE, LCtx, V);
418  Bldr.generateNode(CastE, Pred, state);
419  continue;
420  }
421  case CK_DerivedToBase:
422  case CK_UncheckedDerivedToBase: {
423  // For DerivedToBase cast, delegate to the store manager.
424  SVal val = state->getSVal(Ex, LCtx);
425  val = getStoreManager().evalDerivedToBase(val, CastE);
426  state = state->BindExpr(CastE, LCtx, val);
427  Bldr.generateNode(CastE, Pred, state);
428  continue;
429  }
430  // Handle C++ dyn_cast.
431  case CK_Dynamic: {
432  SVal val = state->getSVal(Ex, LCtx);
433 
434  // Compute the type of the result.
435  QualType resultType = CastE->getType();
436  if (CastE->isGLValue())
437  resultType = getContext().getPointerType(resultType);
438 
439  bool Failed = false;
440 
441  // Check if the value being cast evaluates to 0.
442  if (val.isZeroConstant())
443  Failed = true;
444  // Else, evaluate the cast.
445  else
446  val = getStoreManager().attemptDownCast(val, T, Failed);
447 
448  if (Failed) {
449  if (T->isReferenceType()) {
450  // A bad_cast exception is thrown if input value is a reference.
451  // Currently, we model this, by generating a sink.
452  Bldr.generateSink(CastE, Pred, state);
453  continue;
454  } else {
455  // If the cast fails on a pointer, bind to 0.
456  state = state->BindExpr(CastE, LCtx, svalBuilder.makeNull());
457  }
458  } else {
459  // If we don't know if the cast succeeded, conjure a new symbol.
460  if (val.isUnknown()) {
461  DefinedOrUnknownSVal NewSym =
462  svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx, resultType,
463  currBldrCtx->blockCount());
464  state = state->BindExpr(CastE, LCtx, NewSym);
465  } else
466  // Else, bind to the derived region value.
467  state = state->BindExpr(CastE, LCtx, val);
468  }
469  Bldr.generateNode(CastE, Pred, state);
470  continue;
471  }
472  case CK_BaseToDerived: {
473  SVal val = state->getSVal(Ex, LCtx);
474  QualType resultType = CastE->getType();
475  if (CastE->isGLValue())
476  resultType = getContext().getPointerType(resultType);
477 
478  bool Failed = false;
479 
480  if (!val.isConstant()) {
481  val = getStoreManager().attemptDownCast(val, T, Failed);
482  }
483 
484  // Failed to cast or the result is unknown, fall back to conservative.
485  if (Failed || val.isUnknown()) {
486  val =
487  svalBuilder.conjureSymbolVal(nullptr, CastE, LCtx, resultType,
488  currBldrCtx->blockCount());
489  }
490  state = state->BindExpr(CastE, LCtx, val);
491  Bldr.generateNode(CastE, Pred, state);
492  continue;
493  }
494  case CK_NullToMemberPointer: {
495  SVal V = svalBuilder.getMemberPointer(nullptr);
496  state = state->BindExpr(CastE, LCtx, V);
497  Bldr.generateNode(CastE, Pred, state);
498  continue;
499  }
500  case CK_DerivedToBaseMemberPointer:
501  case CK_BaseToDerivedMemberPointer:
502  case CK_ReinterpretMemberPointer: {
503  SVal V = state->getSVal(Ex, LCtx);
504  if (auto PTMSV = V.getAs<nonloc::PointerToMember>()) {
505  SVal CastedPTMSV = svalBuilder.makePointerToMember(
506  getBasicVals().accumCXXBase(
507  llvm::make_range<CastExpr::path_const_iterator>(
508  CastE->path_begin(), CastE->path_end()), *PTMSV));
509  state = state->BindExpr(CastE, LCtx, CastedPTMSV);
510  Bldr.generateNode(CastE, Pred, state);
511  continue;
512  }
513  // Explicitly proceed with default handler for this case cascade.
514  state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
515  continue;
516  }
517  // Various C++ casts that are not handled yet.
518  case CK_ToUnion:
519  case CK_VectorSplat: {
520  state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
521  continue;
522  }
523  }
524  }
525 }
526 
528  ExplodedNode *Pred,
529  ExplodedNodeSet &Dst) {
530  StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
531 
532  ProgramStateRef State = Pred->getState();
533  const LocationContext *LCtx = Pred->getLocationContext();
534 
535  const Expr *Init = CL->getInitializer();
536  SVal V = State->getSVal(CL->getInitializer(), LCtx);
537 
538  if (isa<CXXConstructExpr>(Init) || isa<CXXStdInitializerListExpr>(Init)) {
539  // No work needed. Just pass the value up to this expression.
540  } else {
541  assert(isa<InitListExpr>(Init));
542  Loc CLLoc = State->getLValue(CL, LCtx);
543  State = State->bindLoc(CLLoc, V, LCtx);
544 
545  if (CL->isGLValue())
546  V = CLLoc;
547  }
548 
549  B.generateNode(CL, Pred, State->BindExpr(CL, LCtx, V));
550 }
551 
553  ExplodedNodeSet &Dst) {
554  // Assumption: The CFG has one DeclStmt per Decl.
555  const VarDecl *VD = dyn_cast_or_null<VarDecl>(*DS->decl_begin());
556 
557  if (!VD) {
558  //TODO:AZ: remove explicit insertion after refactoring is done.
559  Dst.insert(Pred);
560  return;
561  }
562 
563  // FIXME: all pre/post visits should eventually be handled by ::Visit().
564  ExplodedNodeSet dstPreVisit;
565  getCheckerManager().runCheckersForPreStmt(dstPreVisit, Pred, DS, *this);
566 
567  ExplodedNodeSet dstEvaluated;
568  StmtNodeBuilder B(dstPreVisit, dstEvaluated, *currBldrCtx);
569  for (ExplodedNodeSet::iterator I = dstPreVisit.begin(), E = dstPreVisit.end();
570  I!=E; ++I) {
571  ExplodedNode *N = *I;
573  const LocationContext *LC = N->getLocationContext();
574 
575  // Decls without InitExpr are not initialized explicitly.
576  if (const Expr *InitEx = VD->getInit()) {
577 
578  // Note in the state that the initialization has occurred.
579  ExplodedNode *UpdatedN = N;
580  SVal InitVal = state->getSVal(InitEx, LC);
581 
582  assert(DS->isSingleDecl());
583  if (auto *CtorExpr = findDirectConstructorForCurrentCFGElement()) {
584  assert(InitEx->IgnoreImplicit() == CtorExpr);
585  (void)CtorExpr;
586  // We constructed the object directly in the variable.
587  // No need to bind anything.
588  B.generateNode(DS, UpdatedN, state);
589  } else {
590  // We bound the temp obj region to the CXXConstructExpr. Now recover
591  // the lazy compound value when the variable is not a reference.
592  if (AMgr.getLangOpts().CPlusPlus && VD->getType()->isRecordType() &&
593  !VD->getType()->isReferenceType()) {
595  InitVal.getAs<loc::MemRegionVal>()) {
596  InitVal = state->getSVal(M->getRegion());
597  assert(InitVal.getAs<nonloc::LazyCompoundVal>());
598  }
599  }
600 
601  // Recover some path-sensitivity if a scalar value evaluated to
602  // UnknownVal.
603  if (InitVal.isUnknown()) {
604  QualType Ty = InitEx->getType();
605  if (InitEx->isGLValue()) {
606  Ty = getContext().getPointerType(Ty);
607  }
608 
609  InitVal = svalBuilder.conjureSymbolVal(nullptr, InitEx, LC, Ty,
610  currBldrCtx->blockCount());
611  }
612 
613 
614  B.takeNodes(UpdatedN);
615  ExplodedNodeSet Dst2;
616  evalBind(Dst2, DS, UpdatedN, state->getLValue(VD, LC), InitVal, true);
617  B.addNodes(Dst2);
618  }
619  }
620  else {
621  B.generateNode(DS, N, state);
622  }
623  }
624 
625  getCheckerManager().runCheckersForPostStmt(Dst, B.getResults(), DS, *this);
626 }
627 
629  ExplodedNodeSet &Dst) {
630  assert(B->getOpcode() == BO_LAnd ||
631  B->getOpcode() == BO_LOr);
632 
633  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
634  ProgramStateRef state = Pred->getState();
635 
636  if (B->getType()->isVectorType()) {
637  // FIXME: We do not model vector arithmetic yet. When adding support for
638  // that, note that the CFG-based reasoning below does not apply, because
639  // logical operators on vectors are not short-circuit. Currently they are
640  // modeled as short-circuit in Clang CFG but this is incorrect.
641  // Do not set the value for the expression. It'd be UnknownVal by default.
642  Bldr.generateNode(B, Pred, state);
643  return;
644  }
645 
646  ExplodedNode *N = Pred;
647  while (!N->getLocation().getAs<BlockEntrance>()) {
648  ProgramPoint P = N->getLocation();
649  assert(P.getAs<PreStmt>()|| P.getAs<PreStmtPurgeDeadSymbols>());
650  (void) P;
651  assert(N->pred_size() == 1);
652  N = *N->pred_begin();
653  }
654  assert(N->pred_size() == 1);
655  N = *N->pred_begin();
656  BlockEdge BE = N->getLocation().castAs<BlockEdge>();
657  SVal X;
658 
659  // Determine the value of the expression by introspecting how we
660  // got this location in the CFG. This requires looking at the previous
661  // block we were in and what kind of control-flow transfer was involved.
662  const CFGBlock *SrcBlock = BE.getSrc();
663  // The only terminator (if there is one) that makes sense is a logical op.
664  CFGTerminator T = SrcBlock->getTerminator();
665  if (const BinaryOperator *Term = cast_or_null<BinaryOperator>(T.getStmt())) {
666  (void) Term;
667  assert(Term->isLogicalOp());
668  assert(SrcBlock->succ_size() == 2);
669  // Did we take the true or false branch?
670  unsigned constant = (*SrcBlock->succ_begin() == BE.getDst()) ? 1 : 0;
671  X = svalBuilder.makeIntVal(constant, B->getType());
672  }
673  else {
674  // If there is no terminator, by construction the last statement
675  // in SrcBlock is the value of the enclosing expression.
676  // However, we still need to constrain that value to be 0 or 1.
677  assert(!SrcBlock->empty());
678  CFGStmt Elem = SrcBlock->rbegin()->castAs<CFGStmt>();
679  const Expr *RHS = cast<Expr>(Elem.getStmt());
680  SVal RHSVal = N->getState()->getSVal(RHS, Pred->getLocationContext());
681 
682  if (RHSVal.isUndef()) {
683  X = RHSVal;
684  } else {
685  // We evaluate "RHSVal != 0" expression which result in 0 if the value is
686  // known to be false, 1 if the value is known to be true and a new symbol
687  // when the assumption is unknown.
689  X = evalBinOp(N->getState(), BO_NE,
690  svalBuilder.evalCast(RHSVal, B->getType(), RHS->getType()),
691  Zero, B->getType());
692  }
693  }
694  Bldr.generateNode(B, Pred, state->BindExpr(B, Pred->getLocationContext(), X));
695 }
696 
698  ExplodedNode *Pred,
699  ExplodedNodeSet &Dst) {
700  StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
701 
702  ProgramStateRef state = Pred->getState();
703  const LocationContext *LCtx = Pred->getLocationContext();
705  unsigned NumInitElements = IE->getNumInits();
706 
707  if (!IE->isGLValue() &&
708  (T->isArrayType() || T->isRecordType() || T->isVectorType() ||
709  T->isAnyComplexType())) {
711 
712  // Handle base case where the initializer has no elements.
713  // e.g: static int* myArray[] = {};
714  if (NumInitElements == 0) {
715  SVal V = svalBuilder.makeCompoundVal(T, vals);
716  B.generateNode(IE, Pred, state->BindExpr(IE, LCtx, V));
717  return;
718  }
719 
721  ei = IE->rend(); it != ei; ++it) {
722  SVal V = state->getSVal(cast<Expr>(*it), LCtx);
723  vals = getBasicVals().prependSVal(V, vals);
724  }
725 
726  B.generateNode(IE, Pred,
727  state->BindExpr(IE, LCtx,
728  svalBuilder.makeCompoundVal(T, vals)));
729  return;
730  }
731 
732  // Handle scalars: int{5} and int{} and GLvalues.
733  // Note, if the InitListExpr is a GLvalue, it means that there is an address
734  // representing it, so it must have a single init element.
735  assert(NumInitElements <= 1);
736 
737  SVal V;
738  if (NumInitElements == 0)
739  V = getSValBuilder().makeZeroVal(T);
740  else
741  V = state->getSVal(IE->getInit(0), LCtx);
742 
743  B.generateNode(IE, Pred, state->BindExpr(IE, LCtx, V));
744 }
745 
747  const Expr *L,
748  const Expr *R,
749  ExplodedNode *Pred,
750  ExplodedNodeSet &Dst) {
751  assert(L && R);
752 
753  StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
754  ProgramStateRef state = Pred->getState();
755  const LocationContext *LCtx = Pred->getLocationContext();
756  const CFGBlock *SrcBlock = nullptr;
757 
758  // Find the predecessor block.
759  ProgramStateRef SrcState = state;
760  for (const ExplodedNode *N = Pred ; N ; N = *N->pred_begin()) {
761  ProgramPoint PP = N->getLocation();
762  if (PP.getAs<PreStmtPurgeDeadSymbols>() || PP.getAs<BlockEntrance>()) {
763  // If the state N has multiple predecessors P, it means that successors
764  // of P are all equivalent.
765  // In turn, that means that all nodes at P are equivalent in terms
766  // of observable behavior at N, and we can follow any of them.
767  // FIXME: a more robust solution which does not walk up the tree.
768  continue;
769  }
770  SrcBlock = PP.castAs<BlockEdge>().getSrc();
771  SrcState = N->getState();
772  break;
773  }
774 
775  assert(SrcBlock && "missing function entry");
776 
777  // Find the last expression in the predecessor block. That is the
778  // expression that is used for the value of the ternary expression.
779  bool hasValue = false;
780  SVal V;
781 
782  for (CFGElement CE : llvm::reverse(*SrcBlock)) {
783  if (Optional<CFGStmt> CS = CE.getAs<CFGStmt>()) {
784  const Expr *ValEx = cast<Expr>(CS->getStmt());
785  ValEx = ValEx->IgnoreParens();
786 
787  // For GNU extension '?:' operator, the left hand side will be an
788  // OpaqueValueExpr, so get the underlying expression.
789  if (const OpaqueValueExpr *OpaqueEx = dyn_cast<OpaqueValueExpr>(L))
790  L = OpaqueEx->getSourceExpr();
791 
792  // If the last expression in the predecessor block matches true or false
793  // subexpression, get its the value.
794  if (ValEx == L->IgnoreParens() || ValEx == R->IgnoreParens()) {
795  hasValue = true;
796  V = SrcState->getSVal(ValEx, LCtx);
797  }
798  break;
799  }
800  }
801 
802  if (!hasValue)
803  V = svalBuilder.conjureSymbolVal(nullptr, Ex, LCtx,
804  currBldrCtx->blockCount());
805 
806  // Generate a new node with the binding from the appropriate path.
807  B.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V, true));
808 }
809 
810 void ExprEngine::
812  ExplodedNode *Pred, ExplodedNodeSet &Dst) {
813  StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
814  APSInt IV;
815  if (OOE->EvaluateAsInt(IV, getContext())) {
816  assert(IV.getBitWidth() == getContext().getTypeSize(OOE->getType()));
817  assert(OOE->getType()->isBuiltinType());
818  assert(OOE->getType()->getAs<BuiltinType>()->isInteger());
819  assert(IV.isSigned() == OOE->getType()->isSignedIntegerType());
820  SVal X = svalBuilder.makeIntVal(IV);
821  B.generateNode(OOE, Pred,
822  Pred->getState()->BindExpr(OOE, Pred->getLocationContext(),
823  X));
824  }
825  // FIXME: Handle the case where __builtin_offsetof is not a constant.
826 }
827 
828 
829 void ExprEngine::
831  ExplodedNode *Pred,
832  ExplodedNodeSet &Dst) {
833  // FIXME: Prechecks eventually go in ::Visit().
834  ExplodedNodeSet CheckedSet;
835  getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, Ex, *this);
836 
837  ExplodedNodeSet EvalSet;
838  StmtNodeBuilder Bldr(CheckedSet, EvalSet, *currBldrCtx);
839 
840  QualType T = Ex->getTypeOfArgument();
841 
842  for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
843  I != E; ++I) {
844  if (Ex->getKind() == UETT_SizeOf) {
845  if (!T->isIncompleteType() && !T->isConstantSizeType()) {
846  assert(T->isVariableArrayType() && "Unknown non-constant-sized type.");
847 
848  // FIXME: Add support for VLA type arguments and VLA expressions.
849  // When that happens, we should probably refactor VLASizeChecker's code.
850  continue;
851  } else if (T->getAs<ObjCObjectType>()) {
852  // Some code tries to take the sizeof an ObjCObjectType, relying that
853  // the compiler has laid out its representation. Just report Unknown
854  // for these.
855  continue;
856  }
857  }
858 
859  APSInt Value = Ex->EvaluateKnownConstInt(getContext());
860  CharUnits amt = CharUnits::fromQuantity(Value.getZExtValue());
861 
862  ProgramStateRef state = (*I)->getState();
863  state = state->BindExpr(Ex, (*I)->getLocationContext(),
864  svalBuilder.makeIntVal(amt.getQuantity(),
865  Ex->getType()));
866  Bldr.generateNode(Ex, *I, state);
867  }
868 
869  getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, Ex, *this);
870 }
871 
873  const UnaryOperator *U,
874  StmtNodeBuilder &Bldr) {
875  // FIXME: We can probably just have some magic in Environment::getSVal()
876  // that propagates values, instead of creating a new node here.
877  //
878  // Unary "+" is a no-op, similar to a parentheses. We still have places
879  // where it may be a block-level expression, so we need to
880  // generate an extra node that just propagates the value of the
881  // subexpression.
882  const Expr *Ex = U->getSubExpr()->IgnoreParens();
883  ProgramStateRef state = (*I)->getState();
884  const LocationContext *LCtx = (*I)->getLocationContext();
885  Bldr.generateNode(U, *I, state->BindExpr(U, LCtx,
886  state->getSVal(Ex, LCtx)));
887 }
888 
890  ExplodedNodeSet &Dst) {
891  // FIXME: Prechecks eventually go in ::Visit().
892  ExplodedNodeSet CheckedSet;
893  getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, U, *this);
894 
895  ExplodedNodeSet EvalSet;
896  StmtNodeBuilder Bldr(CheckedSet, EvalSet, *currBldrCtx);
897 
898  for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
899  I != E; ++I) {
900  switch (U->getOpcode()) {
901  default: {
902  Bldr.takeNodes(*I);
903  ExplodedNodeSet Tmp;
905  Bldr.addNodes(Tmp);
906  break;
907  }
908  case UO_Real: {
909  const Expr *Ex = U->getSubExpr()->IgnoreParens();
910 
911  // FIXME: We don't have complex SValues yet.
912  if (Ex->getType()->isAnyComplexType()) {
913  // Just report "Unknown."
914  break;
915  }
916 
917  // For all other types, UO_Real is an identity operation.
918  assert (U->getType() == Ex->getType());
919  ProgramStateRef state = (*I)->getState();
920  const LocationContext *LCtx = (*I)->getLocationContext();
921  Bldr.generateNode(U, *I, state->BindExpr(U, LCtx,
922  state->getSVal(Ex, LCtx)));
923  break;
924  }
925 
926  case UO_Imag: {
927  const Expr *Ex = U->getSubExpr()->IgnoreParens();
928  // FIXME: We don't have complex SValues yet.
929  if (Ex->getType()->isAnyComplexType()) {
930  // Just report "Unknown."
931  break;
932  }
933  // For all other types, UO_Imag returns 0.
934  ProgramStateRef state = (*I)->getState();
935  const LocationContext *LCtx = (*I)->getLocationContext();
936  SVal X = svalBuilder.makeZeroVal(Ex->getType());
937  Bldr.generateNode(U, *I, state->BindExpr(U, LCtx, X));
938  break;
939  }
940 
941  case UO_AddrOf: {
942  // Process pointer-to-member address operation.
943  const Expr *Ex = U->getSubExpr()->IgnoreParens();
944  if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Ex)) {
945  const ValueDecl *VD = DRE->getDecl();
946 
947  if (isa<CXXMethodDecl>(VD) || isa<FieldDecl>(VD)) {
948  ProgramStateRef State = (*I)->getState();
949  const LocationContext *LCtx = (*I)->getLocationContext();
950  SVal SV = svalBuilder.getMemberPointer(cast<DeclaratorDecl>(VD));
951  Bldr.generateNode(U, *I, State->BindExpr(U, LCtx, SV));
952  break;
953  }
954  }
955  // Explicitly proceed with default handler for this case cascade.
956  handleUOExtension(I, U, Bldr);
957  break;
958  }
959  case UO_Plus:
960  assert(!U->isGLValue());
961  // FALL-THROUGH.
962  case UO_Deref:
963  case UO_Extension: {
964  handleUOExtension(I, U, Bldr);
965  break;
966  }
967 
968  case UO_LNot:
969  case UO_Minus:
970  case UO_Not: {
971  assert (!U->isGLValue());
972  const Expr *Ex = U->getSubExpr()->IgnoreParens();
973  ProgramStateRef state = (*I)->getState();
974  const LocationContext *LCtx = (*I)->getLocationContext();
975 
976  // Get the value of the subexpression.
977  SVal V = state->getSVal(Ex, LCtx);
978 
979  if (V.isUnknownOrUndef()) {
980  Bldr.generateNode(U, *I, state->BindExpr(U, LCtx, V));
981  break;
982  }
983 
984  switch (U->getOpcode()) {
985  default:
986  llvm_unreachable("Invalid Opcode.");
987  case UO_Not:
988  // FIXME: Do we need to handle promotions?
989  state = state->BindExpr(U, LCtx, evalComplement(V.castAs<NonLoc>()));
990  break;
991  case UO_Minus:
992  // FIXME: Do we need to handle promotions?
993  state = state->BindExpr(U, LCtx, evalMinus(V.castAs<NonLoc>()));
994  break;
995  case UO_LNot:
996  // C99 6.5.3.3: "The expression !E is equivalent to (0==E)."
997  //
998  // Note: technically we do "E == 0", but this is the same in the
999  // transfer functions as "0 == E".
1000  SVal Result;
1001  if (Optional<Loc> LV = V.getAs<Loc>()) {
1002  Loc X = svalBuilder.makeNullWithType(Ex->getType());
1003  Result = evalBinOp(state, BO_EQ, *LV, X, U->getType());
1004  } else if (Ex->getType()->isFloatingType()) {
1005  // FIXME: handle floating point types.
1006  Result = UnknownVal();
1007  } else {
1008  nonloc::ConcreteInt X(getBasicVals().getValue(0, Ex->getType()));
1009  Result = evalBinOp(state, BO_EQ, V.castAs<NonLoc>(), X,
1010  U->getType());
1011  }
1012 
1013  state = state->BindExpr(U, LCtx, Result);
1014  break;
1015  }
1016  Bldr.generateNode(U, *I, state);
1017  break;
1018  }
1019  }
1020  }
1021 
1022  getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, U, *this);
1023 }
1024 
1026  ExplodedNode *Pred,
1027  ExplodedNodeSet &Dst) {
1028  // Handle ++ and -- (both pre- and post-increment).
1029  assert (U->isIncrementDecrementOp());
1030  const Expr *Ex = U->getSubExpr()->IgnoreParens();
1031 
1032  const LocationContext *LCtx = Pred->getLocationContext();
1033  ProgramStateRef state = Pred->getState();
1034  SVal loc = state->getSVal(Ex, LCtx);
1035 
1036  // Perform a load.
1037  ExplodedNodeSet Tmp;
1038  evalLoad(Tmp, U, Ex, Pred, state, loc);
1039 
1040  ExplodedNodeSet Dst2;
1041  StmtNodeBuilder Bldr(Tmp, Dst2, *currBldrCtx);
1042  for (ExplodedNodeSet::iterator I=Tmp.begin(), E=Tmp.end();I!=E;++I) {
1043 
1044  state = (*I)->getState();
1045  assert(LCtx == (*I)->getLocationContext());
1046  SVal V2_untested = state->getSVal(Ex, LCtx);
1047 
1048  // Propagate unknown and undefined values.
1049  if (V2_untested.isUnknownOrUndef()) {
1050  state = state->BindExpr(U, LCtx, V2_untested);
1051 
1052  // Perform the store, so that the uninitialized value detection happens.
1053  Bldr.takeNodes(*I);
1054  ExplodedNodeSet Dst3;
1055  evalStore(Dst3, U, U, *I, state, loc, V2_untested);
1056  Bldr.addNodes(Dst3);
1057 
1058  continue;
1059  }
1060  DefinedSVal V2 = V2_untested.castAs<DefinedSVal>();
1061 
1062  // Handle all other values.
1063  BinaryOperator::Opcode Op = U->isIncrementOp() ? BO_Add : BO_Sub;
1064 
1065  // If the UnaryOperator has non-location type, use its type to create the
1066  // constant value. If the UnaryOperator has location type, create the
1067  // constant with int type and pointer width.
1068  SVal RHS;
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  SVal Result = evalBinOp(state, Op, V2, RHS, U->getType());
1078 
1079  // Conjure a new symbol if necessary to recover precision.
1080  if (Result.isUnknown()){
1081  DefinedOrUnknownSVal SymVal =
1082  svalBuilder.conjureSymbolVal(nullptr, U, LCtx,
1083  currBldrCtx->blockCount());
1084  Result = SymVal;
1085 
1086  // If the value is a location, ++/-- should always preserve
1087  // non-nullness. Check if the original value was non-null, and if so
1088  // propagate that constraint.
1089  if (Loc::isLocType(U->getType())) {
1090  DefinedOrUnknownSVal Constraint =
1091  svalBuilder.evalEQ(state, V2,svalBuilder.makeZeroVal(U->getType()));
1092 
1093  if (!state->assume(Constraint, true)) {
1094  // It isn't feasible for the original value to be null.
1095  // Propagate this constraint.
1096  Constraint = svalBuilder.evalEQ(state, SymVal,
1097  svalBuilder.makeZeroVal(U->getType()));
1098 
1099 
1100  state = state->assume(Constraint, false);
1101  assert(state);
1102  }
1103  }
1104  }
1105 
1106  // Since the lvalue-to-rvalue conversion is explicit in the AST,
1107  // we bind an l-value if the operator is prefix and an lvalue (in C++).
1108  if (U->isGLValue())
1109  state = state->BindExpr(U, LCtx, loc);
1110  else
1111  state = state->BindExpr(U, LCtx, U->isPostfix() ? V2 : Result);
1112 
1113  // Perform the store.
1114  Bldr.takeNodes(*I);
1115  ExplodedNodeSet Dst3;
1116  evalStore(Dst3, U, U, *I, state, loc, Result);
1117  Bldr.addNodes(Dst3);
1118  }
1119  Dst.insert(Dst2);
1120 }
SVal attemptDownCast(SVal Base, QualType DerivedPtrType, bool &Failed)
Attempts to do a down cast.
Definition: Store.cpp:296
const BlockDecl * getBlockDecl() const
Definition: Expr.h:4878
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
Definition: SValBuilder.h:261
DefinedSVal getBlockPointer(const BlockDecl *block, CanQualType locTy, const LocationContext *locContext, unsigned blockCount)
reverse_iterator rbegin()
Definition: Expr.h:4090
SVal evalDerivedToBase(SVal Derived, const CastExpr *Cast)
Evaluates a chain of derived-to-base casts through the path specified in Cast.
Definition: Store.cpp:237
bool empty() const
Definition: CFG.h:727
A (possibly-)qualified type.
Definition: Type.h:653
bool isArrayType() const
Definition: Type.h:5997
succ_iterator succ_begin()
Definition: CFG.h:764
capture_const_iterator capture_begin() const
Definition: Decl.h:3841
const Expr * getInit(unsigned Init) const
Definition: Expr.h:3933
unsigned blockCount() const
Returns the number of times the current basic block has been visited on the exploded graph path...
Definition: CoreEngine.h:196
This builder class is useful for generating nodes that resulted from visiting a statement.
Definition: CoreEngine.h:350
bool isRecordType() const
Definition: Type.h:6021
const CFGBlock * getSrc() const
Definition: ProgramPoint.h:481
Opcode getOpcode() const
Definition: Expr.h:3039
StringRef P
SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, NonLoc L, NonLoc R, QualType T)
Definition: ExprEngine.h:515
Represents a point after we ran remove dead bindings BEFORE processing the given statement.
Definition: ProgramPoint.h:443
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type...
Definition: CFG.h:94
const ProgramStateRef & getState() const
SVal evalCast(SVal val, QualType castTy, QualType originalType)
Value representing integer constant.
Definition: SVals.h:353
capture_const_iterator capture_end() const
Definition: Decl.h:3842
unsigned succ_size() const
Definition: CFG.h:782
void VisitUnaryOperator(const UnaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitUnaryOperator - Transfer function logic for unary operators.
void takeNodes(const ExplodedNodeSet &S)
Definition: CoreEngine.h:303
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:2650
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6317
NonLoc makeArrayIndex(uint64_t idx)
Definition: SValBuilder.h:255
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:3121
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isVariableArrayType() const
Definition: Type.h:6009
InitExprsTy::const_reverse_iterator const_reverse_iterator
Definition: Expr.h:4084
Represents a class type in Objective C.
Definition: Type.h:5190
Value representing pointer-to-member.
Definition: SVals.h:487
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:328
static bool isIncrementDecrementOp(Opcode Op)
Definition: Expr.h:1787
bool isReferenceType() const
Definition: Type.h:5960
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:6231
llvm::ImmutableList< SVal > prependSVal(SVal X, llvm::ImmutableList< SVal > L)
static bool isLocType(QualType T)
Definition: SVals.h:308
bool isGLValue() const
Definition: Expr.h:252
Describes an C or C++ initializer list.
Definition: Expr.h:3885
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:657
ExplodedNode * generateSink(const Stmt *S, ExplodedNode *Pred, ProgramStateRef St, const ProgramPointTag *tag=nullptr, ProgramPoint::Kind K=ProgramPoint::PostStmtKind)
Definition: CoreEngine.h:390
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
path_iterator path_begin()
Definition: Expr.h:2790
const LocationContext * getLocationContext() const
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:2998
bool isUnknown() const
Definition: SVals.h:125
NonLoc makePointerToMember(const DeclaratorDecl *DD)
Definition: SValBuilder.h:243
static bool isPostfix(Opcode Op)
isPostfix - Return true if this is a postfix operation, like x++.
Definition: Expr.h:1761
NonLoc makeCompoundVal(QualType type, llvm::ImmutableList< SVal > vals)
Definition: SValBuilder.h:233
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:2723
SVal evalComplement(SVal X)
Definition: ExprEngine.h:493
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:207
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:141
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:2040
CFGBlock - Represents a single basic block in a source-level CFG.
Definition: CFG.h:562
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:32
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:3713
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
Expr - 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
const FunctionProtoType * T
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:4864
unsigned getNumInits() const
Definition: Expr.h:3915
const ExplodedNodeSet & getResults()
Definition: CoreEngine.h:282
bool isAnyComplexType() const
Definition: Type.h:6029
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:1800
const CFGBlock * getDst() const
Definition: ProgramPoint.h:485
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:2103
ASTContext & getContext() const
getContext - Return the ASTContext associated with this analysis.
Definition: ExprEngine.h:137
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:1717
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:721
const VarDecl * getDecl() const
Definition: MemRegion.h:936
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
Definition: SVals.h:100
CFGTerminator getTerminator()
Definition: CFG.h:853
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Definition: Expr.h:868
bool isBuiltinType() const
Helper methods to distinguish type categories.
Definition: Type.h:6017
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:1744
T castAs() const
Convert to the specified ProgramPoint type, asserting that this ProgramPoint is of the desired type...
Definition: ProgramPoint.h:141
CastKind getCastKind() const
Definition: Expr.h:2770
const MemRegion * getAsRegion() const
Definition: SVals.cpp:140
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:487
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:63
UnaryExprOrTypeTrait getKind() const
Definition: Expr.h:2071
decl_iterator decl_begin()
Definition: Stmt.h:538
void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
bool isAnyPointerType() const
Definition: Type.h:5952
BasicValueFactory & getBasicVals()
Definition: ExprEngine.h:329
void runCheckersForPreStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng)
Run checkers for pre-visiting Stmts.
bool isVectorType() const
Definition: Type.h:6033
void insert(const ExplodedNodeSet &S)
const Expr * getInitializer() const
Definition: Expr.h:2676
Expr * getLHS() const
Definition: Expr.h:3042
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:145
void addNodes(const ExplodedNodeSet &S)
Definition: CoreEngine.h:308
StoreManager & getStoreManager()
Definition: ExprEngine.h:322
bool isZeroConstant() const
Definition: SVals.cpp:219
const Expr * getInit() const
Definition: Decl.h:1214
SVal evalEQ(ProgramStateRef state, SVal lhs, SVal rhs)
const LangOptions & getLangOpts() const
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:2901
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl. ...
Definition: Stmt.h:500
Stmt * getStmt()
Definition: CFG.h:520
path_iterator path_end()
Definition: Expr.h:2791
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:92
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:1976
SVal evalMinus(SVal X)
Definition: ExprEngine.h:489
DefinedSVal getMemberPointer(const DeclaratorDecl *DD)
Opcode getOpcode() const
Definition: Expr.h:1741
static bool isAdditiveOp(Opcode Opc)
Definition: Expr.h:3074
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2018
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
Definition: Type.cpp:1986
static bool isIncrementOp(Opcode Op)
Definition: Expr.h:1773
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2185
reverse_iterator rend()
Definition: Expr.h:4092
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:13401
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:3126
pred_iterator pred_begin()
CFGElement - Represents a top-level expression in a basic block.
Definition: CFG.h:54
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:2149
CFGTerminator - Represents CFGBlock terminator statement.
Definition: CFG.h:512
ExplodedNode * generateNode(const Stmt *S, ExplodedNode *Pred, ProgramStateRef St, const ProgramPointTag *tag=nullptr, ProgramPoint::Kind K=ProgramPoint::PostStmtKind)
Definition: CoreEngine.h:380
bool isUndef() const
Definition: SVals.h:129
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:956
Expr * getRHS() const
Definition: Expr.h:3044
nonloc::ConcreteInt makeTruthVal(bool b, QualType type)
Definition: SValBuilder.h:317
QualType getType() const
Definition: Decl.h:647
Optional< T > getAs() const
Convert to the specified ProgramPoint type, returning None if this ProgramPoint is not of the desired...
Definition: ProgramPoint.h:152
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type, member-designator).
Definition: Expr.h:1935
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:133
llvm::ImmutableList< SVal > getEmptySValList()
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Definition: Expr.cpp:2434