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  if (isa<BlockInvocationContext>(CallerLCtx)) {
200  // Unwrap block invocation contexts. They're mostly part of
201  // the current stack frame.
202  CallerLCtx = CallerLCtx->getParent();
203  assert(!isa<BlockInvocationContext>(CallerLCtx));
204  }
205  return prepareForObjectConstruction(
206  cast<Expr>(SFC->getCallSite()), State, CallerLCtx,
207  RTC->getConstructionContext(), CallOpts);
208  } else {
209  // We are on the top frame of the analysis. We do not know where is the
210  // object returned to. Conjure a symbolic region for the return value.
211  // TODO: We probably need a new MemRegion kind to represent the storage
212  // of that SymbolicRegion, so that we cound produce a fancy symbol
213  // instead of an anonymous conjured symbol.
214  // TODO: Do we need to track the region to avoid having it dead
215  // too early? It does die too early, at least in C++17, but because
216  // putting anything into a SymbolicRegion causes an immediate escape,
217  // it doesn't cause any leak false positives.
218  const auto *RCC = cast<ReturnedValueConstructionContext>(CC);
219  // Make sure that this doesn't coincide with any other symbol
220  // conjured for the returned expression.
221  static const int TopLevelSymRegionTag = 0;
222  const Expr *RetE = RCC->getReturnStmt()->getRetValue();
223  assert(RetE && "Void returns should not have a construction context");
224  QualType ReturnTy = RetE->getType();
225  QualType RegionTy = ACtx.getPointerType(ReturnTy);
226  SVal V = SVB.conjureSymbolVal(&TopLevelSymRegionTag, RetE, SFC,
227  RegionTy, currBldrCtx->blockCount());
228  return std::make_pair(State, V);
229  }
230  llvm_unreachable("Unhandled return value construction context!");
231  }
233  assert(AMgr.getAnalyzerOptions().ShouldElideConstructors);
234  const auto *TCC = cast<ElidedTemporaryObjectConstructionContext>(CC);
235  const CXXBindTemporaryExpr *BTE = TCC->getCXXBindTemporaryExpr();
236  const MaterializeTemporaryExpr *MTE = TCC->getMaterializedTemporaryExpr();
237  const CXXConstructExpr *CE = TCC->getConstructorAfterElision();
238 
239  // Support pre-C++17 copy elision. We'll have the elidable copy
240  // constructor in the AST and in the CFG, but we'll skip it
241  // and construct directly into the final object. This call
242  // also sets the CallOpts flags for us.
243  SVal V;
244  // If the elided copy/move constructor is not supported, there's still
245  // benefit in trying to model the non-elided constructor.
246  // Stash our state before trying to elide, as it'll get overwritten.
247  ProgramStateRef PreElideState = State;
248  EvalCallOptions PreElideCallOpts = CallOpts;
249 
250  std::tie(State, V) = prepareForObjectConstruction(
251  CE, State, LCtx, TCC->getConstructionContextAfterElision(), CallOpts);
252 
253  // FIXME: This definition of "copy elision has not failed" is unreliable.
254  // It doesn't indicate that the constructor will actually be inlined
255  // later; it is still up to evalCall() to decide.
257  // Remember that we've elided the constructor.
258  State = addObjectUnderConstruction(State, CE, LCtx, V);
259 
260  // Remember that we've elided the destructor.
261  if (BTE)
262  State = elideDestructor(State, BTE, LCtx);
263 
264  // Instead of materialization, shamelessly return
265  // the final object destination.
266  if (MTE)
267  State = addObjectUnderConstruction(State, MTE, LCtx, V);
268 
269  return std::make_pair(State, V);
270  } else {
271  // Copy elision failed. Revert the changes and proceed as if we have
272  // a simple temporary.
273  State = PreElideState;
274  CallOpts = PreElideCallOpts;
275  }
276  LLVM_FALLTHROUGH;
277  }
279  const auto *TCC = cast<TemporaryObjectConstructionContext>(CC);
280  const CXXBindTemporaryExpr *BTE = TCC->getCXXBindTemporaryExpr();
281  const MaterializeTemporaryExpr *MTE = TCC->getMaterializedTemporaryExpr();
282  SVal V = UnknownVal();
283 
284  if (MTE) {
285  if (const ValueDecl *VD = MTE->getExtendingDecl()) {
286  assert(MTE->getStorageDuration() != SD_FullExpression);
287  if (!VD->getType()->isReferenceType()) {
288  // We're lifetime-extended by a surrounding aggregate.
289  // Automatic destructors aren't quite working in this case
290  // on the CFG side. We should warn the caller about that.
291  // FIXME: Is there a better way to retrieve this information from
292  // the MaterializeTemporaryExpr?
294  }
295  }
296 
297  if (MTE->getStorageDuration() == SD_Static ||
298  MTE->getStorageDuration() == SD_Thread)
300  }
301 
302  if (V.isUnknown())
303  V = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx));
304 
305  if (BTE)
306  State = addObjectUnderConstruction(State, BTE, LCtx, V);
307 
308  if (MTE)
309  State = addObjectUnderConstruction(State, MTE, LCtx, V);
310 
311  CallOpts.IsTemporaryCtorOrDtor = true;
312  return std::make_pair(State, V);
313  }
315  // Arguments are technically temporaries.
316  CallOpts.IsTemporaryCtorOrDtor = true;
317 
318  const auto *ACC = cast<ArgumentConstructionContext>(CC);
319  const Expr *E = ACC->getCallLikeExpr();
320  unsigned Idx = ACC->getIndex();
321  const CXXBindTemporaryExpr *BTE = ACC->getCXXBindTemporaryExpr();
322 
324  SVal V = UnknownVal();
325  auto getArgLoc = [&](CallEventRef<> Caller) -> Optional<SVal> {
326  const LocationContext *FutureSFC = Caller->getCalleeStackFrame();
327  // Return early if we are unable to reliably foresee
328  // the future stack frame.
329  if (!FutureSFC)
330  return None;
331 
332  // This should be equivalent to Caller->getDecl() for now, but
333  // FutureSFC->getDecl() is likely to support better stuff (like
334  // virtual functions) earlier.
335  const Decl *CalleeD = FutureSFC->getDecl();
336 
337  // FIXME: Support for variadic arguments is not implemented here yet.
338  if (CallEvent::isVariadic(CalleeD))
339  return None;
340 
341  // Operator arguments do not correspond to operator parameters
342  // because this-argument is implemented as a normal argument in
343  // operator call expressions but not in operator declarations.
344  const VarRegion *VR = Caller->getParameterLocation(
345  *Caller->getAdjustedParameterIndex(Idx));
346  if (!VR)
347  return None;
348 
349  return loc::MemRegionVal(VR);
350  };
351 
352  if (const auto *CE = dyn_cast<CallExpr>(E)) {
353  CallEventRef<> Caller = CEMgr.getSimpleCall(CE, State, LCtx);
354  if (auto OptV = getArgLoc(Caller))
355  V = *OptV;
356  else
357  break;
358  State = addObjectUnderConstruction(State, {CE, Idx}, LCtx, V);
359  } else if (const auto *CCE = dyn_cast<CXXConstructExpr>(E)) {
360  // Don't bother figuring out the target region for the future
361  // constructor because we won't need it.
362  CallEventRef<> Caller =
363  CEMgr.getCXXConstructorCall(CCE, /*Target=*/nullptr, State, LCtx);
364  if (auto OptV = getArgLoc(Caller))
365  V = *OptV;
366  else
367  break;
368  State = addObjectUnderConstruction(State, {CCE, Idx}, LCtx, V);
369  } else if (const auto *ME = dyn_cast<ObjCMessageExpr>(E)) {
370  CallEventRef<> Caller = CEMgr.getObjCMethodCall(ME, State, LCtx);
371  if (auto OptV = getArgLoc(Caller))
372  V = *OptV;
373  else
374  break;
375  State = addObjectUnderConstruction(State, {ME, Idx}, LCtx, V);
376  }
377 
378  assert(!V.isUnknown());
379 
380  if (BTE)
381  State = addObjectUnderConstruction(State, BTE, LCtx, V);
382 
383  return std::make_pair(State, V);
384  }
385  }
386  }
387  // If we couldn't find an existing region to construct into, assume we're
388  // constructing a temporary. Notify the caller of our failure.
390  return std::make_pair(
391  State, loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx)));
392 }
393 
395  ExplodedNode *Pred,
396  ExplodedNodeSet &destNodes) {
397  const LocationContext *LCtx = Pred->getLocationContext();
398  ProgramStateRef State = Pred->getState();
399 
400  SVal Target = UnknownVal();
401 
402  if (Optional<SVal> ElidedTarget =
403  getObjectUnderConstruction(State, CE, LCtx)) {
404  // We've previously modeled an elidable constructor by pretending that it in
405  // fact constructs into the correct target. This constructor can therefore
406  // be skipped.
407  Target = *ElidedTarget;
408  StmtNodeBuilder Bldr(Pred, destNodes, *currBldrCtx);
409  State = finishObjectConstruction(State, CE, LCtx);
410  if (auto L = Target.getAs<Loc>())
411  State = State->BindExpr(CE, LCtx, State->getSVal(*L, CE->getType()));
412  Bldr.generateNode(CE, Pred, State);
413  return;
414  }
415 
416  // FIXME: Handle arrays, which run the same constructor for every element.
417  // For now, we just run the first constructor (which should still invalidate
418  // the entire array).
419 
420  EvalCallOptions CallOpts;
422  assert(C || getCurrentCFGElement().getAs<CFGStmt>());
423  const ConstructionContext *CC = C ? C->getConstructionContext() : nullptr;
424 
425  switch (CE->getConstructionKind()) {
427  std::tie(State, Target) =
428  prepareForObjectConstruction(CE, State, LCtx, CC, CallOpts);
429  break;
430  }
432  // Make sure we are not calling virtual base class initializers twice.
433  // Only the most-derived object should initialize virtual base classes.
434  const auto *OuterCtor = dyn_cast_or_null<CXXConstructExpr>(
435  LCtx->getStackFrame()->getCallSite());
436  assert(
437  (!OuterCtor ||
438  OuterCtor->getConstructionKind() == CXXConstructExpr::CK_Complete ||
439  OuterCtor->getConstructionKind() == CXXConstructExpr::CK_Delegating) &&
440  ("This virtual base should have already been initialized by "
441  "the most derived class!"));
442  (void)OuterCtor;
443  LLVM_FALLTHROUGH;
444  }
446  // In C++17, classes with non-virtual bases may be aggregates, so they would
447  // be initialized as aggregates without a constructor call, so we may have
448  // a base class constructed directly into an initializer list without
449  // having the derived-class constructor call on the previous stack frame.
450  // Initializer lists may be nested into more initializer lists that
451  // correspond to surrounding aggregate initializations.
452  // FIXME: For now this code essentially bails out. We need to find the
453  // correct target region and set it.
454  // FIXME: Instead of relying on the ParentMap, we should have the
455  // trigger-statement (InitListExpr in this case) passed down from CFG or
456  // otherwise always available during construction.
457  if (dyn_cast_or_null<InitListExpr>(LCtx->getParentMap().getParent(CE))) {
459  Target = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(CE, LCtx));
461  break;
462  }
463  LLVM_FALLTHROUGH;
465  const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl());
466  Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor,
467  LCtx->getStackFrame());
468  SVal ThisVal = State->getSVal(ThisPtr);
469 
471  Target = ThisVal;
472  } else {
473  // Cast to the base type.
474  bool IsVirtual =
476  SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, CE->getType(),
477  IsVirtual);
478  Target = BaseVal;
479  }
480  break;
481  }
482  }
483 
484  if (State != Pred->getState()) {
485  static SimpleProgramPointTag T("ExprEngine",
486  "Prepare for object construction");
487  ExplodedNodeSet DstPrepare;
488  StmtNodeBuilder BldrPrepare(Pred, DstPrepare, *currBldrCtx);
489  BldrPrepare.generateNode(CE, Pred, State, &T, ProgramPoint::PreStmtKind);
490  assert(DstPrepare.size() <= 1);
491  if (DstPrepare.size() == 0)
492  return;
493  Pred = *BldrPrepare.begin();
494  }
495 
498  CEMgr.getCXXConstructorCall(CE, Target.getAsRegion(), State, LCtx);
499 
500  ExplodedNodeSet DstPreVisit;
501  getCheckerManager().runCheckersForPreStmt(DstPreVisit, Pred, CE, *this);
502 
503  // FIXME: Is it possible and/or useful to do this before PreStmt?
504  ExplodedNodeSet PreInitialized;
505  {
506  StmtNodeBuilder Bldr(DstPreVisit, PreInitialized, *currBldrCtx);
507  for (ExplodedNodeSet::iterator I = DstPreVisit.begin(),
508  E = DstPreVisit.end();
509  I != E; ++I) {
510  ProgramStateRef State = (*I)->getState();
511  if (CE->requiresZeroInitialization()) {
512  // FIXME: Once we properly handle constructors in new-expressions, we'll
513  // need to invalidate the region before setting a default value, to make
514  // sure there aren't any lingering bindings around. This probably needs
515  // to happen regardless of whether or not the object is zero-initialized
516  // to handle random fields of a placement-initialized object picking up
517  // old bindings. We might only want to do it when we need to, though.
518  // FIXME: This isn't actually correct for arrays -- we need to zero-
519  // initialize the entire array, not just the first element -- but our
520  // handling of arrays everywhere else is weak as well, so this shouldn't
521  // actually make things worse. Placement new makes this tricky as well,
522  // since it's then possible to be initializing one part of a multi-
523  // dimensional array.
524  State = State->bindDefaultZero(Target, LCtx);
525  }
526 
527  Bldr.generateNode(CE, *I, State, /*tag=*/nullptr,
529  }
530  }
531 
532  ExplodedNodeSet DstPreCall;
533  getCheckerManager().runCheckersForPreCall(DstPreCall, PreInitialized,
534  *Call, *this);
535 
536  ExplodedNodeSet DstEvaluated;
537  StmtNodeBuilder Bldr(DstPreCall, DstEvaluated, *currBldrCtx);
538 
539  if (CE->getConstructor()->isTrivial() &&
541  !CallOpts.IsArrayCtorOrDtor) {
542  // FIXME: Handle other kinds of trivial constructors as well.
543  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
544  I != E; ++I)
545  performTrivialCopy(Bldr, *I, *Call);
546 
547  } else {
548  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
549  I != E; ++I)
550  defaultEvalCall(Bldr, *I, *Call, CallOpts);
551  }
552 
553  // If the CFG was constructed without elements for temporary destructors
554  // and the just-called constructor created a temporary object then
555  // stop exploration if the temporary object has a noreturn constructor.
556  // This can lose coverage because the destructor, if it were present
557  // in the CFG, would be called at the end of the full expression or
558  // later (for life-time extended temporaries) -- but avoids infeasible
559  // paths when no-return temporary destructors are used for assertions.
560  const AnalysisDeclContext *ADC = LCtx->getAnalysisDeclContext();
562  const MemRegion *Target = Call->getCXXThisVal().getAsRegion();
563  if (Target && isa<CXXTempObjectRegion>(Target) &&
564  Call->getDecl()->getParent()->isAnyDestructorNoReturn()) {
565 
566  // If we've inlined the constructor, then DstEvaluated would be empty.
567  // In this case we still want a sink, which could be implemented
568  // in processCallExit. But we don't have that implemented at the moment,
569  // so if you hit this assertion, see if you can avoid inlining
570  // the respective constructor when analyzer-config cfg-temporary-dtors
571  // is set to false.
572  // Otherwise there's nothing wrong with inlining such constructor.
573  assert(!DstEvaluated.empty() &&
574  "We should not have inlined this constructor!");
575 
576  for (ExplodedNode *N : DstEvaluated) {
577  Bldr.generateSink(CE, N, N->getState());
578  }
579 
580  // There is no need to run the PostCall and PostStmt checker
581  // callbacks because we just generated sinks on all nodes in th
582  // frontier.
583  return;
584  }
585  }
586 
587  ExplodedNodeSet DstPostArgumentCleanup;
588  for (auto I : DstEvaluated)
589  finishArgumentConstruction(DstPostArgumentCleanup, I, *Call);
590 
591  // If there were other constructors called for object-type arguments
592  // of this constructor, clean them up.
593  ExplodedNodeSet DstPostCall;
595  DstPostArgumentCleanup,
596  *Call, *this);
597  getCheckerManager().runCheckersForPostStmt(destNodes, DstPostCall, CE, *this);
598 }
599 
601  const MemRegion *Dest,
602  const Stmt *S,
603  bool IsBaseDtor,
604  ExplodedNode *Pred,
605  ExplodedNodeSet &Dst,
606  const EvalCallOptions &CallOpts) {
607  assert(S && "A destructor without a trigger!");
608  const LocationContext *LCtx = Pred->getLocationContext();
609  ProgramStateRef State = Pred->getState();
610 
611  const CXXRecordDecl *RecordDecl = ObjectType->getAsCXXRecordDecl();
612  assert(RecordDecl && "Only CXXRecordDecls should have destructors");
613  const CXXDestructorDecl *DtorDecl = RecordDecl->getDestructor();
614 
615  // FIXME: There should always be a Decl, otherwise the destructor call
616  // shouldn't have been added to the CFG in the first place.
617  if (!DtorDecl) {
618  // Skip the invalid destructor. We cannot simply return because
619  // it would interrupt the analysis instead.
620  static SimpleProgramPointTag T("ExprEngine", "SkipInvalidDestructor");
621  // FIXME: PostImplicitCall with a null decl may crash elsewhere anyway.
622  PostImplicitCall PP(/*Decl=*/nullptr, S->getEndLoc(), LCtx, &T);
623  NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
624  Bldr.generateNode(PP, Pred->getState(), Pred);
625  return;
626  }
627 
630  CEMgr.getCXXDestructorCall(DtorDecl, S, Dest, IsBaseDtor, State, LCtx);
631 
632  PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
633  Call->getSourceRange().getBegin(),
634  "Error evaluating destructor");
635 
636  ExplodedNodeSet DstPreCall;
637  getCheckerManager().runCheckersForPreCall(DstPreCall, Pred,
638  *Call, *this);
639 
640  ExplodedNodeSet DstInvalidated;
641  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
642  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
643  I != E; ++I)
644  defaultEvalCall(Bldr, *I, *Call, CallOpts);
645 
646  getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
647  *Call, *this);
648 }
649 
651  ExplodedNode *Pred,
652  ExplodedNodeSet &Dst) {
653  ProgramStateRef State = Pred->getState();
654  const LocationContext *LCtx = Pred->getLocationContext();
655  PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
656  CNE->getBeginLoc(),
657  "Error evaluating New Allocator Call");
660  CEMgr.getCXXAllocatorCall(CNE, State, LCtx);
661 
662  ExplodedNodeSet DstPreCall;
663  getCheckerManager().runCheckersForPreCall(DstPreCall, Pred,
664  *Call, *this);
665 
666  ExplodedNodeSet DstPostCall;
667  StmtNodeBuilder CallBldr(DstPreCall, DstPostCall, *currBldrCtx);
668  for (auto I : DstPreCall) {
669  // FIXME: Provide evalCall for checkers?
670  defaultEvalCall(CallBldr, I, *Call);
671  }
672  // If the call is inlined, DstPostCall will be empty and we bail out now.
673 
674  // Store return value of operator new() for future use, until the actual
675  // CXXNewExpr gets processed.
676  ExplodedNodeSet DstPostValue;
677  StmtNodeBuilder ValueBldr(DstPostCall, DstPostValue, *currBldrCtx);
678  for (auto I : DstPostCall) {
679  // FIXME: Because CNE serves as the "call site" for the allocator (due to
680  // lack of a better expression in the AST), the conjured return value symbol
681  // is going to be of the same type (C++ object pointer type). Technically
682  // this is not correct because the operator new's prototype always says that
683  // it returns a 'void *'. So we should change the type of the symbol,
684  // and then evaluate the cast over the symbolic pointer from 'void *' to
685  // the object pointer type. But without changing the symbol's type it
686  // is breaking too much to evaluate the no-op symbolic cast over it, so we
687  // skip it for now.
688  ProgramStateRef State = I->getState();
689  SVal RetVal = State->getSVal(CNE, LCtx);
690 
691  // If this allocation function is not declared as non-throwing, failures
692  // /must/ be signalled by exceptions, and thus the return value will never
693  // be NULL. -fno-exceptions does not influence this semantics.
694  // FIXME: GCC has a -fcheck-new option, which forces it to consider the case
695  // where new can return NULL. If we end up supporting that option, we can
696  // consider adding a check for it here.
697  // C++11 [basic.stc.dynamic.allocation]p3.
698  if (const FunctionDecl *FD = CNE->getOperatorNew()) {
699  QualType Ty = FD->getType();
700  if (const auto *ProtoType = Ty->getAs<FunctionProtoType>())
701  if (!ProtoType->isNothrow())
702  State = State->assume(RetVal.castAs<DefinedOrUnknownSVal>(), true);
703  }
704 
705  ValueBldr.generateNode(
706  CNE, I, addObjectUnderConstruction(State, CNE, LCtx, RetVal));
707  }
708 
709  ExplodedNodeSet DstPostPostCallCallback;
710  getCheckerManager().runCheckersForPostCall(DstPostPostCallCallback,
711  DstPostValue, *Call, *this);
712  for (auto I : DstPostPostCallCallback) {
714  CNE, *getObjectUnderConstruction(I->getState(), CNE, LCtx), Dst, I,
715  *this);
716  }
717 }
718 
720  ExplodedNodeSet &Dst) {
721  // FIXME: Much of this should eventually migrate to CXXAllocatorCall.
722  // Also, we need to decide how allocators actually work -- they're not
723  // really part of the CXXNewExpr because they happen BEFORE the
724  // CXXConstructExpr subexpression. See PR12014 for some discussion.
725 
726  unsigned blockCount = currBldrCtx->blockCount();
727  const LocationContext *LCtx = Pred->getLocationContext();
728  SVal symVal = UnknownVal();
729  FunctionDecl *FD = CNE->getOperatorNew();
730 
731  bool IsStandardGlobalOpNewFunction =
733 
734  ProgramStateRef State = Pred->getState();
735 
736  // Retrieve the stored operator new() return value.
737  if (AMgr.getAnalyzerOptions().MayInlineCXXAllocator) {
738  symVal = *getObjectUnderConstruction(State, CNE, LCtx);
739  State = finishObjectConstruction(State, CNE, LCtx);
740  }
741 
742  // We assume all standard global 'operator new' functions allocate memory in
743  // heap. We realize this is an approximation that might not correctly model
744  // a custom global allocator.
745  if (symVal.isUnknown()) {
746  if (IsStandardGlobalOpNewFunction)
747  symVal = svalBuilder.getConjuredHeapSymbolVal(CNE, LCtx, blockCount);
748  else
749  symVal = svalBuilder.conjureSymbolVal(nullptr, CNE, LCtx, CNE->getType(),
750  blockCount);
751  }
752 
755  CEMgr.getCXXAllocatorCall(CNE, State, LCtx);
756 
757  if (!AMgr.getAnalyzerOptions().MayInlineCXXAllocator) {
758  // Invalidate placement args.
759  // FIXME: Once we figure out how we want allocators to work,
760  // we should be using the usual pre-/(default-)eval-/post-call checks here.
761  State = Call->invalidateRegions(blockCount);
762  if (!State)
763  return;
764 
765  // If this allocation function is not declared as non-throwing, failures
766  // /must/ be signalled by exceptions, and thus the return value will never
767  // be NULL. -fno-exceptions does not influence this semantics.
768  // FIXME: GCC has a -fcheck-new option, which forces it to consider the case
769  // where new can return NULL. If we end up supporting that option, we can
770  // consider adding a check for it here.
771  // C++11 [basic.stc.dynamic.allocation]p3.
772  if (FD) {
773  QualType Ty = FD->getType();
774  if (const auto *ProtoType = Ty->getAs<FunctionProtoType>())
775  if (!ProtoType->isNothrow())
776  if (auto dSymVal = symVal.getAs<DefinedOrUnknownSVal>())
777  State = State->assume(*dSymVal, true);
778  }
779  }
780 
781  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
782 
783  SVal Result = symVal;
784 
785  if (CNE->isArray()) {
786  // FIXME: allocating an array requires simulating the constructors.
787  // For now, just return a symbolicated region.
788  if (const SubRegion *NewReg =
789  dyn_cast_or_null<SubRegion>(symVal.getAsRegion())) {
790  QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType();
791  const ElementRegion *EleReg =
792  getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
793  Result = loc::MemRegionVal(EleReg);
794  }
795  State = State->BindExpr(CNE, Pred->getLocationContext(), Result);
796  Bldr.generateNode(CNE, Pred, State);
797  return;
798  }
799 
800  // FIXME: Once we have proper support for CXXConstructExprs inside
801  // CXXNewExpr, we need to make sure that the constructed object is not
802  // immediately invalidated here. (The placement call should happen before
803  // the constructor call anyway.)
804  if (FD && FD->isReservedGlobalPlacementOperator()) {
805  // Non-array placement new should always return the placement location.
806  SVal PlacementLoc = State->getSVal(CNE->getPlacementArg(0), LCtx);
807  Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(),
808  CNE->getPlacementArg(0)->getType());
809  }
810 
811  // Bind the address of the object, then check to see if we cached out.
812  State = State->BindExpr(CNE, LCtx, Result);
813  ExplodedNode *NewN = Bldr.generateNode(CNE, Pred, State);
814  if (!NewN)
815  return;
816 
817  // If the type is not a record, we won't have a CXXConstructExpr as an
818  // initializer. Copy the value over.
819  if (const Expr *Init = CNE->getInitializer()) {
820  if (!isa<CXXConstructExpr>(Init)) {
821  assert(Bldr.getResults().size() == 1);
822  Bldr.takeNodes(NewN);
823  evalBind(Dst, CNE, NewN, Result, State->getSVal(Init, LCtx),
824  /*FirstInit=*/IsStandardGlobalOpNewFunction);
825  }
826  }
827 }
828 
830  ExplodedNode *Pred, ExplodedNodeSet &Dst) {
831  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
832  ProgramStateRef state = Pred->getState();
833  Bldr.generateNode(CDE, Pred, state);
834 }
835 
837  ExplodedNode *Pred,
838  ExplodedNodeSet &Dst) {
839  const VarDecl *VD = CS->getExceptionDecl();
840  if (!VD) {
841  Dst.Add(Pred);
842  return;
843  }
844 
845  const LocationContext *LCtx = Pred->getLocationContext();
846  SVal V = svalBuilder.conjureSymbolVal(CS, LCtx, VD->getType(),
847  currBldrCtx->blockCount());
848  ProgramStateRef state = Pred->getState();
849  state = state->bindLoc(state->getLValue(VD, LCtx), V, LCtx);
850 
851  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
852  Bldr.generateNode(CS, Pred, state);
853 }
854 
856  ExplodedNodeSet &Dst) {
857  StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
858 
859  // Get the this object region from StoreManager.
860  const LocationContext *LCtx = Pred->getLocationContext();
861  const MemRegion *R =
862  svalBuilder.getRegionManager().getCXXThisRegion(
863  getContext().getCanonicalType(TE->getType()),
864  LCtx);
865 
866  ProgramStateRef state = Pred->getState();
867  SVal V = state->getSVal(loc::MemRegionVal(R));
868  Bldr.generateNode(TE, Pred, state->BindExpr(TE, LCtx, V));
869 }
870 
872  ExplodedNodeSet &Dst) {
873  const LocationContext *LocCtxt = Pred->getLocationContext();
874 
875  // Get the region of the lambda itself.
876  const MemRegion *R = svalBuilder.getRegionManager().getCXXTempObjectRegion(
877  LE, LocCtxt);
878  SVal V = loc::MemRegionVal(R);
879 
880  ProgramStateRef State = Pred->getState();
881 
882  // If we created a new MemRegion for the lambda, we should explicitly bind
883  // the captures.
886  e = LE->capture_init_end();
887  i != e; ++i, ++CurField) {
888  FieldDecl *FieldForCapture = *CurField;
889  SVal FieldLoc = State->getLValue(FieldForCapture, V);
890 
891  SVal InitVal;
892  if (!FieldForCapture->hasCapturedVLAType()) {
893  Expr *InitExpr = *i;
894  assert(InitExpr && "Capture missing initialization expression");
895  InitVal = State->getSVal(InitExpr, LocCtxt);
896  } else {
897  // The field stores the length of a captured variable-length array.
898  // These captures don't have initialization expressions; instead we
899  // get the length from the VLAType size expression.
900  Expr *SizeExpr = FieldForCapture->getCapturedVLAType()->getSizeExpr();
901  InitVal = State->getSVal(SizeExpr, LocCtxt);
902  }
903 
904  State = State->bindLoc(FieldLoc, InitVal, LocCtxt);
905  }
906 
907  // Decay the Loc into an RValue, because there might be a
908  // MaterializeTemporaryExpr node above this one which expects the bound value
909  // to be an RValue.
910  SVal LambdaRVal = State->getSVal(R);
911 
912  ExplodedNodeSet Tmp;
913  StmtNodeBuilder Bldr(Pred, Tmp, *currBldrCtx);
914  // FIXME: is this the right program point kind?
915  Bldr.generateNode(LE, Pred,
916  State->BindExpr(LE, LocCtxt, LambdaRVal),
918 
919  // FIXME: Move all post/pre visits to ::Visit().
920  getCheckerManager().runCheckersForPostStmt(Dst, Tmp, LE, *this);
921 }
bool hasCapturedVLAType() const
Determine whether this member captures the variable length array type.
Definition: Decl.h:2780
Represents a function declaration or definition.
Definition: Decl.h:1748
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
Definition: Decl.cpp:2872
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:2569
A (possibly-)qualified type.
Definition: Type.h:643
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:94
Static storage duration.
Definition: Specifiers.h:309
bool IsTemporaryCtorOrDtor
This call is a constructor or a destructor of a temporary value.
Definition: ExprEngine.h:106
unsigned blockCount() const
Returns the number of times the current basic block has been visited on the exploded graph path...
Definition: CoreEngine.h:220
Stmt - This represents one statement.
Definition: Stmt.h:66
This builder class is useful for generating nodes that resulted from visiting a statement.
Definition: CoreEngine.h:378
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
FunctionDecl * getOperatorNew() const
Definition: ExprCXX.h:2119
Manages the lifetime of CallEvent objects.
Definition: CallEvent.h:1133
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called...
Definition: ExprCXX.h:1437
CallEventRef< CXXDestructorCall > getCXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBase, ProgramStateRef State, const LocationContext *LCtx)
Definition: CallEvent.h:1214
Stmt * getParent(Stmt *) const
Definition: ParentMap.cpp:134
Hints for figuring out of a call should be inlined during evalCall().
Definition: ExprEngine.h:96
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2844
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1326
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:103
CallEventRef getSimpleCall(const CallExpr *E, ProgramStateRef State, const LocationContext *LCtx)
Definition: CallEvent.cpp:1355
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:4320
const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:222
void takeNodes(const ExplodedNodeSet &S)
Definition: CoreEngine.h:329
Represents a variable declaration or definition.
Definition: Decl.h:812
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6851
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:474
const ElementRegion * GetElementZeroRegion(const SubRegion *R, QualType T)
Definition: Store.cpp:67
long i
Definition: xmmintrin.h:1456
void VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition: ExprCXX.cpp:1199
Represents a function call that returns a C++ object by value.
Definition: CFG.h:178
Represents a struct/union/class.
Definition: Decl.h:3626
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Definition: DeclCXX.h:1332
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
Definition: ExprCXX.h:4361
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:2607
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:2895
ExplodedNode * generateSink(const Stmt *S, ExplodedNode *Pred, ProgramStateRef St, const ProgramPointTag *tag=nullptr, ProgramPoint::Kind K=ProgramPoint::PostStmtKind)
Definition: CoreEngine.h:417
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:659
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
Definition: ExprCXX.h:1867
Expr * getInitializer()
The initializer of this new-expression.
Definition: ExprCXX.h:2176
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:3023
field_iterator field_begin() const
Definition: Decl.cpp:4300
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1277
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1722
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:1735
static bool isVariadic(const Decl *D)
Returns true if the given decl is known to be variadic.
Definition: CallEvent.cpp:487
Represents the this expression in C++.
Definition: ExprCXX.h:1001
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:190
const ValueDecl * getExtendingDecl() const
Get the declaration which triggered the lifetime-extension of this temporary, if any.
Definition: ExprCXX.h:4383
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:1636
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3719
const Stmt * getCallSite() const
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1398
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:108
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Definition: DeclCXX.cpp:2464
void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCXXNewAllocatorCall(const CXXNewExpr *CNE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
#define V(N, I)
Definition: ASTContext.h:2907
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2830
AnalyzerOptions & getAnalyzerOptions() override
VarDecl * getExceptionDecl() const
Definition: StmtCXX.h:49
This is the simplest builder which generates nodes in the ExplodedGraph.
Definition: CoreEngine.h:236
Represents C++ constructor call.
Definition: CFG.h:150
void Add(ExplodedNode *N)
const ExplodedNodeSet & getResults()
Definition: CoreEngine.h:306
QualType getType() const
Definition: Expr.h:137
virtual const Decl * getDecl() const
Returns the declaration of the function or method that will be called.
Definition: CallEvent.h:202
ASTContext & getContext() const
getContext - Return the ASTContext associated with this analysis.
Definition: ExprEngine.h:182
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1779
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Definition: ExprCXX.h:4364
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2040
CallEventRef< ObjCMethodCall > getObjCMethodCall(const ObjCMessageExpr *E, ProgramStateRef State, const LocationContext *LCtx)
Definition: CallEvent.h:1202
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:276
Thread storage duration.
Definition: Specifiers.h:308
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:1221
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:151
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Definition: ExprCXX.h:2000
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:2240
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition: Decl.h:2785
CallEventManager & getCallEventManager()
Definition: ProgramState.h:526
const CXXTempObjectRegion * getCXXTempObjectRegion(Expr const *Ex, LocationContext const *LC)
Definition: MemRegion.cpp:1044
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2114
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:99
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:2124
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:1100
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:194
Represents a delete expression for memory deallocation and destructor calls, e.g. ...
Definition: ExprCXX.h:2260
StoreManager & getStoreManager()
Definition: ExprEngine.h:386
Represents a program point just after an implicit call event.
Definition: ProgramPoint.h:600
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:138
Expr * getPlacementArg(unsigned I)
Definition: ExprCXX.h:2146
ProgramStateManager & getStateManager() override
Definition: ExprEngine.h:384
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:2048
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:967
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:1208
ExplodedNode * generateNode(const ProgramPoint &PP, ProgramStateRef State, ExplodedNode *Pred)
Generates a node in the ExplodedGraph.
Definition: CoreEngine.h:289
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++...
static bool isTrivial(ASTContext &Ctx, const Expr *E)
Checks if the expression is constant or does not have non-trivial function calls. ...
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
bool IsTemporaryLifetimeExtendedViaAggregate
This call is a constructor for a temporary that is lifetime-extended by binding it to a reference-typ...
Definition: ExprEngine.h:111
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:306
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2516
ExplodedNode * generateNode(const Stmt *S, ExplodedNode *Pred, ProgramStateRef St, const ProgramPointTag *tag=nullptr, ProgramPoint::Kind K=ProgramPoint::PostStmtKind)
Definition: CoreEngine.h:407
iterator begin()
Iterators through the results frontier.
Definition: CoreEngine.h:315
ElementRegion is used to represent both array elements and casts.
Definition: MemRegion.h:1082
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument for this lambda expression...
Definition: ExprCXX.h:1879
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
Definition: ExprCXX.h:1853
virtual SVal getArgSVal(unsigned Index) const
Returns the value of a given argument at the time of the call.
Definition: CallEvent.cpp:411
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:816
bool isUnknownOrUndef() const
Definition: SVals.h:144
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:2938
ConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1446