clang  9.0.0svn
ExprEngineCXX.cpp
Go to the documentation of this file.
1 //===- ExprEngineCXX.cpp - ExprEngine support for C++ -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the C++ expression evaluation engine.
10 //
11 //===----------------------------------------------------------------------===//
12 
15 #include "clang/AST/DeclCXX.h"
16 #include "clang/AST/StmtCXX.h"
17 #include "clang/AST/ParentMap.h"
22 
23 using namespace clang;
24 using namespace ento;
25 
27  ExplodedNode *Pred,
28  ExplodedNodeSet &Dst) {
29  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
30  const Expr *tempExpr = ME->GetTemporaryExpr()->IgnoreParens();
31  ProgramStateRef state = Pred->getState();
32  const LocationContext *LCtx = Pred->getLocationContext();
33 
34  state = createTemporaryRegionIfNeeded(state, LCtx, tempExpr, ME);
35  Bldr.generateNode(ME, Pred, state);
36 }
37 
38 // FIXME: This is the sort of code that should eventually live in a Core
39 // checker rather than as a special case in ExprEngine.
40 void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
41  const CallEvent &Call) {
42  SVal ThisVal;
43  bool AlwaysReturnsLValue;
44  const CXXRecordDecl *ThisRD = nullptr;
45  if (const CXXConstructorCall *Ctor = dyn_cast<CXXConstructorCall>(&Call)) {
46  assert(Ctor->getDecl()->isTrivial());
47  assert(Ctor->getDecl()->isCopyOrMoveConstructor());
48  ThisVal = Ctor->getCXXThisVal();
49  ThisRD = Ctor->getDecl()->getParent();
50  AlwaysReturnsLValue = false;
51  } else {
52  assert(cast<CXXMethodDecl>(Call.getDecl())->isTrivial());
53  assert(cast<CXXMethodDecl>(Call.getDecl())->getOverloadedOperator() ==
54  OO_Equal);
55  ThisVal = cast<CXXInstanceCall>(Call).getCXXThisVal();
56  ThisRD = cast<CXXMethodDecl>(Call.getDecl())->getParent();
57  AlwaysReturnsLValue = true;
58  }
59 
60  assert(ThisRD);
61  if (ThisRD->isEmpty()) {
62  // Do nothing for empty classes. Otherwise it'd retrieve an UnknownVal
63  // and bind it and RegionStore would think that the actual value
64  // in this region at this offset is unknown.
65  return;
66  }
67 
68  const LocationContext *LCtx = Pred->getLocationContext();
69 
70  ExplodedNodeSet Dst;
71  Bldr.takeNodes(Pred);
72 
73  SVal V = Call.getArgSVal(0);
74 
75  // If the value being copied is not unknown, load from its location to get
76  // an aggregate rvalue.
77  if (Optional<Loc> L = V.getAs<Loc>())
78  V = Pred->getState()->getSVal(*L);
79  else
80  assert(V.isUnknownOrUndef());
81 
82  const Expr *CallExpr = Call.getOriginExpr();
83  evalBind(Dst, CallExpr, Pred, ThisVal, V, true);
84 
85  PostStmt PS(CallExpr, LCtx);
86  for (ExplodedNodeSet::iterator I = Dst.begin(), E = Dst.end();
87  I != E; ++I) {
88  ProgramStateRef State = (*I)->getState();
89  if (AlwaysReturnsLValue)
90  State = State->BindExpr(CallExpr, LCtx, ThisVal);
91  else
92  State = bindReturnValue(Call, LCtx, State);
93  Bldr.generateNode(PS, State, *I);
94  }
95 }
96 
97 
98 SVal ExprEngine::makeZeroElementRegion(ProgramStateRef State, SVal LValue,
99  QualType &Ty, bool &IsArray) {
100  SValBuilder &SVB = State->getStateManager().getSValBuilder();
101  ASTContext &Ctx = SVB.getContext();
102 
103  while (const ArrayType *AT = Ctx.getAsArrayType(Ty)) {
104  Ty = AT->getElementType();
105  LValue = State->getLValue(Ty, SVB.makeZeroArrayIndex(), LValue);
106  IsArray = true;
107  }
108 
109  return LValue;
110 }
111 
112 std::pair<ProgramStateRef, SVal> ExprEngine::prepareForObjectConstruction(
113  const Expr *E, ProgramStateRef State, const LocationContext *LCtx,
114  const ConstructionContext *CC, EvalCallOptions &CallOpts) {
115  SValBuilder &SVB = getSValBuilder();
116  MemRegionManager &MRMgr = SVB.getRegionManager();
117  ASTContext &ACtx = SVB.getContext();
118 
119  // See if we're constructing an existing region by looking at the
120  // current construction context.
121  if (CC) {
122  switch (CC->getKind()) {
125  const auto *DSCC = cast<VariableConstructionContext>(CC);
126  const auto *DS = DSCC->getDeclStmt();
127  const auto *Var = cast<VarDecl>(DS->getSingleDecl());
128  SVal LValue = State->getLValue(Var, LCtx);
129  QualType Ty = Var->getType();
130  LValue =
131  makeZeroElementRegion(State, LValue, Ty, CallOpts.IsArrayCtorOrDtor);
132  State =
133  addObjectUnderConstruction(State, DSCC->getDeclStmt(), LCtx, LValue);
134  return std::make_pair(State, LValue);
135  }
138  const auto *ICC = cast<ConstructorInitializerConstructionContext>(CC);
139  const auto *Init = ICC->getCXXCtorInitializer();
140  assert(Init->isAnyMemberInitializer());
141  const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl());
142  Loc ThisPtr =
143  SVB.getCXXThis(CurCtor, LCtx->getStackFrame());
144  SVal ThisVal = State->getSVal(ThisPtr);
145 
146  const ValueDecl *Field;
147  SVal FieldVal;
148  if (Init->isIndirectMemberInitializer()) {
149  Field = Init->getIndirectMember();
150  FieldVal = State->getLValue(Init->getIndirectMember(), ThisVal);
151  } else {
152  Field = Init->getMember();
153  FieldVal = State->getLValue(Init->getMember(), ThisVal);
154  }
155 
156  QualType Ty = Field->getType();
157  FieldVal = makeZeroElementRegion(State, FieldVal, Ty,
158  CallOpts.IsArrayCtorOrDtor);
159  State = addObjectUnderConstruction(State, Init, LCtx, FieldVal);
160  return std::make_pair(State, FieldVal);
161  }
163  if (AMgr.getAnalyzerOptions().MayInlineCXXAllocator) {
164  const auto *NECC = cast<NewAllocatedObjectConstructionContext>(CC);
165  const auto *NE = NECC->getCXXNewExpr();
166  SVal V = *getObjectUnderConstruction(State, NE, LCtx);
167  if (const SubRegion *MR =
168  dyn_cast_or_null<SubRegion>(V.getAsRegion())) {
169  if (NE->isArray()) {
170  // TODO: In fact, we need to call the constructor for every
171  // allocated element, not just the first one!
172  CallOpts.IsArrayCtorOrDtor = true;
173  return std::make_pair(
174  State, loc::MemRegionVal(getStoreManager().GetElementZeroRegion(
175  MR, NE->getType()->getPointeeType())));
176  }
177  return std::make_pair(State, V);
178  }
179  // TODO: Detect when the allocator returns a null pointer.
180  // Constructor shall not be called in this case.
181  }
182  break;
183  }
186  // The temporary is to be managed by the parent stack frame.
187  // So build it in the parent stack frame if we're not in the
188  // top frame of the analysis.
189  const StackFrameContext *SFC = LCtx->getStackFrame();
190  if (const LocationContext *CallerLCtx = SFC->getParent()) {
191  auto RTC = (*SFC->getCallSiteBlock())[SFC->getIndex()]
192  .getAs<CFGCXXRecordTypedCall>();
193  if (!RTC) {
194  // We were unable to find the correct construction context for the
195  // call in the parent stack frame. This is equivalent to not being
196  // able to find construction context at all.
197  break;
198  }
199  return prepareForObjectConstruction(
200  cast<Expr>(SFC->getCallSite()), State, CallerLCtx,
201  RTC->getConstructionContext(), CallOpts);
202  } else {
203  // We are on the top frame of the analysis. We do not know where is the
204  // object returned to. Conjure a symbolic region for the return value.
205  // TODO: We probably need a new MemRegion kind to represent the storage
206  // of that SymbolicRegion, so that we cound produce a fancy symbol
207  // instead of an anonymous conjured symbol.
208  // TODO: Do we need to track the region to avoid having it dead
209  // too early? It does die too early, at least in C++17, but because
210  // putting anything into a SymbolicRegion causes an immediate escape,
211  // it doesn't cause any leak false positives.
212  const auto *RCC = cast<ReturnedValueConstructionContext>(CC);
213  // Make sure that this doesn't coincide with any other symbol
214  // conjured for the returned expression.
215  static const int TopLevelSymRegionTag = 0;
216  const Expr *RetE = RCC->getReturnStmt()->getRetValue();
217  assert(RetE && "Void returns should not have a construction context");
218  QualType ReturnTy = RetE->getType();
219  QualType RegionTy = ACtx.getPointerType(ReturnTy);
220  SVal V = SVB.conjureSymbolVal(&TopLevelSymRegionTag, RetE, SFC,
221  RegionTy, currBldrCtx->blockCount());
222  return std::make_pair(State, V);
223  }
224  llvm_unreachable("Unhandled return value construction context!");
225  }
227  assert(AMgr.getAnalyzerOptions().ShouldElideConstructors);
228  const auto *TCC = cast<ElidedTemporaryObjectConstructionContext>(CC);
229  const CXXBindTemporaryExpr *BTE = TCC->getCXXBindTemporaryExpr();
230  const MaterializeTemporaryExpr *MTE = TCC->getMaterializedTemporaryExpr();
231  const CXXConstructExpr *CE = TCC->getConstructorAfterElision();
232 
233  // Support pre-C++17 copy elision. We'll have the elidable copy
234  // constructor in the AST and in the CFG, but we'll skip it
235  // and construct directly into the final object. This call
236  // also sets the CallOpts flags for us.
237  SVal V;
238  // If the elided copy/move constructor is not supported, there's still
239  // benefit in trying to model the non-elided constructor.
240  // Stash our state before trying to elide, as it'll get overwritten.
241  ProgramStateRef PreElideState = State;
242  EvalCallOptions PreElideCallOpts = CallOpts;
243 
244  std::tie(State, V) = prepareForObjectConstruction(
245  CE, State, LCtx, TCC->getConstructionContextAfterElision(), CallOpts);
246 
247  // FIXME: This definition of "copy elision has not failed" is unreliable.
248  // It doesn't indicate that the constructor will actually be inlined
249  // later; it is still up to evalCall() to decide.
251  // Remember that we've elided the constructor.
252  State = addObjectUnderConstruction(State, CE, LCtx, V);
253 
254  // Remember that we've elided the destructor.
255  if (BTE)
256  State = elideDestructor(State, BTE, LCtx);
257 
258  // Instead of materialization, shamelessly return
259  // the final object destination.
260  if (MTE)
261  State = addObjectUnderConstruction(State, MTE, LCtx, V);
262 
263  return std::make_pair(State, V);
264  } else {
265  // Copy elision failed. Revert the changes and proceed as if we have
266  // a simple temporary.
267  State = PreElideState;
268  CallOpts = PreElideCallOpts;
269  }
270  LLVM_FALLTHROUGH;
271  }
273  const auto *TCC = cast<TemporaryObjectConstructionContext>(CC);
274  const CXXBindTemporaryExpr *BTE = TCC->getCXXBindTemporaryExpr();
275  const MaterializeTemporaryExpr *MTE = TCC->getMaterializedTemporaryExpr();
276  SVal V = UnknownVal();
277 
278  if (MTE) {
279  if (const ValueDecl *VD = MTE->getExtendingDecl()) {
280  assert(MTE->getStorageDuration() != SD_FullExpression);
281  if (!VD->getType()->isReferenceType()) {
282  // We're lifetime-extended by a surrounding aggregate.
283  // Automatic destructors aren't quite working in this case
284  // on the CFG side. We should warn the caller about that.
285  // FIXME: Is there a better way to retrieve this information from
286  // the MaterializeTemporaryExpr?
288  }
289  }
290 
291  if (MTE->getStorageDuration() == SD_Static ||
292  MTE->getStorageDuration() == SD_Thread)
294  }
295 
296  if (V.isUnknown())
297  V = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx));
298 
299  if (BTE)
300  State = addObjectUnderConstruction(State, BTE, LCtx, V);
301 
302  if (MTE)
303  State = addObjectUnderConstruction(State, MTE, LCtx, V);
304 
305  CallOpts.IsTemporaryCtorOrDtor = true;
306  return std::make_pair(State, V);
307  }
309  // Arguments are technically temporaries.
310  CallOpts.IsTemporaryCtorOrDtor = true;
311 
312  const auto *ACC = cast<ArgumentConstructionContext>(CC);
313  const Expr *E = ACC->getCallLikeExpr();
314  unsigned Idx = ACC->getIndex();
315  const CXXBindTemporaryExpr *BTE = ACC->getCXXBindTemporaryExpr();
316 
318  SVal V = UnknownVal();
319  auto getArgLoc = [&](CallEventRef<> Caller) -> Optional<SVal> {
320  const LocationContext *FutureSFC = Caller->getCalleeStackFrame();
321  // Return early if we are unable to reliably foresee
322  // the future stack frame.
323  if (!FutureSFC)
324  return None;
325 
326  // This should be equivalent to Caller->getDecl() for now, but
327  // FutureSFC->getDecl() is likely to support better stuff (like
328  // virtual functions) earlier.
329  const Decl *CalleeD = FutureSFC->getDecl();
330 
331  // FIXME: Support for variadic arguments is not implemented here yet.
332  if (CallEvent::isVariadic(CalleeD))
333  return None;
334 
335  // Operator arguments do not correspond to operator parameters
336  // because this-argument is implemented as a normal argument in
337  // operator call expressions but not in operator declarations.
338  const VarRegion *VR = Caller->getParameterLocation(
339  *Caller->getAdjustedParameterIndex(Idx));
340  if (!VR)
341  return None;
342 
343  return loc::MemRegionVal(VR);
344  };
345 
346  if (const auto *CE = dyn_cast<CallExpr>(E)) {
347  CallEventRef<> Caller = CEMgr.getSimpleCall(CE, State, LCtx);
348  if (auto OptV = getArgLoc(Caller))
349  V = *OptV;
350  else
351  break;
352  State = addObjectUnderConstruction(State, {CE, Idx}, LCtx, V);
353  } else if (const auto *CCE = dyn_cast<CXXConstructExpr>(E)) {
354  // Don't bother figuring out the target region for the future
355  // constructor because we won't need it.
356  CallEventRef<> Caller =
357  CEMgr.getCXXConstructorCall(CCE, /*Target=*/nullptr, State, LCtx);
358  if (auto OptV = getArgLoc(Caller))
359  V = *OptV;
360  else
361  break;
362  State = addObjectUnderConstruction(State, {CCE, Idx}, LCtx, V);
363  } else if (const auto *ME = dyn_cast<ObjCMessageExpr>(E)) {
364  CallEventRef<> Caller = CEMgr.getObjCMethodCall(ME, State, LCtx);
365  if (auto OptV = getArgLoc(Caller))
366  V = *OptV;
367  else
368  break;
369  State = addObjectUnderConstruction(State, {ME, Idx}, LCtx, V);
370  }
371 
372  assert(!V.isUnknown());
373 
374  if (BTE)
375  State = addObjectUnderConstruction(State, BTE, LCtx, V);
376 
377  return std::make_pair(State, V);
378  }
379  }
380  }
381  // If we couldn't find an existing region to construct into, assume we're
382  // constructing a temporary. Notify the caller of our failure.
384  return std::make_pair(
385  State, loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx)));
386 }
387 
389  ExplodedNode *Pred,
390  ExplodedNodeSet &destNodes) {
391  const LocationContext *LCtx = Pred->getLocationContext();
392  ProgramStateRef State = Pred->getState();
393 
394  SVal Target = UnknownVal();
395 
396  if (Optional<SVal> ElidedTarget =
397  getObjectUnderConstruction(State, CE, LCtx)) {
398  // We've previously modeled an elidable constructor by pretending that it in
399  // fact constructs into the correct target. This constructor can therefore
400  // be skipped.
401  Target = *ElidedTarget;
402  StmtNodeBuilder Bldr(Pred, destNodes, *currBldrCtx);
403  State = finishObjectConstruction(State, CE, LCtx);
404  if (auto L = Target.getAs<Loc>())
405  State = State->BindExpr(CE, LCtx, State->getSVal(*L, CE->getType()));
406  Bldr.generateNode(CE, Pred, State);
407  return;
408  }
409 
410  // FIXME: Handle arrays, which run the same constructor for every element.
411  // For now, we just run the first constructor (which should still invalidate
412  // the entire array).
413 
414  EvalCallOptions CallOpts;
416  assert(C || getCurrentCFGElement().getAs<CFGStmt>());
417  const ConstructionContext *CC = C ? C->getConstructionContext() : nullptr;
418 
419  switch (CE->getConstructionKind()) {
421  std::tie(State, Target) =
422  prepareForObjectConstruction(CE, State, LCtx, CC, CallOpts);
423  break;
424  }
426  // Make sure we are not calling virtual base class initializers twice.
427  // Only the most-derived object should initialize virtual base classes.
428  if (const Stmt *Outer = LCtx->getStackFrame()->getCallSite()) {
429  const CXXConstructExpr *OuterCtor = dyn_cast<CXXConstructExpr>(Outer);
430  if (OuterCtor) {
431  switch (OuterCtor->getConstructionKind()) {
434  // Bail out!
435  destNodes.Add(Pred);
436  return;
439  break;
440  }
441  }
442  }
443  LLVM_FALLTHROUGH;
445  // In C++17, classes with non-virtual bases may be aggregates, so they would
446  // be initialized as aggregates without a constructor call, so we may have
447  // a base class constructed directly into an initializer list without
448  // having the derived-class constructor call on the previous stack frame.
449  // Initializer lists may be nested into more initializer lists that
450  // correspond to surrounding aggregate initializations.
451  // FIXME: For now this code essentially bails out. We need to find the
452  // correct target region and set it.
453  // FIXME: Instead of relying on the ParentMap, we should have the
454  // trigger-statement (InitListExpr in this case) passed down from CFG or
455  // otherwise always available during construction.
456  if (dyn_cast_or_null<InitListExpr>(LCtx->getParentMap().getParent(CE))) {
458  Target = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(CE, LCtx));
460  break;
461  }
462  LLVM_FALLTHROUGH;
464  const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl());
465  Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor,
466  LCtx->getStackFrame());
467  SVal ThisVal = State->getSVal(ThisPtr);
468 
470  Target = ThisVal;
471  } else {
472  // Cast to the base type.
473  bool IsVirtual =
475  SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, CE->getType(),
476  IsVirtual);
477  Target = BaseVal;
478  }
479  break;
480  }
481  }
482 
483  if (State != Pred->getState()) {
484  static SimpleProgramPointTag T("ExprEngine",
485  "Prepare for object construction");
486  ExplodedNodeSet DstPrepare;
487  StmtNodeBuilder BldrPrepare(Pred, DstPrepare, *currBldrCtx);
488  BldrPrepare.generateNode(CE, Pred, State, &T, ProgramPoint::PreStmtKind);
489  assert(DstPrepare.size() <= 1);
490  if (DstPrepare.size() == 0)
491  return;
492  Pred = *BldrPrepare.begin();
493  }
494 
497  CEMgr.getCXXConstructorCall(CE, Target.getAsRegion(), State, LCtx);
498 
499  ExplodedNodeSet DstPreVisit;
500  getCheckerManager().runCheckersForPreStmt(DstPreVisit, Pred, CE, *this);
501 
502  // FIXME: Is it possible and/or useful to do this before PreStmt?
503  ExplodedNodeSet PreInitialized;
504  {
505  StmtNodeBuilder Bldr(DstPreVisit, PreInitialized, *currBldrCtx);
506  for (ExplodedNodeSet::iterator I = DstPreVisit.begin(),
507  E = DstPreVisit.end();
508  I != E; ++I) {
509  ProgramStateRef State = (*I)->getState();
510  if (CE->requiresZeroInitialization()) {
511  // FIXME: Once we properly handle constructors in new-expressions, we'll
512  // need to invalidate the region before setting a default value, to make
513  // sure there aren't any lingering bindings around. This probably needs
514  // to happen regardless of whether or not the object is zero-initialized
515  // to handle random fields of a placement-initialized object picking up
516  // old bindings. We might only want to do it when we need to, though.
517  // FIXME: This isn't actually correct for arrays -- we need to zero-
518  // initialize the entire array, not just the first element -- but our
519  // handling of arrays everywhere else is weak as well, so this shouldn't
520  // actually make things worse. Placement new makes this tricky as well,
521  // since it's then possible to be initializing one part of a multi-
522  // dimensional array.
523  State = State->bindDefaultZero(Target, LCtx);
524  }
525 
526  Bldr.generateNode(CE, *I, State, /*tag=*/nullptr,
528  }
529  }
530 
531  ExplodedNodeSet DstPreCall;
532  getCheckerManager().runCheckersForPreCall(DstPreCall, PreInitialized,
533  *Call, *this);
534 
535  ExplodedNodeSet DstEvaluated;
536  StmtNodeBuilder Bldr(DstPreCall, DstEvaluated, *currBldrCtx);
537 
538  if (CE->getConstructor()->isTrivial() &&
540  !CallOpts.IsArrayCtorOrDtor) {
541  // FIXME: Handle other kinds of trivial constructors as well.
542  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
543  I != E; ++I)
544  performTrivialCopy(Bldr, *I, *Call);
545 
546  } else {
547  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
548  I != E; ++I)
549  defaultEvalCall(Bldr, *I, *Call, CallOpts);
550  }
551 
552  // If the CFG was constructed without elements for temporary destructors
553  // and the just-called constructor created a temporary object then
554  // stop exploration if the temporary object has a noreturn constructor.
555  // This can lose coverage because the destructor, if it were present
556  // in the CFG, would be called at the end of the full expression or
557  // later (for life-time extended temporaries) -- but avoids infeasible
558  // paths when no-return temporary destructors are used for assertions.
559  const AnalysisDeclContext *ADC = LCtx->getAnalysisDeclContext();
561  const MemRegion *Target = Call->getCXXThisVal().getAsRegion();
562  if (Target && isa<CXXTempObjectRegion>(Target) &&
563  Call->getDecl()->getParent()->isAnyDestructorNoReturn()) {
564 
565  // If we've inlined the constructor, then DstEvaluated would be empty.
566  // In this case we still want a sink, which could be implemented
567  // in processCallExit. But we don't have that implemented at the moment,
568  // so if you hit this assertion, see if you can avoid inlining
569  // the respective constructor when analyzer-config cfg-temporary-dtors
570  // is set to false.
571  // Otherwise there's nothing wrong with inlining such constructor.
572  assert(!DstEvaluated.empty() &&
573  "We should not have inlined this constructor!");
574 
575  for (ExplodedNode *N : DstEvaluated) {
576  Bldr.generateSink(CE, N, N->getState());
577  }
578 
579  // There is no need to run the PostCall and PostStmt checker
580  // callbacks because we just generated sinks on all nodes in th
581  // frontier.
582  return;
583  }
584  }
585 
586  ExplodedNodeSet DstPostArgumentCleanup;
587  for (auto I : DstEvaluated)
588  finishArgumentConstruction(DstPostArgumentCleanup, I, *Call);
589 
590  // If there were other constructors called for object-type arguments
591  // of this constructor, clean them up.
592  ExplodedNodeSet DstPostCall;
594  DstPostArgumentCleanup,
595  *Call, *this);
596  getCheckerManager().runCheckersForPostStmt(destNodes, DstPostCall, CE, *this);
597 }
598 
600  const MemRegion *Dest,
601  const Stmt *S,
602  bool IsBaseDtor,
603  ExplodedNode *Pred,
604  ExplodedNodeSet &Dst,
605  const EvalCallOptions &CallOpts) {
606  assert(S && "A destructor without a trigger!");
607  const LocationContext *LCtx = Pred->getLocationContext();
608  ProgramStateRef State = Pred->getState();
609 
610  const CXXRecordDecl *RecordDecl = ObjectType->getAsCXXRecordDecl();
611  assert(RecordDecl && "Only CXXRecordDecls should have destructors");
612  const CXXDestructorDecl *DtorDecl = RecordDecl->getDestructor();
613 
614  // FIXME: There should always be a Decl, otherwise the destructor call
615  // shouldn't have been added to the CFG in the first place.
616  if (!DtorDecl) {
617  // Skip the invalid destructor. We cannot simply return because
618  // it would interrupt the analysis instead.
619  static SimpleProgramPointTag T("ExprEngine", "SkipInvalidDestructor");
620  // FIXME: PostImplicitCall with a null decl may crash elsewhere anyway.
621  PostImplicitCall PP(/*Decl=*/nullptr, S->getEndLoc(), LCtx, &T);
622  NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
623  Bldr.generateNode(PP, Pred->getState(), Pred);
624  return;
625  }
626 
629  CEMgr.getCXXDestructorCall(DtorDecl, S, Dest, IsBaseDtor, State, LCtx);
630 
631  PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
632  Call->getSourceRange().getBegin(),
633  "Error evaluating destructor");
634 
635  ExplodedNodeSet DstPreCall;
636  getCheckerManager().runCheckersForPreCall(DstPreCall, Pred,
637  *Call, *this);
638 
639  ExplodedNodeSet DstInvalidated;
640  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
641  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
642  I != E; ++I)
643  defaultEvalCall(Bldr, *I, *Call, CallOpts);
644 
645  getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
646  *Call, *this);
647 }
648 
650  ExplodedNode *Pred,
651  ExplodedNodeSet &Dst) {
652  ProgramStateRef State = Pred->getState();
653  const LocationContext *LCtx = Pred->getLocationContext();
654  PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
655  CNE->getBeginLoc(),
656  "Error evaluating New Allocator Call");
659  CEMgr.getCXXAllocatorCall(CNE, State, LCtx);
660 
661  ExplodedNodeSet DstPreCall;
662  getCheckerManager().runCheckersForPreCall(DstPreCall, Pred,
663  *Call, *this);
664 
665  ExplodedNodeSet DstPostCall;
666  StmtNodeBuilder CallBldr(DstPreCall, DstPostCall, *currBldrCtx);
667  for (auto I : DstPreCall) {
668  // FIXME: Provide evalCall for checkers?
669  defaultEvalCall(CallBldr, I, *Call);
670  }
671  // If the call is inlined, DstPostCall will be empty and we bail out now.
672 
673  // Store return value of operator new() for future use, until the actual
674  // CXXNewExpr gets processed.
675  ExplodedNodeSet DstPostValue;
676  StmtNodeBuilder ValueBldr(DstPostCall, DstPostValue, *currBldrCtx);
677  for (auto I : DstPostCall) {
678  // FIXME: Because CNE serves as the "call site" for the allocator (due to
679  // lack of a better expression in the AST), the conjured return value symbol
680  // is going to be of the same type (C++ object pointer type). Technically
681  // this is not correct because the operator new's prototype always says that
682  // it returns a 'void *'. So we should change the type of the symbol,
683  // and then evaluate the cast over the symbolic pointer from 'void *' to
684  // the object pointer type. But without changing the symbol's type it
685  // is breaking too much to evaluate the no-op symbolic cast over it, so we
686  // skip it for now.
687  ProgramStateRef State = I->getState();
688  SVal RetVal = State->getSVal(CNE, LCtx);
689 
690  // If this allocation function is not declared as non-throwing, failures
691  // /must/ be signalled by exceptions, and thus the return value will never
692  // be NULL. -fno-exceptions does not influence this semantics.
693  // FIXME: GCC has a -fcheck-new option, which forces it to consider the case
694  // where new can return NULL. If we end up supporting that option, we can
695  // consider adding a check for it here.
696  // C++11 [basic.stc.dynamic.allocation]p3.
697  if (const FunctionDecl *FD = CNE->getOperatorNew()) {
698  QualType Ty = FD->getType();
699  if (const auto *ProtoType = Ty->getAs<FunctionProtoType>())
700  if (!ProtoType->isNothrow())
701  State = State->assume(RetVal.castAs<DefinedOrUnknownSVal>(), true);
702  }
703 
704  ValueBldr.generateNode(
705  CNE, I, addObjectUnderConstruction(State, CNE, LCtx, RetVal));
706  }
707 
708  ExplodedNodeSet DstPostPostCallCallback;
709  getCheckerManager().runCheckersForPostCall(DstPostPostCallCallback,
710  DstPostValue, *Call, *this);
711  for (auto I : DstPostPostCallCallback) {
713  CNE, *getObjectUnderConstruction(I->getState(), CNE, LCtx), Dst, I,
714  *this);
715  }
716 }
717 
719  ExplodedNodeSet &Dst) {
720  // FIXME: Much of this should eventually migrate to CXXAllocatorCall.
721  // Also, we need to decide how allocators actually work -- they're not
722  // really part of the CXXNewExpr because they happen BEFORE the
723  // CXXConstructExpr subexpression. See PR12014 for some discussion.
724 
725  unsigned blockCount = currBldrCtx->blockCount();
726  const LocationContext *LCtx = Pred->getLocationContext();
727  SVal symVal = UnknownVal();
728  FunctionDecl *FD = CNE->getOperatorNew();
729 
730  bool IsStandardGlobalOpNewFunction =
732 
733  ProgramStateRef State = Pred->getState();
734 
735  // Retrieve the stored operator new() return value.
736  if (AMgr.getAnalyzerOptions().MayInlineCXXAllocator) {
737  symVal = *getObjectUnderConstruction(State, CNE, LCtx);
738  State = finishObjectConstruction(State, CNE, LCtx);
739  }
740 
741  // We assume all standard global 'operator new' functions allocate memory in
742  // heap. We realize this is an approximation that might not correctly model
743  // a custom global allocator.
744  if (symVal.isUnknown()) {
745  if (IsStandardGlobalOpNewFunction)
746  symVal = svalBuilder.getConjuredHeapSymbolVal(CNE, LCtx, blockCount);
747  else
748  symVal = svalBuilder.conjureSymbolVal(nullptr, CNE, LCtx, CNE->getType(),
749  blockCount);
750  }
751 
754  CEMgr.getCXXAllocatorCall(CNE, State, LCtx);
755 
756  if (!AMgr.getAnalyzerOptions().MayInlineCXXAllocator) {
757  // Invalidate placement args.
758  // FIXME: Once we figure out how we want allocators to work,
759  // we should be using the usual pre-/(default-)eval-/post-call checks here.
760  State = Call->invalidateRegions(blockCount);
761  if (!State)
762  return;
763 
764  // If this allocation function is not declared as non-throwing, failures
765  // /must/ be signalled by exceptions, and thus the return value will never
766  // be NULL. -fno-exceptions does not influence this semantics.
767  // FIXME: GCC has a -fcheck-new option, which forces it to consider the case
768  // where new can return NULL. If we end up supporting that option, we can
769  // consider adding a check for it here.
770  // C++11 [basic.stc.dynamic.allocation]p3.
771  if (FD) {
772  QualType Ty = FD->getType();
773  if (const auto *ProtoType = Ty->getAs<FunctionProtoType>())
774  if (!ProtoType->isNothrow())
775  if (auto dSymVal = symVal.getAs<DefinedOrUnknownSVal>())
776  State = State->assume(*dSymVal, true);
777  }
778  }
779 
780  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
781 
782  SVal Result = symVal;
783 
784  if (CNE->isArray()) {
785  // FIXME: allocating an array requires simulating the constructors.
786  // For now, just return a symbolicated region.
787  if (const SubRegion *NewReg =
788  dyn_cast_or_null<SubRegion>(symVal.getAsRegion())) {
789  QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType();
790  const ElementRegion *EleReg =
791  getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
792  Result = loc::MemRegionVal(EleReg);
793  }
794  State = State->BindExpr(CNE, Pred->getLocationContext(), Result);
795  Bldr.generateNode(CNE, Pred, State);
796  return;
797  }
798 
799  // FIXME: Once we have proper support for CXXConstructExprs inside
800  // CXXNewExpr, we need to make sure that the constructed object is not
801  // immediately invalidated here. (The placement call should happen before
802  // the constructor call anyway.)
803  if (FD && FD->isReservedGlobalPlacementOperator()) {
804  // Non-array placement new should always return the placement location.
805  SVal PlacementLoc = State->getSVal(CNE->getPlacementArg(0), LCtx);
806  Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(),
807  CNE->getPlacementArg(0)->getType());
808  }
809 
810  // Bind the address of the object, then check to see if we cached out.
811  State = State->BindExpr(CNE, LCtx, Result);
812  ExplodedNode *NewN = Bldr.generateNode(CNE, Pred, State);
813  if (!NewN)
814  return;
815 
816  // If the type is not a record, we won't have a CXXConstructExpr as an
817  // initializer. Copy the value over.
818  if (const Expr *Init = CNE->getInitializer()) {
819  if (!isa<CXXConstructExpr>(Init)) {
820  assert(Bldr.getResults().size() == 1);
821  Bldr.takeNodes(NewN);
822  evalBind(Dst, CNE, NewN, Result, State->getSVal(Init, LCtx),
823  /*FirstInit=*/IsStandardGlobalOpNewFunction);
824  }
825  }
826 }
827 
829  ExplodedNode *Pred, ExplodedNodeSet &Dst) {
830  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
831  ProgramStateRef state = Pred->getState();
832  Bldr.generateNode(CDE, Pred, state);
833 }
834 
836  ExplodedNode *Pred,
837  ExplodedNodeSet &Dst) {
838  const VarDecl *VD = CS->getExceptionDecl();
839  if (!VD) {
840  Dst.Add(Pred);
841  return;
842  }
843 
844  const LocationContext *LCtx = Pred->getLocationContext();
845  SVal V = svalBuilder.conjureSymbolVal(CS, LCtx, VD->getType(),
846  currBldrCtx->blockCount());
847  ProgramStateRef state = Pred->getState();
848  state = state->bindLoc(state->getLValue(VD, LCtx), V, LCtx);
849 
850  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
851  Bldr.generateNode(CS, Pred, state);
852 }
853 
855  ExplodedNodeSet &Dst) {
856  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
857 
858  // Get the this object region from StoreManager.
859  const LocationContext *LCtx = Pred->getLocationContext();
860  const MemRegion *R =
861  svalBuilder.getRegionManager().getCXXThisRegion(
862  getContext().getCanonicalType(TE->getType()),
863  LCtx);
864 
865  ProgramStateRef state = Pred->getState();
866  SVal V = state->getSVal(loc::MemRegionVal(R));
867  Bldr.generateNode(TE, Pred, state->BindExpr(TE, LCtx, V));
868 }
869 
871  ExplodedNodeSet &Dst) {
872  const LocationContext *LocCtxt = Pred->getLocationContext();
873 
874  // Get the region of the lambda itself.
875  const MemRegion *R = svalBuilder.getRegionManager().getCXXTempObjectRegion(
876  LE, LocCtxt);
877  SVal V = loc::MemRegionVal(R);
878 
879  ProgramStateRef State = Pred->getState();
880 
881  // If we created a new MemRegion for the lambda, we should explicitly bind
882  // the captures.
885  e = LE->capture_init_end();
886  i != e; ++i, ++CurField) {
887  FieldDecl *FieldForCapture = *CurField;
888  SVal FieldLoc = State->getLValue(FieldForCapture, V);
889 
890  SVal InitVal;
891  if (!FieldForCapture->hasCapturedVLAType()) {
892  Expr *InitExpr = *i;
893  assert(InitExpr && "Capture missing initialization expression");
894  InitVal = State->getSVal(InitExpr, LocCtxt);
895  } else {
896  // The field stores the length of a captured variable-length array.
897  // These captures don't have initialization expressions; instead we
898  // get the length from the VLAType size expression.
899  Expr *SizeExpr = FieldForCapture->getCapturedVLAType()->getSizeExpr();
900  InitVal = State->getSVal(SizeExpr, LocCtxt);
901  }
902 
903  State = State->bindLoc(FieldLoc, InitVal, LocCtxt);
904  }
905 
906  // Decay the Loc into an RValue, because there might be a
907  // MaterializeTemporaryExpr node above this one which expects the bound value
908  // to be an RValue.
909  SVal LambdaRVal = State->getSVal(R);
910 
911  ExplodedNodeSet Tmp;
912  StmtNodeBuilder Bldr(Pred, Tmp, *currBldrCtx);
913  // FIXME: is this the right program point kind?
914  Bldr.generateNode(LE, Pred,
915  State->BindExpr(LE, LocCtxt, LambdaRVal),
917 
918  // FIXME: Move all post/pre visits to ::Visit().
919  getCheckerManager().runCheckersForPostStmt(Dst, Tmp, LE, *this);
920 }
bool hasCapturedVLAType() const
Determine whether this member captures the variable length array type.
Definition: Decl.h:2746
Represents a function declaration or definition.
Definition: Decl.h:1737
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
Definition: Decl.cpp:2794
SVal evalDerivedToBase(SVal Derived, const CastExpr *Cast)
Evaluates a chain of derived-to-base casts through the path specified in Cast.
Definition: Store.cpp:248
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2539
A (possibly-)qualified type.
Definition: Type.h:637
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:94
Static storage duration.
Definition: Specifiers.h:280
bool IsTemporaryCtorOrDtor
This call is a constructor or a destructor of a temporary value.
Definition: ExprEngine.h:105
unsigned blockCount() const
Returns the number of times the current basic block has been visited on the exploded graph path...
Definition: CoreEngine.h:211
Stmt - This represents one statement.
Definition: Stmt.h:65
This builder class is useful for generating nodes that resulted from visiting a statement.
Definition: CoreEngine.h:369
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
FunctionDecl * getOperatorNew() const
Definition: ExprCXX.h:2032
Manages the lifetime of CallEvent objects.
Definition: CallEvent.h:1086
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called...
Definition: ExprCXX.h:1372
CallEventRef< CXXDestructorCall > getCXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBase, ProgramStateRef State, const LocationContext *LCtx)
Definition: CallEvent.h:1167
Stmt * getParent(Stmt *) const
Definition: ParentMap.cpp:122
Hints for figuring out of a call should be inlined during evalCall().
Definition: ExprEngine.h:95
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2814
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1261
bool IsArrayCtorOrDtor
This call is a constructor or a destructor for a single element within an array, a part of array cons...
Definition: ExprEngine.h:102
CallEventRef getSimpleCall(const CallExpr *E, ProgramStateRef State, const LocationContext *LCtx)
Definition: CallEvent.cpp:1341
const ProgramStateRef & getState() const
SVal evalCast(SVal val, QualType castTy, QualType originalType)
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Definition: ExprCXX.h:4155
const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:254
void takeNodes(const ExplodedNodeSet &S)
Definition: CoreEngine.h:320
Represents a variable declaration or definition.
Definition: Decl.h:812
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6754
loc::MemRegionVal getCXXThis(const CXXMethodDecl *D, const StackFrameContext *SFC)
Return a memory region for the &#39;this&#39; object reference.
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:462
const ElementRegion * GetElementZeroRegion(const SubRegion *R, QualType T)
Definition: Store.cpp:67
void VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition: ExprCXX.cpp:1195
Represents a function call that returns a C++ object by value.
Definition: CFG.h:178
Represents a struct/union/class.
Definition: Decl.h:3592
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Definition: DeclCXX.h:1326
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
Definition: ExprCXX.h:4196
MemRegionManager & getRegionManager()
Definition: SValBuilder.h:174
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
LineState State
Represents a member of a struct/union/class.
Definition: Decl.h:2578
AnalysisDeclContext contains the context data for the function or method under analysis.
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 isReplaceableGlobalAllocationFunction(bool *IsAligned=nullptr) const
Determines whether this function is one of the replaceable global allocation functions: void *operato...
Definition: Decl.cpp:2817
ExplodedNode * generateSink(const Stmt *S, ExplodedNode *Pred, ProgramStateRef St, const ProgramPointTag *tag=nullptr, ProgramPoint::Kind K=ProgramPoint::PostStmtKind)
Definition: CoreEngine.h:408
void runCheckersForPreCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng)
Run checkers for pre-visiting obj-c messages.
CFGElement getCurrentCFGElement()
Return the CFG element corresponding to the worklist element that is currently being processed by Exp...
Definition: ExprEngine.h:656
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
Definition: ExprCXX.h:1793
Expr * getInitializer()
The initializer of this new-expression.
Definition: ExprCXX.h:2089
const LocationContext * getLocationContext() const
const LocationContext * getParent() const
bool isUnknown() const
Definition: SVals.h:136
If a crash happens while one of these objects are live, the message is printed out along with the spe...
Expr * getSizeExpr() const
Definition: Type.h:2993
field_iterator field_begin() const
Definition: Decl.cpp:4144
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1216
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1648
void runCheckersForPostCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting obj-c messages.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Definition: DeclCXX.cpp:1696
static bool isVariadic(const Decl *D)
Returns true if the given decl is known to be variadic.
Definition: CallEvent.cpp:476
Represents the this expression in C++.
Definition: ExprCXX.h:975
const CFGBlock * getCallSiteBlock() const
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:189
const ValueDecl * getExtendingDecl() const
Get the declaration which triggered the lifetime-extension of this temporary, if any.
Definition: ExprCXX.h:4218
ProgramStateRef bindReturnValue(const CallEvent &Call, const LocationContext *LCtx, ProgramStateRef State)
Create a new state in which the call return value is binded to the call origin expression.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1612
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3689
const Stmt * getCallSite() const
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1333
void VisitCXXCatchStmt(const CXXCatchStmt *CS, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void runCheckersForPostStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting Stmts.
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
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Definition: DeclCXX.cpp:2375
void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCXXNewAllocatorCall(const CXXNewExpr *CNE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2705
AnalyzerOptions & getAnalyzerOptions() override
VarDecl * getExceptionDecl() const
Definition: StmtCXX.h:49
This is the simplest builder which generates nodes in the ExplodedGraph.
Definition: CoreEngine.h:227
Represents C++ constructor call.
Definition: CFG.h:150
void Add(ExplodedNode *N)
const ExplodedNodeSet & getResults()
Definition: CoreEngine.h:297
QualType getType() const
Definition: Expr.h:128
virtual const Decl * getDecl() const
Returns the declaration of the function or method that will be called.
Definition: CallEvent.h:234
ASTContext & getContext() const
getContext - Return the ASTContext associated with this analysis.
Definition: ExprEngine.h:181
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1751
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Definition: ExprCXX.h:4199
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2025
CallEventRef< ObjCMethodCall > getObjCMethodCall(const ObjCMessageExpr *E, ProgramStateRef State, const LocationContext *LCtx)
Definition: CallEvent.h:1155
ParentMap & getParentMap() const
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
Definition: SVals.h:111
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:300
Thread storage duration.
Definition: Specifiers.h:279
void runCheckersForNewAllocator(const CXXNewExpr *NE, SVal Target, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng, bool wasInlined=false)
Run checkers between C++ operator new and constructor calls.
CallEventRef< CXXAllocatorCall > getCXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef State, const LocationContext *LCtx)
Definition: CallEvent.h:1174
DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, const Expr *expr, const LocationContext *LCtx, unsigned count)
Create a new symbol with a unique &#39;name&#39;.
const MemRegion * getAsRegion() const
Definition: SVals.cpp:150
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Definition: ExprCXX.h:1913
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:2153
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition: Decl.h:2751
CallEventManager & getCallEventManager()
Definition: ProgramState.h:561
const CXXTempObjectRegion * getCXXTempObjectRegion(Expr const *Ex, LocationContext const *LC)
Definition: MemRegion.cpp:1041
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2040
ASTContext & getContext()
Definition: SValBuilder.h:155
void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
bool IsCtorOrDtorWithImproperlyModeledTargetRegion
This call is a constructor or a destructor for which we do not currently compute the this-region corr...
Definition: ExprEngine.h:98
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Definition: SVals.h:75
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
bool isArray() const
Definition: ExprCXX.h:2037
void runCheckersForPreStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng)
Run checkers for pre-visiting Stmts.
DefinedOrUnknownSVal getConjuredHeapSymbolVal(const Expr *E, const LocationContext *LCtx, unsigned Count)
Conjure a symbol representing heap allocated memory region.
const CXXThisRegion * getCXXThisRegion(QualType thisPointerTy, const LocationContext *LC)
getCXXThisRegion - Retrieve the [artificial] region associated with the parameter &#39;this&#39;...
Definition: MemRegion.cpp:1097
Optional< T > getAs() const
Convert to the specified CFGElement type, returning None if this CFGElement is not of the desired typ...
Definition: CFG.h:109
Dataflow Directional Tag Classes.
CFG::BuildOptions & getCFGBuildOptions()
Return the build options used to construct the CFG.
SValBuilder & getSValBuilder()
Definition: ExprEngine.h:193
Represents a delete expression for memory deallocation and destructor calls, e.g. ...
Definition: ExprCXX.h:2169
StoreManager & getStoreManager()
Definition: ExprEngine.h:385
Represents a program point just after an implicit call event.
Definition: ProgramPoint.h:601
void VisitCXXDestructor(QualType ObjectType, const MemRegion *Dest, const Stmt *S, bool IsBaseDtor, ExplodedNode *Pred, ExplodedNodeSet &Dst, const EvalCallOptions &Options)
void VisitLambdaExpr(const LambdaExpr *LE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitLambdaExpr - Transfer function logic for LambdaExprs.
Represents an abstract call to a function or method along a particular path.
Definition: CallEvent.h:170
Expr * getPlacementArg(unsigned I)
Definition: ExprCXX.h:2059
ProgramStateManager & getStateManager() override
Definition: ExprEngine.h:383
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Definition: DeclBase.h:2016
const Decl * getDecl() const
const CXXTempObjectRegion * getCXXStaticTempObjectRegion(const Expr *Ex)
Create a CXXTempObjectRegion for temporaries which are lifetime-extended by static references...
Definition: MemRegion.cpp:965
void defaultEvalCall(NodeBuilder &B, ExplodedNode *Pred, const CallEvent &Call, const EvalCallOptions &CallOpts={})
Default implementation of call evaluation.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition: SVals.h:103
SubRegion - A region that subsets another larger region.
Definition: MemRegion.h:435
void VisitCXXConstructExpr(const CXXConstructExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
const StackFrameContext * getStackFrame() const
CallEventRef< CXXConstructorCall > getCXXConstructorCall(const CXXConstructExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx)
Definition: CallEvent.h:1161
ExplodedNode * generateNode(const ProgramPoint &PP, ProgramStateRef State, ExplodedNode *Pred)
Generates a node in the ExplodedGraph.
Definition: CoreEngine.h:280
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
ConstructionContext&#39;s subclasses describe different ways of constructing an object in C++...
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
bool IsTemporaryLifetimeExtendedViaAggregate
This call is a constructor for a temporary that is lifetime-extended by binding it to a reference-typ...
Definition: ExprEngine.h:110
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
Full-expression storage duration (for temporaries).
Definition: Specifiers.h:277
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2402
ExplodedNode * generateNode(const Stmt *S, ExplodedNode *Pred, ProgramStateRef St, const ProgramPointTag *tag=nullptr, ProgramPoint::Kind K=ProgramPoint::PostStmtKind)
Definition: CoreEngine.h:398
iterator begin()
Iterators through the results frontier.
Definition: CoreEngine.h:306
ElementRegion is used to represent both array elements and casts.
Definition: MemRegion.h:1085
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument for this lambda expression...
Definition: ExprCXX.h:1805
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
Definition: ExprCXX.h:1779
virtual SVal getArgSVal(unsigned Index) const
Returns the value of a given argument at the time of the call.
Definition: CallEvent.cpp:400
QualType getType() const
Definition: Decl.h:647
AnalysisDeclContext * getAnalysisDeclContext() const
void CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Create a C++ temporary object for an rvalue.
Represents a call to a C++ constructor.
Definition: CallEvent.h:848
bool isUnknownOrUndef() const
Definition: SVals.h:144
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Definition: Expr.cpp:2559
ConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1381