clang 19.0.0git
CallEvent.h
Go to the documentation of this file.
1//===- CallEvent.h - Wrapper for all function and method calls --*- 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/// \file This file defines CallEvent and its subclasses, which represent path-
10/// sensitive instances of different kinds of function and method calls
11/// (C, C++, and Objective-C).
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H
16#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H
17
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclBase.h"
20#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclObjC.h"
22#include "clang/AST/Expr.h"
23#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
25#include "clang/AST/Stmt.h"
26#include "clang/AST/Type.h"
28#include "clang/Basic/LLVM.h"
35#include "llvm/ADT/ArrayRef.h"
36#include "llvm/ADT/IntrusiveRefCntPtr.h"
37#include "llvm/ADT/PointerIntPair.h"
38#include "llvm/ADT/PointerUnion.h"
39#include "llvm/ADT/STLExtras.h"
40#include "llvm/ADT/SmallVector.h"
41#include "llvm/ADT/StringRef.h"
42#include "llvm/ADT/iterator_range.h"
43#include "llvm/Support/Allocator.h"
44#include "llvm/Support/Casting.h"
45#include "llvm/Support/ErrorHandling.h"
46#include <cassert>
47#include <limits>
48#include <optional>
49#include <utility>
50
51namespace clang {
52
53class LocationContext;
54class ProgramPoint;
55class ProgramPointTag;
56class StackFrameContext;
57
58namespace ento {
59
77};
78
79class CallEvent;
80
81template <typename T = CallEvent>
82class CallEventRef : public IntrusiveRefCntPtr<const T> {
83public:
84 CallEventRef(const T *Call) : IntrusiveRefCntPtr<const T>(Call) {}
85 CallEventRef(const CallEventRef &Orig) : IntrusiveRefCntPtr<const T>(Orig) {}
86
87 // The copy assignment operator is defined as deleted pending further
88 // motivation.
90
92 return this->get()->template cloneWithState<T>(State);
93 }
94
95 // Allow implicit conversions to a superclass type, since CallEventRef
96 // behaves like a pointer-to-const.
97 template <typename SuperT> operator CallEventRef<SuperT>() const {
98 return this->get();
99 }
100};
101
102/// \class RuntimeDefinition
103/// Defines the runtime definition of the called function.
104///
105/// Encapsulates the information we have about which Decl will be used
106/// when the call is executed on the given path. When dealing with dynamic
107/// dispatch, the information is based on DynamicTypeInfo and might not be
108/// precise.
110 /// The Declaration of the function which could be called at runtime.
111 /// NULL if not available.
112 const Decl *D = nullptr;
113
114 /// The region representing an object (ObjC/C++) on which the method is
115 /// called. With dynamic dispatch, the method definition depends on the
116 /// runtime type of this object. NULL when the DynamicTypeInfo is
117 /// precise.
118 const MemRegion *R = nullptr;
119
120 /// A definition is foreign if it has been imported and newly created by the
121 /// ASTImporter. This can be true only if CTU is enabled.
122 const bool Foreign = false;
123
124public:
125 RuntimeDefinition() = default;
126 RuntimeDefinition(const Decl *InD) : D(InD) {}
127 RuntimeDefinition(const Decl *InD, bool Foreign) : D(InD), Foreign(Foreign) {}
128 RuntimeDefinition(const Decl *InD, const MemRegion *InR) : D(InD), R(InR) {}
129
130 const Decl *getDecl() { return D; }
131 bool isForeign() const { return Foreign; }
132
133 /// Check if the definition we have is precise.
134 /// If not, it is possible that the call dispatches to another definition at
135 /// execution time.
136 bool mayHaveOtherDefinitions() { return R != nullptr; }
137
138 /// When other definitions are possible, returns the region whose runtime type
139 /// determines the method definition.
140 const MemRegion *getDispatchRegion() { return R; }
141};
142
143/// Represents an abstract call to a function or method along a
144/// particular path.
145///
146/// CallEvents are created through the factory methods of CallEventManager.
147///
148/// CallEvents should always be cheap to create and destroy. In order for
149/// CallEventManager to be able to re-use CallEvent-sized memory blocks,
150/// subclasses of CallEvent may not add any data members to the base class.
151/// Use the "Data" and "Location" fields instead.
153public:
155
156private:
157 ProgramStateRef State;
158 const LocationContext *LCtx;
159 llvm::PointerUnion<const Expr *, const Decl *> Origin;
160 CFGBlock::ConstCFGElementRef ElemRef = {nullptr, 0};
161 mutable std::optional<bool> Foreign; // Set by CTU analysis.
162
163protected:
164 // This is user data for subclasses.
165 const void *Data;
166
167 // This is user data for subclasses.
168 // This should come right before RefCount, so that the two fields can be
169 // packed together on LP64 platforms.
171
172private:
173 template <typename T> friend struct llvm::IntrusiveRefCntPtrInfo;
174
175 mutable unsigned RefCount = 0;
176
177 void Retain() const { ++RefCount; }
178 void Release() const;
179
180protected:
181 friend class CallEventManager;
182
183 CallEvent(const Expr *E, ProgramStateRef state, const LocationContext *lctx,
185 : State(std::move(state)), LCtx(lctx), Origin(E), ElemRef(ElemRef) {}
186
187 CallEvent(const Decl *D, ProgramStateRef state, const LocationContext *lctx,
189 : State(std::move(state)), LCtx(lctx), Origin(D), ElemRef(ElemRef) {}
190
191 // DO NOT MAKE PUBLIC
192 CallEvent(const CallEvent &Original)
193 : State(Original.State), LCtx(Original.LCtx), Origin(Original.Origin),
194 ElemRef(Original.ElemRef), Data(Original.Data),
195 Location(Original.Location) {}
196
197 /// Copies this CallEvent, with vtable intact, into a new block of memory.
198 virtual void cloneTo(void *Dest) const = 0;
199
200 /// Get the value of arbitrary expressions at this point in the path.
201 SVal getSVal(const Stmt *S) const {
202 return getState()->getSVal(S, getLocationContext());
203 }
204
206
207 /// Used to specify non-argument regions that will be invalidated as a
208 /// result of this call.
209 virtual void
211 RegionAndSymbolInvalidationTraits *ETraits) const {}
212
213public:
214 CallEvent &operator=(const CallEvent &) = delete;
215 virtual ~CallEvent() = default;
216
217 /// Returns the kind of call this is.
218 virtual Kind getKind() const = 0;
219 virtual StringRef getKindAsString() const = 0;
220
221 /// Returns the declaration of the function or method that will be
222 /// called. May be null.
223 virtual const Decl *getDecl() const {
224 return Origin.dyn_cast<const Decl *>();
225 }
226
227 bool isForeign() const {
228 assert(Foreign && "Foreign must be set before querying");
229 return *Foreign;
230 }
231 void setForeign(bool B) const { Foreign = B; }
232
233 /// The state in which the call is being evaluated.
234 const ProgramStateRef &getState() const { return State; }
235
236 /// The context in which the call is being evaluated.
237 const LocationContext *getLocationContext() const { return LCtx; }
238
240 return ElemRef;
241 }
242
243 /// Returns the definition of the function or method that will be
244 /// called.
246
247 /// Returns the expression whose value will be the result of this call.
248 /// May be null.
249 virtual const Expr *getOriginExpr() const {
250 return Origin.dyn_cast<const Expr *>();
251 }
252
253 /// Returns the number of arguments (explicit and implicit).
254 ///
255 /// Note that this may be greater than the number of parameters in the
256 /// callee's declaration, and that it may include arguments not written in
257 /// the source.
258 virtual unsigned getNumArgs() const = 0;
259
260 /// Returns true if the callee is known to be from a system header.
261 bool isInSystemHeader() const {
262 const Decl *D = getDecl();
263 if (!D)
264 return false;
265
267 if (Loc.isValid()) {
268 const SourceManager &SM =
269 getState()->getStateManager().getContext().getSourceManager();
270 return SM.isInSystemHeader(D->getLocation());
271 }
272
273 // Special case for implicitly-declared global operator new/delete.
274 // These should be considered system functions.
275 if (const auto *FD = dyn_cast<FunctionDecl>(D))
276 return FD->isOverloadedOperator() && FD->isImplicit() && FD->isGlobal();
277
278 return false;
279 }
280
281 /// Returns a source range for the entire call, suitable for
282 /// outputting in diagnostics.
283 virtual SourceRange getSourceRange() const {
284 return getOriginExpr()->getSourceRange();
285 }
286
287 /// Returns the value of a given argument at the time of the call.
288 virtual SVal getArgSVal(unsigned Index) const;
289
290 /// Returns the expression associated with a given argument.
291 /// May be null if this expression does not appear in the source.
292 virtual const Expr *getArgExpr(unsigned Index) const { return nullptr; }
293
294 /// Returns the source range for errors associated with this argument.
295 ///
296 /// May be invalid if the argument is not written in the source.
297 virtual SourceRange getArgSourceRange(unsigned Index) const;
298
299 /// Returns the result type, adjusted for references.
300 QualType getResultType() const;
301
302 /// Returns the return value of the call.
303 ///
304 /// This should only be called if the CallEvent was created using a state in
305 /// which the return value has already been bound to the origin expression.
306 SVal getReturnValue() const;
307
308 /// Returns true if the type of any of the non-null arguments satisfies
309 /// the condition.
311
312 /// Returns true if any of the arguments appear to represent callbacks.
313 bool hasNonZeroCallbackArg() const;
314
315 /// Returns true if any of the arguments is void*.
316 bool hasVoidPointerToNonConstArg() const;
317
318 /// Returns true if any of the arguments are known to escape to long-
319 /// term storage, even if this method will not modify them.
320 // NOTE: The exact semantics of this are still being defined!
321 // We don't really want a list of hardcoded exceptions in the long run,
322 // but we don't want duplicated lists of known APIs in the short term either.
323 virtual bool argumentsMayEscape() const { return hasNonZeroCallbackArg(); }
324
325 /// Returns true if the callee is an externally-visible function in the
326 /// top-level namespace, such as \c malloc.
327 ///
328 /// You can use this call to determine that a particular function really is
329 /// a library function and not, say, a C++ member function with the same name.
330 ///
331 /// If a name is provided, the function must additionally match the given
332 /// name.
333 ///
334 /// Note that this deliberately excludes C++ library functions in the \c std
335 /// namespace, but will include C library functions accessed through the
336 /// \c std namespace. This also does not check if the function is declared
337 /// as 'extern "C"', or if it uses C++ name mangling.
338 // FIXME: Add a helper for checking namespaces.
339 // FIXME: Move this down to AnyFunctionCall once checkers have more
340 // precise callbacks.
341 bool isGlobalCFunction(StringRef SpecificName = StringRef()) const;
342
343 /// Returns the name of the callee, if its name is a simple identifier.
344 ///
345 /// Note that this will fail for Objective-C methods, blocks, and C++
346 /// overloaded operators. The former is named by a Selector rather than a
347 /// simple identifier, and the latter two do not have names.
348 // FIXME: Move this down to AnyFunctionCall once checkers have more
349 // precise callbacks.
351 const auto *ND = dyn_cast_or_null<NamedDecl>(getDecl());
352 if (!ND)
353 return nullptr;
354 return ND->getIdentifier();
355 }
356
357 /// Returns an appropriate ProgramPoint for this call.
358 ProgramPoint getProgramPoint(bool IsPreVisit = false,
359 const ProgramPointTag *Tag = nullptr) const;
360
361 /// Returns a new state with all argument regions invalidated.
362 ///
363 /// This accepts an alternate state in case some processing has already
364 /// occurred.
365 ProgramStateRef invalidateRegions(unsigned BlockCount,
366 ProgramStateRef Orig = nullptr) const;
367
368 using FrameBindingTy = std::pair<SVal, SVal>;
370
371 /// Populates the given SmallVector with the bindings in the callee's stack
372 /// frame at the start of this call.
373 virtual void getInitialStackFrameContents(const StackFrameContext *CalleeCtx,
374 BindingsTy &Bindings) const = 0;
375
376 /// Returns a copy of this CallEvent, but using the given state.
377 template <typename T>
379
380 /// Returns a copy of this CallEvent, but using the given state.
382 return cloneWithState<CallEvent>(NewState);
383 }
384
385 /// Returns true if this is a statement is a function or method call
386 /// of some kind.
387 static bool isCallStmt(const Stmt *S);
388
389 /// Returns the result type of a function or method declaration.
390 ///
391 /// This will return a null QualType if the result type cannot be determined.
392 static QualType getDeclaredResultType(const Decl *D);
393
394 /// Returns true if the given decl is known to be variadic.
395 ///
396 /// \p D must not be null.
397 static bool isVariadic(const Decl *D);
398
399 /// Returns AnalysisDeclContext for the callee stack frame.
400 /// Currently may fail; returns null on failure.
402
403 /// Returns the callee stack frame. That stack frame will only be entered
404 /// during analysis if the call is inlined, but it may still be useful
405 /// in intermediate calculations even if the call isn't inlined.
406 /// May fail; returns null on failure.
407 const StackFrameContext *getCalleeStackFrame(unsigned BlockCount) const;
408
409 /// Returns memory location for a parameter variable within the callee stack
410 /// frame. The behavior is undefined if the block count is different from the
411 /// one that is there when call happens. May fail; returns null on failure.
412 const ParamVarRegion *getParameterLocation(unsigned Index,
413 unsigned BlockCount) const;
414
415 /// Returns true if on the current path, the argument was constructed by
416 /// calling a C++ constructor over it. This is an internal detail of the
417 /// analysis which doesn't necessarily represent the program semantics:
418 /// if we are supposed to construct an argument directly, we may still
419 /// not do that because we don't know how (i.e., construction context is
420 /// unavailable in the CFG or not supported by the analyzer).
421 bool isArgumentConstructedDirectly(unsigned Index) const {
422 // This assumes that the object was not yet removed from the state.
425 .has_value();
426 }
427
428 /// Some calls have parameter numbering mismatched from argument numbering.
429 /// This function converts an argument index to the corresponding
430 /// parameter index. Returns std::nullopt is the argument doesn't correspond
431 /// to any parameter variable.
432 virtual std::optional<unsigned>
433 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const {
434 return ASTArgumentIndex;
435 }
436
437 /// Some call event sub-classes conveniently adjust mismatching AST indices
438 /// to match parameter indices. This function converts an argument index
439 /// as understood by CallEvent to the argument index as understood by the AST.
440 virtual unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const {
441 return CallArgumentIndex;
442 }
443
444 /// Returns the construction context of the call, if it is a C++ constructor
445 /// call or a call of a function returning a C++ class instance. Otherwise
446 /// return nullptr.
448
449 /// If the call returns a C++ record type then the region of its return value
450 /// can be retrieved from its construction context.
451 std::optional<SVal> getReturnValueUnderConstruction() const;
452
453 // Returns the CallEvent representing the caller of this function
454 const CallEventRef<> getCaller() const;
455
456 // Returns true if the function was called from a standard library function.
457 // If not or could not get the caller (it may be a top level function)
458 // returns false.
459 bool isCalledFromSystemHeader() const;
460
461 // Iterator access to formal parameters and their types.
462private:
463 struct GetTypeFn {
464 QualType operator()(ParmVarDecl *PD) const { return PD->getType(); }
465 };
466
467public:
468 /// Return call's formal parameters.
469 ///
470 /// Remember that the number of formal parameters may not match the number
471 /// of arguments for all calls. However, the first parameter will always
472 /// correspond with the argument value returned by \c getArgSVal(0).
474
476 llvm::mapped_iterator<ArrayRef<ParmVarDecl *>::iterator, GetTypeFn>;
477
478 /// Returns an iterator over the types of the call's formal parameters.
479 ///
480 /// This uses the callee decl found by default name lookup rather than the
481 /// definition because it represents a public interface, and probably has
482 /// more annotations.
484 return llvm::map_iterator(parameters().begin(), GetTypeFn());
485 }
486 /// \sa param_type_begin()
488 return llvm::map_iterator(parameters().end(), GetTypeFn());
489 }
490
491 // For debugging purposes only
492 void dump(raw_ostream &Out) const;
493 void dump() const;
494};
495
496/// Represents a call to any sort of function that might have a
497/// FunctionDecl.
499protected:
501 const LocationContext *LCtx,
503 : CallEvent(E, St, LCtx, ElemRef) {}
505 const LocationContext *LCtx,
507 : CallEvent(D, St, LCtx, ElemRef) {}
509
510public:
511 // This function is overridden by subclasses, but they must return
512 // a FunctionDecl.
513 const FunctionDecl *getDecl() const override {
514 return cast<FunctionDecl>(CallEvent::getDecl());
515 }
516
518
519 bool argumentsMayEscape() const override;
520
522 BindingsTy &Bindings) const override;
523
524 ArrayRef<ParmVarDecl *> parameters() const override;
525
526 static bool classof(const CallEvent *CA) {
527 return CA->getKind() >= CE_BEG_FUNCTION_CALLS &&
529 }
530};
531
532/// Represents a C function or static C++ member function call.
533///
534/// Example: \c fun()
536 friend class CallEventManager;
537
538protected:
540 const LocationContext *LCtx,
542 : AnyFunctionCall(CE, St, LCtx, ElemRef) {}
544
545 void cloneTo(void *Dest) const override {
546 new (Dest) SimpleFunctionCall(*this);
547 }
548
549public:
550 const CallExpr *getOriginExpr() const override {
551 return cast<CallExpr>(AnyFunctionCall::getOriginExpr());
552 }
553
554 const FunctionDecl *getDecl() const override;
555
556 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
557
558 const Expr *getArgExpr(unsigned Index) const override {
559 return getOriginExpr()->getArg(Index);
560 }
561
562 Kind getKind() const override { return CE_Function; }
563 StringRef getKindAsString() const override { return "SimpleFunctionCall"; }
564
565 static bool classof(const CallEvent *CA) {
566 return CA->getKind() == CE_Function;
567 }
568};
569
570/// Represents a call to a block.
571///
572/// Example: <tt>^{ statement-body }()</tt>
573class BlockCall : public CallEvent {
574 friend class CallEventManager;
575
576protected:
579 : CallEvent(CE, St, LCtx, ElemRef) {}
580 BlockCall(const BlockCall &Other) = default;
581
582 void cloneTo(void *Dest) const override { new (Dest) BlockCall(*this); }
583
585 ValueList &Values,
586 RegionAndSymbolInvalidationTraits *ETraits) const override;
587
588public:
589 const CallExpr *getOriginExpr() const override {
590 return cast<CallExpr>(CallEvent::getOriginExpr());
591 }
592
593 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
594
595 const Expr *getArgExpr(unsigned Index) const override {
596 return getOriginExpr()->getArg(Index);
597 }
598
599 /// Returns the region associated with this instance of the block.
600 ///
601 /// This may be NULL if the block's origin is unknown.
602 const BlockDataRegion *getBlockRegion() const;
603
604 const BlockDecl *getDecl() const override {
605 const BlockDataRegion *BR = getBlockRegion();
606 if (!BR)
607 return nullptr;
608 return BR->getDecl();
609 }
610
612 const BlockDecl *BD = getDecl();
613 if (!BD)
614 return false;
615
616 return BD->isConversionFromLambda();
617 }
618
619 /// For a block converted from a C++ lambda, returns the block
620 /// VarRegion for the variable holding the captured C++ lambda record.
622 assert(isConversionFromLambda());
623 const BlockDataRegion *BR = getBlockRegion();
624 assert(BR && "Block converted from lambda must have a block region");
625
626 auto ReferencedVars = BR->referenced_vars();
627 assert(!ReferencedVars.empty());
628 return ReferencedVars.begin().getCapturedRegion();
629 }
630
633 return RuntimeDefinition(getDecl());
634
635 // Clang converts lambdas to blocks with an implicit user-defined
636 // conversion operator method on the lambda record that looks (roughly)
637 // like:
638 //
639 // typedef R(^block_type)(P1, P2, ...);
640 // operator block_type() const {
641 // auto Lambda = *this;
642 // return ^(P1 p1, P2 p2, ...){
643 // /* return Lambda(p1, p2, ...); */
644 // };
645 // }
646 //
647 // Here R is the return type of the lambda and P1, P2, ... are
648 // its parameter types. 'Lambda' is a fake VarDecl captured by the block
649 // that is initialized to a copy of the lambda.
650 //
651 // Sema leaves the body of a lambda-converted block empty (it is
652 // produced by CodeGen), so we can't analyze it directly. Instead, we skip
653 // the block body and analyze the operator() method on the captured lambda.
654 const VarDecl *LambdaVD = getRegionStoringCapturedLambda()->getDecl();
655 const CXXRecordDecl *LambdaDecl = LambdaVD->getType()->getAsCXXRecordDecl();
656 CXXMethodDecl *LambdaCallOperator = LambdaDecl->getLambdaCallOperator();
657
658 return RuntimeDefinition(LambdaCallOperator);
659 }
660
661 bool argumentsMayEscape() const override { return true; }
662
664 BindingsTy &Bindings) const override;
665
666 ArrayRef<ParmVarDecl *> parameters() const override;
667
668 Kind getKind() const override { return CE_Block; }
669 StringRef getKindAsString() const override { return "BlockCall"; }
670
671 static bool classof(const CallEvent *CA) { return CA->getKind() == CE_Block; }
672};
673
674/// Represents a non-static C++ member function call, no matter how
675/// it is written.
677protected:
679 const LocationContext *LCtx,
681 : AnyFunctionCall(CE, St, LCtx, ElemRef) {}
683 const LocationContext *LCtx,
685 : AnyFunctionCall(D, St, LCtx, ElemRef) {}
687
689 ValueList &Values,
690 RegionAndSymbolInvalidationTraits *ETraits) const override;
691
692public:
693 /// Returns the expression representing the implicit 'this' object.
694 virtual const Expr *getCXXThisExpr() const { return nullptr; }
695
696 /// Returns the value of the implicit 'this' object.
697 virtual SVal getCXXThisVal() const;
698
699 const FunctionDecl *getDecl() const override;
700
702
704 BindingsTy &Bindings) const override;
705
706 static bool classof(const CallEvent *CA) {
707 return CA->getKind() >= CE_BEG_CXX_INSTANCE_CALLS &&
709 }
710};
711
712/// Represents a non-static C++ member function call.
713///
714/// Example: \c obj.fun()
716 friend class CallEventManager;
717
718protected:
720 const LocationContext *LCtx,
722 : CXXInstanceCall(CE, St, LCtx, ElemRef) {}
724
725 void cloneTo(void *Dest) const override { new (Dest) CXXMemberCall(*this); }
726
727public:
728 const CXXMemberCallExpr *getOriginExpr() const override {
729 return cast<CXXMemberCallExpr>(CXXInstanceCall::getOriginExpr());
730 }
731
732 unsigned getNumArgs() const override {
733 if (const CallExpr *CE = getOriginExpr())
734 return CE->getNumArgs();
735 return 0;
736 }
737
738 const Expr *getArgExpr(unsigned Index) const override {
739 return getOriginExpr()->getArg(Index);
740 }
741
742 const Expr *getCXXThisExpr() const override;
743
745
746 Kind getKind() const override { return CE_CXXMember; }
747 StringRef getKindAsString() const override { return "CXXMemberCall"; }
748
749 static bool classof(const CallEvent *CA) {
750 return CA->getKind() == CE_CXXMember;
751 }
752};
753
754/// Represents a C++ overloaded operator call where the operator is
755/// implemented as a non-static member function.
756///
757/// Example: <tt>iter + 1</tt>
759 friend class CallEventManager;
760
761protected:
763 const LocationContext *LCtx,
765 : CXXInstanceCall(CE, St, LCtx, ElemRef) {}
767
768 void cloneTo(void *Dest) const override {
769 new (Dest) CXXMemberOperatorCall(*this);
770 }
771
772public:
773 const CXXOperatorCallExpr *getOriginExpr() const override {
774 return cast<CXXOperatorCallExpr>(CXXInstanceCall::getOriginExpr());
775 }
776
777 unsigned getNumArgs() const override {
778 return getOriginExpr()->getNumArgs() - 1;
779 }
780
781 const Expr *getArgExpr(unsigned Index) const override {
782 return getOriginExpr()->getArg(Index + 1);
783 }
784
785 const Expr *getCXXThisExpr() const override;
786
787 Kind getKind() const override { return CE_CXXMemberOperator; }
788 StringRef getKindAsString() const override { return "CXXMemberOperatorCall"; }
789
790 static bool classof(const CallEvent *CA) {
791 return CA->getKind() == CE_CXXMemberOperator;
792 }
793
794 std::optional<unsigned>
795 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override {
796 // For member operator calls argument 0 on the expression corresponds
797 // to implicit this-parameter on the declaration.
798 return (ASTArgumentIndex > 0)
799 ? std::optional<unsigned>(ASTArgumentIndex - 1)
800 : std::nullopt;
801 }
802
803 unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override {
804 // For member operator calls argument 0 on the expression corresponds
805 // to implicit this-parameter on the declaration.
806 return CallArgumentIndex + 1;
807 }
808
810 return getOriginExpr()->getOperator();
811 }
812};
813
814/// Represents an implicit call to a C++ destructor.
815///
816/// This can occur at the end of a scope (for automatic objects), at the end
817/// of a full-expression (for temporaries), or as part of a delete.
819 friend class CallEventManager;
820
821protected:
822 using DtorDataTy = llvm::PointerIntPair<const MemRegion *, 1, bool>;
823
824 /// Creates an implicit destructor.
825 ///
826 /// \param DD The destructor that will be called.
827 /// \param Trigger The statement whose completion causes this destructor call.
828 /// \param Target The object region to be destructed.
829 /// \param St The path-sensitive state at this point in the program.
830 /// \param LCtx The location context at this point in the program.
831 /// \param ElemRef The reference to this destructor in the CFG.
832 ///
833 /// FIXME: Eventually we want to drop \param Target and deduce it from
834 /// \param ElemRef. To do that we need to migrate the logic for target
835 /// region lookup from ExprEngine::ProcessImplicitDtor() and make it
836 /// independent from ExprEngine.
837 CXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger,
838 const MemRegion *Target, bool IsBaseDestructor,
839 ProgramStateRef St, const LocationContext *LCtx,
841 : CXXInstanceCall(DD, St, LCtx, ElemRef) {
842 Data = DtorDataTy(Target, IsBaseDestructor).getOpaqueValue();
843 Location = Trigger->getEndLoc();
844 }
845
847
848 void cloneTo(void *Dest) const override {
849 new (Dest) CXXDestructorCall(*this);
850 }
851
852public:
853 SourceRange getSourceRange() const override { return Location; }
854 unsigned getNumArgs() const override { return 0; }
855
857
858 /// Returns the value of the implicit 'this' object.
859 SVal getCXXThisVal() const override;
860
861 /// Returns true if this is a call to a base class destructor.
862 bool isBaseDestructor() const {
863 return DtorDataTy::getFromOpaqueValue(Data).getInt();
864 }
865
866 Kind getKind() const override { return CE_CXXDestructor; }
867 StringRef getKindAsString() const override { return "CXXDestructorCall"; }
868
869 static bool classof(const CallEvent *CA) {
870 return CA->getKind() == CE_CXXDestructor;
871 }
872};
873
874/// Represents any constructor invocation. This includes regular constructors
875/// and inherited constructors.
877protected:
879 ProgramStateRef St, const LocationContext *LCtx,
881 : AnyFunctionCall(E, St, LCtx, ElemRef) {
882 assert(E && (isa<CXXConstructExpr>(E) || isa<CXXInheritedCtorInitExpr>(E)));
883 // Target may be null when the region is unknown.
884 Data = Target;
885 }
886
888 ValueList &Values,
889 RegionAndSymbolInvalidationTraits *ETraits) const override;
890
892 BindingsTy &Bindings) const override;
893
894public:
895 /// Returns the value of the implicit 'this' object.
896 SVal getCXXThisVal() const;
897
898 static bool classof(const CallEvent *Call) {
899 return Call->getKind() >= CE_BEG_CXX_CONSTRUCTOR_CALLS &&
901 }
902};
903
904/// Represents a call to a C++ constructor.
905///
906/// Example: \c T(1)
908 friend class CallEventManager;
909
910protected:
911 /// Creates a constructor call.
912 ///
913 /// \param CE The constructor expression as written in the source.
914 /// \param Target The region where the object should be constructed. If NULL,
915 /// a new symbolic region will be used.
916 /// \param St The path-sensitive state at this point in the program.
917 /// \param LCtx The location context at this point in the program.
918 /// \param ElemRef The reference to this constructor in the CFG.
919 ///
920 /// FIXME: Eventually we want to drop \param Target and deduce it from
921 /// \param ElemRef.
923 ProgramStateRef St, const LocationContext *LCtx,
925 : AnyCXXConstructorCall(CE, Target, St, LCtx, ElemRef) {}
926
928
929 void cloneTo(void *Dest) const override {
930 new (Dest) CXXConstructorCall(*this);
931 }
932
933public:
934 const CXXConstructExpr *getOriginExpr() const override {
935 return cast<CXXConstructExpr>(AnyFunctionCall::getOriginExpr());
936 }
937
938 const CXXConstructorDecl *getDecl() const override {
939 return getOriginExpr()->getConstructor();
940 }
941
942 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
943
944 const Expr *getArgExpr(unsigned Index) const override {
945 return getOriginExpr()->getArg(Index);
946 }
947
948 Kind getKind() const override { return CE_CXXConstructor; }
949 StringRef getKindAsString() const override { return "CXXConstructorCall"; }
950
951 static bool classof(const CallEvent *CA) {
952 return CA->getKind() == CE_CXXConstructor;
953 }
954};
955
956/// Represents a call to a C++ inherited constructor.
957///
958/// Example: \c class T : public S { using S::S; }; T(1);
959///
960// Note, it is difficult to model the parameters. This is one of the reasons
961// why we skip analysis of inheriting constructors as top-level functions.
962// CXXInheritedCtorInitExpr doesn't take arguments and doesn't model parameter
963// initialization because there is none: the arguments in the outer
964// CXXConstructExpr directly initialize the parameters of the base class
965// constructor, and no copies are made. (Making a copy of the parameter is
966// incorrect, at least if it's done in an observable way.) The derived class
967// constructor doesn't even exist in the formal model.
968/// E.g., in:
969///
970/// struct X { X *p = this; ~X() {} };
971/// struct A { A(X x) : b(x.p == &x) {} bool b; };
972/// struct B : A { using A::A; };
973/// B b = X{};
974///
975/// ... b.b is initialized to true.
977 friend class CallEventManager;
978
979protected:
982 const LocationContext *LCtx,
984 : AnyCXXConstructorCall(CE, Target, St, LCtx, ElemRef) {}
985
987 default;
988
989 void cloneTo(void *Dest) const override {
990 new (Dest) CXXInheritedConstructorCall(*this);
991 }
992
993public:
994 const CXXInheritedCtorInitExpr *getOriginExpr() const override {
995 return cast<CXXInheritedCtorInitExpr>(AnyFunctionCall::getOriginExpr());
996 }
997
998 const CXXConstructorDecl *getDecl() const override {
999 return getOriginExpr()->getConstructor();
1000 }
1001
1002 /// Obtain the stack frame of the inheriting constructor. Argument expressions
1003 /// can be found on the call site of that stack frame.
1005
1006 /// Obtain the CXXConstructExpr for the sub-class that inherited the current
1007 /// constructor (possibly indirectly). It's the statement that contains
1008 /// argument expressions.
1010 return cast<CXXConstructExpr>(getInheritingStackFrame()->getCallSite());
1011 }
1012
1013 unsigned getNumArgs() const override {
1015 }
1016
1017 const Expr *getArgExpr(unsigned Index) const override {
1018 return getInheritingConstructor()->getArg(Index);
1019 }
1020
1021 SVal getArgSVal(unsigned Index) const override {
1022 return getState()->getSVal(
1023 getArgExpr(Index),
1024 getInheritingStackFrame()->getParent()->getStackFrame());
1025 }
1026
1027 Kind getKind() const override { return CE_CXXInheritedConstructor; }
1028 StringRef getKindAsString() const override {
1029 return "CXXInheritedConstructorCall";
1030 }
1031
1032 static bool classof(const CallEvent *CA) {
1033 return CA->getKind() == CE_CXXInheritedConstructor;
1034 }
1035};
1036
1037/// Represents the memory allocation call in a C++ new-expression.
1038///
1039/// This is a call to "operator new".
1041 friend class CallEventManager;
1042
1043protected:
1045 const LocationContext *LCtx,
1047 : AnyFunctionCall(E, St, LCtx, ElemRef) {}
1049
1050 void cloneTo(void *Dest) const override {
1051 new (Dest) CXXAllocatorCall(*this);
1052 }
1053
1054public:
1055 const CXXNewExpr *getOriginExpr() const override {
1056 return cast<CXXNewExpr>(AnyFunctionCall::getOriginExpr());
1057 }
1058
1059 const FunctionDecl *getDecl() const override {
1060 return getOriginExpr()->getOperatorNew();
1061 }
1062
1066 }
1067
1068 /// Number of non-placement arguments to the call. It is equal to 2 for
1069 /// C++17 aligned operator new() calls that have alignment implicitly
1070 /// passed as the second argument, and to 1 for other operator new() calls.
1071 unsigned getNumImplicitArgs() const {
1072 return getOriginExpr()->passAlignment() ? 2 : 1;
1073 }
1074
1075 unsigned getNumArgs() const override {
1077 }
1078
1079 bool isArray() const { return getOriginExpr()->isArray(); }
1080
1081 std::optional<const clang::Expr *> getArraySizeExpr() const {
1082 return getOriginExpr()->getArraySize();
1083 }
1084
1086 assert(isArray() && "The allocator call doesn't allocate and array!");
1087
1088 return getState()->getSVal(*getArraySizeExpr(), getLocationContext());
1089 }
1090
1091 const Expr *getArgExpr(unsigned Index) const override {
1092 // The first argument of an allocator call is the size of the allocation.
1093 if (Index < getNumImplicitArgs())
1094 return nullptr;
1096 }
1097
1098 /// Number of placement arguments to the operator new() call. For example,
1099 /// standard std::nothrow operator new and standard placement new both have
1100 /// 1 implicit argument (size) and 1 placement argument, while regular
1101 /// operator new() has 1 implicit argument and 0 placement arguments.
1102 const Expr *getPlacementArgExpr(unsigned Index) const {
1103 return getOriginExpr()->getPlacementArg(Index);
1104 }
1105
1106 Kind getKind() const override { return CE_CXXAllocator; }
1107 StringRef getKindAsString() const override { return "CXXAllocatorCall"; }
1108
1109 static bool classof(const CallEvent *CE) {
1110 return CE->getKind() == CE_CXXAllocator;
1111 }
1112};
1113
1114/// Represents the memory deallocation call in a C++ delete-expression.
1115///
1116/// This is a call to "operator delete".
1117// FIXME: CXXDeleteExpr isn't present for custom delete operators, or even for
1118// some those that are in the standard library, like the no-throw or align_val
1119// versions.
1120// Some pointers:
1121// http://lists.llvm.org/pipermail/cfe-dev/2020-April/065080.html
1122// clang/test/Analysis/cxx-dynamic-memory-analysis-order.cpp
1123// clang/unittests/StaticAnalyzer/CallEventTest.cpp
1125 friend class CallEventManager;
1126
1127protected:
1129 const LocationContext *LCtx,
1131 : AnyFunctionCall(E, St, LCtx, ElemRef) {}
1133
1134 void cloneTo(void *Dest) const override {
1135 new (Dest) CXXDeallocatorCall(*this);
1136 }
1137
1138public:
1139 const CXXDeleteExpr *getOriginExpr() const override {
1140 return cast<CXXDeleteExpr>(AnyFunctionCall::getOriginExpr());
1141 }
1142
1143 const FunctionDecl *getDecl() const override {
1144 return getOriginExpr()->getOperatorDelete();
1145 }
1146
1147 unsigned getNumArgs() const override { return getDecl()->getNumParams(); }
1148
1149 const Expr *getArgExpr(unsigned Index) const override {
1150 // CXXDeleteExpr's only have a single argument.
1151 return getOriginExpr()->getArgument();
1152 }
1153
1154 Kind getKind() const override { return CE_CXXDeallocator; }
1155 StringRef getKindAsString() const override { return "CXXDeallocatorCall"; }
1156
1157 static bool classof(const CallEvent *CE) {
1158 return CE->getKind() == CE_CXXDeallocator;
1159 }
1160};
1161
1162/// Represents the ways an Objective-C message send can occur.
1163//
1164// Note to maintainers: OCM_Message should always be last, since it does not
1165// need to fit in the Data field's low bits.
1167
1168/// Represents any expression that calls an Objective-C method.
1169///
1170/// This includes all of the kinds listed in ObjCMessageKind.
1172 friend class CallEventManager;
1173
1174 const PseudoObjectExpr *getContainingPseudoObjectExpr() const;
1175
1176protected:
1178 const LocationContext *LCtx,
1180 : CallEvent(Msg, St, LCtx, ElemRef) {
1181 Data = nullptr;
1182 }
1183
1185
1186 void cloneTo(void *Dest) const override { new (Dest) ObjCMethodCall(*this); }
1187
1189 ValueList &Values,
1190 RegionAndSymbolInvalidationTraits *ETraits) const override;
1191
1192 /// Check if the selector may have multiple definitions (may have overrides).
1193 virtual bool canBeOverridenInSubclass(ObjCInterfaceDecl *IDecl,
1194 Selector Sel) const;
1195
1196public:
1197 const ObjCMessageExpr *getOriginExpr() const override {
1198 return cast<ObjCMessageExpr>(CallEvent::getOriginExpr());
1199 }
1200
1201 const ObjCMethodDecl *getDecl() const override {
1202 return getOriginExpr()->getMethodDecl();
1203 }
1204
1205 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
1206
1207 const Expr *getArgExpr(unsigned Index) const override {
1208 return getOriginExpr()->getArg(Index);
1209 }
1210
1211 bool isInstanceMessage() const {
1212 return getOriginExpr()->isInstanceMessage();
1213 }
1214
1216 return getOriginExpr()->getMethodFamily();
1217 }
1218
1220
1221 SourceRange getSourceRange() const override;
1222
1223 /// Returns the value of the receiver at the time of this call.
1224 SVal getReceiverSVal() const;
1225
1226 /// Get the interface for the receiver.
1227 ///
1228 /// This works whether this is an instance message or a class message.
1229 /// However, it currently just uses the static type of the receiver.
1232 }
1233
1234 /// Checks if the receiver refers to 'self' or 'super'.
1235 bool isReceiverSelfOrSuper() const;
1236
1237 /// Returns how the message was written in the source (property access,
1238 /// subscript, or explicit message send).
1240
1241 /// Returns true if this property access or subscript is a setter (has the
1242 /// form of an assignment).
1243 bool isSetter() const {
1244 switch (getMessageKind()) {
1245 case OCM_Message:
1246 llvm_unreachable("This is not a pseudo-object access!");
1247 case OCM_PropertyAccess:
1248 return getNumArgs() > 0;
1249 case OCM_Subscript:
1250 return getNumArgs() > 1;
1251 }
1252 llvm_unreachable("Unknown message kind");
1253 }
1254
1255 // Returns the property accessed by this method, either explicitly via
1256 // property syntax or implicitly via a getter or setter method. Returns
1257 // nullptr if the call is not a prooperty access.
1259
1260 RuntimeDefinition getRuntimeDefinition() const override;
1261
1262 bool argumentsMayEscape() const override;
1263
1264 void getInitialStackFrameContents(const StackFrameContext *CalleeCtx,
1265 BindingsTy &Bindings) const override;
1266
1267 ArrayRef<ParmVarDecl *> parameters() const override;
1268
1269 Kind getKind() const override { return CE_ObjCMessage; }
1270 StringRef getKindAsString() const override { return "ObjCMethodCall"; }
1271
1272 static bool classof(const CallEvent *CA) {
1273 return CA->getKind() == CE_ObjCMessage;
1274 }
1275};
1276
1277/// Manages the lifetime of CallEvent objects.
1278///
1279/// CallEventManager provides a way to create arbitrary CallEvents "on the
1280/// stack" as if they were value objects by keeping a cache of CallEvent-sized
1281/// memory blocks. The CallEvents created by CallEventManager are only valid
1282/// for the lifetime of the OwnedCallEvent that holds them; right now these
1283/// objects cannot be copied and ownership cannot be transferred.
1285 friend class CallEvent;
1286
1287 llvm::BumpPtrAllocator &Alloc;
1289
1291
1292 void reclaim(const void *Memory) {
1293 Cache.push_back(const_cast<void *>(Memory));
1294 }
1295
1296 /// Returns memory that can be initialized as a CallEvent.
1297 void *allocate() {
1298 if (Cache.empty())
1299 return Alloc.Allocate<CallEventTemplateTy>();
1300 else
1301 return Cache.pop_back_val();
1302 }
1303
1304 template <typename T, typename Arg>
1305 T *create(Arg A, ProgramStateRef St, const LocationContext *LCtx,
1307 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1308 "CallEvent subclasses are not all the same size");
1309 return new (allocate()) T(A, St, LCtx, ElemRef);
1310 }
1311
1312 template <typename T, typename Arg1, typename Arg2>
1313 T *create(Arg1 A1, Arg2 A2, ProgramStateRef St, const LocationContext *LCtx,
1315 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1316 "CallEvent subclasses are not all the same size");
1317 return new (allocate()) T(A1, A2, St, LCtx, ElemRef);
1318 }
1319
1320 template <typename T, typename Arg1, typename Arg2, typename Arg3>
1321 T *create(Arg1 A1, Arg2 A2, Arg3 A3, ProgramStateRef St,
1322 const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef) {
1323 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1324 "CallEvent subclasses are not all the same size");
1325 return new (allocate()) T(A1, A2, A3, St, LCtx, ElemRef);
1326 }
1327
1328 template <typename T, typename Arg1, typename Arg2, typename Arg3,
1329 typename Arg4>
1330 T *create(Arg1 A1, Arg2 A2, Arg3 A3, Arg4 A4, ProgramStateRef St,
1331 const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef) {
1332 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1333 "CallEvent subclasses are not all the same size");
1334 return new (allocate()) T(A1, A2, A3, A4, St, LCtx, ElemRef);
1335 }
1336
1337public:
1338 CallEventManager(llvm::BumpPtrAllocator &alloc) : Alloc(alloc) {}
1339
1340 /// Gets an outside caller given a callee context.
1342 ProgramStateRef State);
1343
1344 /// Gets a call event for a function call, Objective-C method call,
1345 /// a 'new', or a 'delete' call.
1347 const LocationContext *LC,
1349
1351 const LocationContext *LCtx,
1353
1356 const LocationContext *LCtx,
1358 return create<ObjCMethodCall>(E, State, LCtx, ElemRef);
1359 }
1360
1363 ProgramStateRef State, const LocationContext *LCtx,
1365 return create<CXXConstructorCall>(E, Target, State, LCtx, ElemRef);
1366 }
1367
1370 const MemRegion *Target, ProgramStateRef State,
1371 const LocationContext *LCtx,
1373 return create<CXXInheritedConstructorCall>(E, Target, State, LCtx, ElemRef);
1374 }
1375
1378 const MemRegion *Target, bool IsBase,
1379 ProgramStateRef State, const LocationContext *LCtx,
1381 return create<CXXDestructorCall>(DD, Trigger, Target, IsBase, State, LCtx,
1382 ElemRef);
1383 }
1384
1387 const LocationContext *LCtx,
1389 return create<CXXAllocatorCall>(E, State, LCtx, ElemRef);
1390 }
1391
1394 const LocationContext *LCtx,
1396 return create<CXXDeallocatorCall>(E, State, LCtx, ElemRef);
1397 }
1398};
1399
1400template <typename T>
1402 assert(isa<T>(*this) && "Cloning to unrelated type");
1403 static_assert(sizeof(T) == sizeof(CallEvent),
1404 "Subclasses may not add fields");
1405
1406 if (NewState == State)
1407 return cast<T>(this);
1408
1409 CallEventManager &Mgr = State->getStateManager().getCallEventManager();
1410 T *Copy = static_cast<T *>(Mgr.allocate());
1411 cloneTo(Copy);
1412 assert(Copy->getKind() == this->getKind() && "Bad copy");
1413
1414 Copy->State = NewState;
1415 return Copy;
1416}
1417
1418inline void CallEvent::Release() const {
1419 assert(RefCount > 0 && "Reference count is already zero.");
1420 --RefCount;
1421
1422 if (RefCount > 0)
1423 return;
1424
1425 CallEventManager &Mgr = State->getStateManager().getCallEventManager();
1426 Mgr.reclaim(this);
1427
1428 this->~CallEvent();
1429}
1430
1431} // namespace ento
1432
1433} // namespace clang
1434
1435namespace llvm {
1436
1437// Support isa<>, cast<>, and dyn_cast<> for CallEventRef.
1438template <class T> struct simplify_type<clang::ento::CallEventRef<T>> {
1439 using SimpleType = const T *;
1440
1442 return Val.get();
1443 }
1444};
1445
1446} // namespace llvm
1447
1448#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H
#define SM(sm)
Definition: Cuda.cpp:82
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
TypePropertyCache< Private > Cache
Definition: Type.cpp:4305
C Language Family Type Representation.
AnalysisDeclContext contains the context data for the function, method or block under analysis.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4455
bool isConversionFromLambda() const
Definition: Decl.h:4598
ElementRefImpl< true > ConstCFGElementRef
Definition: CFG.h:915
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1530
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1673
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1593
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1670
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2528
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2481
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2520
Expr * getArgument()
Definition: ExprCXX.h:2522
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2792
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1721
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition: ExprCXX.h:1758
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2053
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2224
bool isArray() const
Definition: ExprCXX.h:2332
std::optional< Expr * > getArraySize()
This might return std::nullopt even if isArray() returns true, since there might not be an array size...
Definition: ExprCXX.h:2337
Expr * getPlacementArg(unsigned I)
Definition: ExprCXX.h:2371
bool passAlignment() const
Indicates whether the required alignment should be implicitly passed to the allocation function.
Definition: ExprCXX.h:2415
unsigned getNumPlacementArgs() const
Definition: ExprCXX.h:2362
FunctionDecl * getOperatorNew() const
Definition: ExprCXX.h:2327
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:81
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Definition: ExprCXX.h:111
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition: DeclCXX.cpp:1591
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2808
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:2999
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2986
ConstructionContext's subclasses describe different ways of constructing an object in C++.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
SourceLocation getLocation() const
Definition: DeclBase.h:444
This represents one expression.
Definition: Expr.h:110
Represents a function declaration or definition.
Definition: Decl.h:1959
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3647
One of these records is kept for each identifier that is lexed.
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
Represents an ObjC class declaration.
Definition: DeclObjC.h:1150
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:945
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: ExprObjC.h:1395
ObjCMethodFamily getMethodFamily() const
Definition: ExprObjC.h:1375
Selector getSelector() const
Definition: ExprObjC.cpp:293
bool isInstanceMessage() const
Determine whether this is an instance message to either a computed object or to super.
Definition: ExprObjC.h:1248
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
Definition: ExprObjC.cpp:314
const ObjCMethodDecl * getMethodDecl() const
Definition: ExprObjC.h:1356
unsigned getNumArgs() const
Return the number of actual arguments in this message, not counting the receiver.
Definition: ExprObjC.h:1382
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:729
Represents a parameter to a function.
Definition: Decl.h:1749
ProgramPoints can be "tagged" as representing points specific to a given analysis entity.
Definition: ProgramPoint.h:38
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6288
A (possibly-)qualified type.
Definition: Type.h:737
Smart pointer class that efficiently represents Objective-C method names.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
It represents a stack frame of the call stack (based on CallEvent).
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:350
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1819
QualType getType() const
Definition: Decl.h:717
Represents a variable declaration or definition.
Definition: Decl.h:918
Represents any constructor invocation.
Definition: CallEvent.h:876
void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
Definition: CallEvent.cpp:935
AnyCXXConstructorCall(const Expr *E, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:878
void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override
Used to specify non-argument regions that will be invalidated as a result of this call.
Definition: CallEvent.cpp:926
SVal getCXXThisVal() const
Returns the value of the implicit 'this' object.
Definition: CallEvent.cpp:920
static bool classof(const CallEvent *Call)
Definition: CallEvent.h:898
Represents a call to any sort of function that might have a FunctionDecl.
Definition: CallEvent.h:498
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition: CallEvent.h:513
AnyFunctionCall(const Expr *E, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:500
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
Definition: CallEvent.cpp:553
void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
Definition: CallEvent.cpp:614
static bool classof(const CallEvent *CA)
Definition: CallEvent.h:526
AnyFunctionCall(const Decl *D, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:504
bool argumentsMayEscape() const override
Returns true if any of the arguments are known to escape to long- term storage, even if this method w...
Definition: CallEvent.cpp:623
AnyFunctionCall(const AnyFunctionCall &Other)=default
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
Definition: CallEvent.cpp:560
Represents a call to a block.
Definition: CallEvent.h:573
const BlockDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition: CallEvent.h:604
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition: CallEvent.h:582
bool argumentsMayEscape() const override
Returns true if any of the arguments are known to escape to long- term storage, even if this method w...
Definition: CallEvent.h:661
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition: CallEvent.h:593
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
Definition: CallEvent.h:631
const BlockDataRegion * getBlockRegion() const
Returns the region associated with this instance of the block.
Definition: CallEvent.cpp:876
bool isConversionFromLambda() const
Definition: CallEvent.h:611
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
Definition: CallEvent.cpp:883
Kind getKind() const override
Returns the kind of call this is.
Definition: CallEvent.h:668
void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override
Used to specify non-argument regions that will be invalidated as a result of this call.
Definition: CallEvent.cpp:890
const VarRegion * getRegionStoringCapturedLambda() const
For a block converted from a C++ lambda, returns the block VarRegion for the variable holding the cap...
Definition: CallEvent.h:621
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition: CallEvent.h:595
BlockCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:577
BlockCall(const BlockCall &Other)=default
static bool classof(const CallEvent *CA)
Definition: CallEvent.h:671
void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
Definition: CallEvent.cpp:897
StringRef getKindAsString() const override
Definition: CallEvent.h:669
const CallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:589
BlockDataRegion - A region that represents a block instance.
Definition: MemRegion.h:673
LLVM_ATTRIBUTE_RETURNS_NONNULL const BlockDecl * getDecl() const
Definition: MemRegion.h:703
llvm::iterator_range< referenced_vars_iterator > referenced_vars() const
Definition: MemRegion.cpp:1746
Represents the memory allocation call in a C++ new-expression.
Definition: CallEvent.h:1040
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition: CallEvent.h:1075
unsigned getNumImplicitArgs() const
Number of non-placement arguments to the call.
Definition: CallEvent.h:1071
const CXXNewExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:1055
Kind getKind() const override
Returns the kind of call this is.
Definition: CallEvent.h:1106
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition: CallEvent.h:1091
std::optional< const clang::Expr * > getArraySizeExpr() const
Definition: CallEvent.h:1081
static bool classof(const CallEvent *CE)
Definition: CallEvent.h:1109
const Expr * getPlacementArgExpr(unsigned Index) const
Number of placement arguments to the operator new() call.
Definition: CallEvent.h:1102
CXXAllocatorCall(const CXXAllocatorCall &Other)=default
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition: CallEvent.h:1059
StringRef getKindAsString() const override
Definition: CallEvent.h:1107
SVal getObjectUnderConstruction() const
Definition: CallEvent.h:1063
CXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:1044
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition: CallEvent.h:1050
Represents a call to a C++ constructor.
Definition: CallEvent.h:907
CXXConstructorCall(const CXXConstructorCall &Other)=default
const CXXConstructorDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition: CallEvent.h:938
const CXXConstructExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:934
Kind getKind() const override
Returns the kind of call this is.
Definition: CallEvent.h:948
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition: CallEvent.h:929
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition: CallEvent.h:944
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition: CallEvent.h:942
CXXConstructorCall(const CXXConstructExpr *CE, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Creates a constructor call.
Definition: CallEvent.h:922
StringRef getKindAsString() const override
Definition: CallEvent.h:949
static bool classof(const CallEvent *CA)
Definition: CallEvent.h:951
Represents the memory deallocation call in a C++ delete-expression.
Definition: CallEvent.h:1124
Kind getKind() const override
Returns the kind of call this is.
Definition: CallEvent.h:1154
const CXXDeleteExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:1139
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition: CallEvent.h:1149
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition: CallEvent.h:1147
CXXDeallocatorCall(const CXXDeallocatorCall &Other)=default
static bool classof(const CallEvent *CE)
Definition: CallEvent.h:1157
StringRef getKindAsString() const override
Definition: CallEvent.h:1155
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition: CallEvent.h:1143
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition: CallEvent.h:1134
CXXDeallocatorCall(const CXXDeleteExpr *E, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:1128
Represents an implicit call to a C++ destructor.
Definition: CallEvent.h:818
static bool classof(const CallEvent *CA)
Definition: CallEvent.h:869
SVal getCXXThisVal() const override
Returns the value of the implicit 'this' object.
Definition: CallEvent.cpp:957
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
Definition: CallEvent.cpp:963
bool isBaseDestructor() const
Returns true if this is a call to a base class destructor.
Definition: CallEvent.h:862
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition: CallEvent.h:854
llvm::PointerIntPair< const MemRegion *, 1, bool > DtorDataTy
Definition: CallEvent.h:822
CXXDestructorCall(const CXXDestructorCall &Other)=default
SourceRange getSourceRange() const override
Returns a source range for the entire call, suitable for outputting in diagnostics.
Definition: CallEvent.h:853
CXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBaseDestructor, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Creates an implicit destructor.
Definition: CallEvent.h:837
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition: CallEvent.h:848
StringRef getKindAsString() const override
Definition: CallEvent.h:867
Kind getKind() const override
Returns the kind of call this is.
Definition: CallEvent.h:866
Represents a call to a C++ inherited constructor.
Definition: CallEvent.h:976
CXXInheritedConstructorCall(const CXXInheritedCtorInitExpr *CE, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:980
CXXInheritedConstructorCall(const CXXInheritedConstructorCall &Other)=default
static bool classof(const CallEvent *CA)
Definition: CallEvent.h:1032
const CXXInheritedCtorInitExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:994
const StackFrameContext * getInheritingStackFrame() const
Obtain the stack frame of the inheriting constructor.
Definition: CallEvent.cpp:950
StringRef getKindAsString() const override
Definition: CallEvent.h:1028
Kind getKind() const override
Returns the kind of call this is.
Definition: CallEvent.h:1027
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition: CallEvent.h:1013
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition: CallEvent.h:1017
const CXXConstructorDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition: CallEvent.h:998
const CXXConstructExpr * getInheritingConstructor() const
Obtain the CXXConstructExpr for the sub-class that inherited the current constructor (possibly indire...
Definition: CallEvent.h:1009
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition: CallEvent.h:989
SVal getArgSVal(unsigned Index) const override
Returns the value of a given argument at the time of the call.
Definition: CallEvent.h:1021
Represents a non-static C++ member function call, no matter how it is written.
Definition: CallEvent.h:676
CXXInstanceCall(const CXXInstanceCall &Other)=default
CXXInstanceCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:678
CXXInstanceCall(const FunctionDecl *D, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:682
void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override
Used to specify non-argument regions that will be invalidated as a result of this call.
Definition: CallEvent.cpp:704
virtual SVal getCXXThisVal() const
Returns the value of the implicit 'this' object.
Definition: CallEvent.cpp:735
static bool classof(const CallEvent *CA)
Definition: CallEvent.h:706
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
Definition: CallEvent.cpp:750
virtual const Expr * getCXXThisExpr() const
Returns the expression representing the implicit 'this' object.
Definition: CallEvent.h:694
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition: CallEvent.cpp:692
void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
Definition: CallEvent.cpp:815
Represents a non-static C++ member function call.
Definition: CallEvent.h:715
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition: CallEvent.h:738
CXXMemberCall(const CXXMemberCall &Other)=default
const CXXMemberCallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:728
static bool classof(const CallEvent *CA)
Definition: CallEvent.h:749
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition: CallEvent.h:732
CXXMemberCall(const CXXMemberCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:719
const Expr * getCXXThisExpr() const override
Returns the expression representing the implicit 'this' object.
Definition: CallEvent.cpp:856
StringRef getKindAsString() const override
Definition: CallEvent.h:747
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition: CallEvent.h:725
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
Definition: CallEvent.cpp:860
Kind getKind() const override
Returns the kind of call this is.
Definition: CallEvent.h:746
Represents a C++ overloaded operator call where the operator is implemented as a non-static member fu...
Definition: CallEvent.h:758
std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override
Some calls have parameter numbering mismatched from argument numbering.
Definition: CallEvent.h:795
OverloadedOperatorKind getOverloadedOperator() const
Definition: CallEvent.h:809
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition: CallEvent.h:781
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition: CallEvent.h:777
Kind getKind() const override
Returns the kind of call this is.
Definition: CallEvent.h:787
StringRef getKindAsString() const override
Definition: CallEvent.h:788
const Expr * getCXXThisExpr() const override
Returns the expression representing the implicit 'this' object.
Definition: CallEvent.cpp:872
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition: CallEvent.h:768
CXXMemberOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:762
const CXXOperatorCallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:773
CXXMemberOperatorCall(const CXXMemberOperatorCall &Other)=default
unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override
Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices.
Definition: CallEvent.h:803
static bool classof(const CallEvent *CA)
Definition: CallEvent.h:790
Manages the lifetime of CallEvent objects.
Definition: CallEvent.h:1284
CallEventRef< CXXDestructorCall > getCXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBase, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:1377
CallEventRef getCall(const Stmt *S, ProgramStateRef State, const LocationContext *LC, CFGBlock::ConstCFGElementRef ElemRef)
Gets a call event for a function call, Objective-C method call, a 'new', or a 'delete' call.
Definition: CallEvent.cpp:1482
CallEventRef< CXXDeallocatorCall > getCXXDeallocatorCall(const CXXDeleteExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:1393
CallEventRef getSimpleCall(const CallExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.cpp:1403
CallEventRef< ObjCMethodCall > getObjCMethodCall(const ObjCMessageExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:1355
CallEventRef< CXXAllocatorCall > getCXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:1386
CallEventRef< CXXConstructorCall > getCXXConstructorCall(const CXXConstructExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:1362
CallEventRef< CXXInheritedConstructorCall > getCXXInheritedConstructorCall(const CXXInheritedCtorInitExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:1369
CallEventManager(llvm::BumpPtrAllocator &alloc)
Definition: CallEvent.h:1338
CallEventRef getCaller(const StackFrameContext *CalleeCtx, ProgramStateRef State)
Gets an outside caller given a callee context.
Definition: CallEvent.cpp:1425
CallEventRef(const T *Call)
Definition: CallEvent.h:84
CallEventRef(const CallEventRef &Orig)
Definition: CallEvent.h:85
CallEventRef & operator=(const CallEventRef &)=delete
CallEventRef< T > cloneWithState(ProgramStateRef State) const
Definition: CallEvent.h:91
Represents an abstract call to a function or method along a particular path.
Definition: CallEvent.h:152
virtual SourceRange getArgSourceRange(unsigned Index) const
Returns the source range for errors associated with this argument.
Definition: CallEvent.cpp:315
virtual void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const
Used to specify non-argument regions that will be invalidated as a result of this call.
Definition: CallEvent.h:210
virtual StringRef getKindAsString() const =0
void setForeign(bool B) const
Definition: CallEvent.h:231
virtual const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:249
virtual RuntimeDefinition getRuntimeDefinition() const =0
Returns the definition of the function or method that will be called.
CallEventRef cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
Definition: CallEvent.h:381
static bool isCallStmt(const Stmt *S)
Returns true if this is a statement is a function or method call of some kind.
Definition: CallEvent.cpp:347
CallEvent & operator=(const CallEvent &)=delete
llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn > param_type_iterator
Definition: CallEvent.h:476
const ConstructionContext * getConstructionContext() const
Returns the construction context of the call, if it is a C++ constructor call or a call of a function...
Definition: CallEvent.cpp:503
param_type_iterator param_type_end() const
Definition: CallEvent.h:487
const ParamVarRegion * getParameterLocation(unsigned Index, unsigned BlockCount) const
Returns memory location for a parameter variable within the callee stack frame.
Definition: CallEvent.cpp:194
bool isCalledFromSystemHeader() const
Definition: CallEvent.cpp:533
const IdentifierInfo * getCalleeIdentifier() const
Returns the name of the callee, if its name is a simple identifier.
Definition: CallEvent.h:350
AnalysisDeclContext * getCalleeAnalysisDeclContext() const
Returns AnalysisDeclContext for the callee stack frame.
Definition: CallEvent.cpp:152
ProgramStateRef invalidateRegions(unsigned BlockCount, ProgramStateRef Orig=nullptr) const
Returns a new state with all argument regions invalidated.
Definition: CallEvent.cpp:233
virtual std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const
Some calls have parameter numbering mismatched from argument numbering.
Definition: CallEvent.h:433
const ProgramStateRef & getState() const
The state in which the call is being evaluated.
Definition: CallEvent.h:234
QualType getResultType() const
Returns the result type, adjusted for references.
Definition: CallEvent.cpp:71
CallEvent(const Expr *E, ProgramStateRef state, const LocationContext *lctx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:183
CallEventRef< T > cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
Definition: CallEvent.h:1401
bool isInSystemHeader() const
Returns true if the callee is known to be from a system header.
Definition: CallEvent.h:261
bool isForeign() const
Definition: CallEvent.h:227
bool isGlobalCFunction(StringRef SpecificName=StringRef()) const
Returns true if the callee is an externally-visible function in the top-level namespace,...
Definition: CallEvent.cpp:144
virtual bool argumentsMayEscape() const
Returns true if any of the arguments are known to escape to long- term storage, even if this method w...
Definition: CallEvent.h:323
CallEvent(const CallEvent &Original)
Definition: CallEvent.h:192
param_type_iterator param_type_begin() const
Returns an iterator over the types of the call's formal parameters.
Definition: CallEvent.h:483
SourceLocation Location
Definition: CallEvent.h:170
const void * Data
Definition: CallEvent.h:165
std::pair< SVal, SVal > FrameBindingTy
Definition: CallEvent.h:368
ProgramPoint getProgramPoint(bool IsPreVisit=false, const ProgramPointTag *Tag=nullptr) const
Returns an appropriate ProgramPoint for this call.
Definition: CallEvent.cpp:288
virtual ~CallEvent()=default
const StackFrameContext * getCalleeStackFrame(unsigned BlockCount) const
Returns the callee stack frame.
Definition: CallEvent.cpp:164
static QualType getDeclaredResultType(const Decl *D)
Returns the result type of a function or method declaration.
Definition: CallEvent.cpp:351
SVal getSVal(const Stmt *S) const
Get the value of arbitrary expressions at this point in the path.
Definition: CallEvent.h:201
virtual void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const =0
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
virtual void cloneTo(void *Dest) const =0
Copies this CallEvent, with vtable intact, into a new block of memory.
static bool isVariadic(const Decl *D)
Returns true if the given decl is known to be variadic.
Definition: CallEvent.cpp:380
virtual SVal getArgSVal(unsigned Index) const
Returns the value of a given argument at the time of the call.
Definition: CallEvent.cpp:308
bool hasNonNullArgumentsWithType(bool(*Condition)(QualType)) const
Returns true if the type of any of the non-null arguments satisfies the condition.
Definition: CallEvent.cpp:113
std::optional< SVal > getReturnValueUnderConstruction() const
If the call returns a C++ record type then the region of its return value can be retrieved from its c...
Definition: CallEvent.cpp:540
virtual const Expr * getArgExpr(unsigned Index) const
Returns the expression associated with a given argument.
Definition: CallEvent.h:292
virtual unsigned getNumArgs() const =0
Returns the number of arguments (explicit and implicit).
bool hasVoidPointerToNonConstArg() const
Returns true if any of the arguments is void*.
Definition: CallEvent.cpp:140
const CallEventRef getCaller() const
Definition: CallEvent.cpp:520
bool isArgumentConstructedDirectly(unsigned Index) const
Returns true if on the current path, the argument was constructed by calling a C++ constructor over i...
Definition: CallEvent.h:421
SmallVectorImpl< FrameBindingTy > BindingsTy
Definition: CallEvent.h:369
SVal getReturnValue() const
Returns the return value of the call.
Definition: CallEvent.cpp:322
virtual const Decl * getDecl() const
Returns the declaration of the function or method that will be called.
Definition: CallEvent.h:223
const LocationContext * getLocationContext() const
The context in which the call is being evaluated.
Definition: CallEvent.h:237
const CFGBlock::ConstCFGElementRef & getCFGElementRef() const
Definition: CallEvent.h:239
CallEvent(const Decl *D, ProgramStateRef state, const LocationContext *lctx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:187
virtual ArrayRef< ParmVarDecl * > parameters() const =0
Return call's formal parameters.
bool hasNonZeroCallbackArg() const
Returns true if any of the arguments appear to represent callbacks.
Definition: CallEvent.cpp:136
virtual Kind getKind() const =0
Returns the kind of call this is.
virtual SourceRange getSourceRange() const
Returns a source range for the entire call, suitable for outputting in diagnostics.
Definition: CallEvent.h:283
virtual unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const
Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices.
Definition: CallEvent.h:440
bool isValid() const =delete
static std::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's ConstructionContext,...
Definition: ExprEngine.cpp:603
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:96
Represents any expression that calls an Objective-C method.
Definition: CallEvent.h:1171
ObjCMethodCall(const ObjCMethodCall &Other)=default
const ObjCMethodDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition: CallEvent.h:1201
void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override
Used to specify non-argument regions that will be invalidated as a result of this call.
Definition: CallEvent.cpp:979
static bool classof(const CallEvent *CA)
Definition: CallEvent.h:1272
bool isInstanceMessage() const
Definition: CallEvent.h:1211
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition: CallEvent.h:1207
ObjCMessageKind getMessageKind() const
Returns how the message was written in the source (property access, subscript, or explicit message se...
Definition: CallEvent.cpp:1065
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition: CallEvent.h:1205
bool isSetter() const
Returns true if this property access or subscript is a setter (has the form of an assignment).
Definition: CallEvent.h:1243
const ObjCMessageExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:1197
ObjCMethodFamily getMethodFamily() const
Definition: CallEvent.h:1215
ObjCMethodCall(const ObjCMessageExpr *Msg, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:1177
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
Definition: CallEvent.cpp:972
StringRef getKindAsString() const override
Definition: CallEvent.h:1270
SourceRange getSourceRange() const override
Returns a source range for the entire call, suitable for outputting in diagnostics.
Definition: CallEvent.cpp:1034
virtual bool canBeOverridenInSubclass(ObjCInterfaceDecl *IDecl, Selector Sel) const
Check if the selector may have multiple definitions (may have overrides).
Definition: CallEvent.cpp:1131
bool argumentsMayEscape() const override
Returns true if any of the arguments are known to escape to long- term storage, even if this method w...
Definition: CallEvent.cpp:1374
SVal getReceiverSVal() const
Returns the value of the receiver at the time of this call.
Definition: CallEvent.cpp:1004
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
Definition: CallEvent.cpp:1271
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition: CallEvent.h:1186
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
Definition: CallEvent.h:1230
bool isReceiverSelfOrSuper() const
Checks if the receiver refers to 'self' or 'super'.
Definition: CallEvent.cpp:1020
Selector getSelector() const
Definition: CallEvent.h:1219
const ObjCPropertyDecl * getAccessedProperty() const
Definition: CallEvent.cpp:1109
Kind getKind() const override
Returns the kind of call this is.
Definition: CallEvent.h:1269
void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const override
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
Definition: CallEvent.cpp:1385
ParamVarRegion - Represents a region for paremters.
Definition: MemRegion.h:1029
Information about invalidation for a particular region/symbol.
Definition: MemRegion.h:1624
Defines the runtime definition of the called function.
Definition: CallEvent.h:109
RuntimeDefinition(const Decl *InD, const MemRegion *InR)
Definition: CallEvent.h:128
RuntimeDefinition(const Decl *InD, bool Foreign)
Definition: CallEvent.h:127
const MemRegion * getDispatchRegion()
When other definitions are possible, returns the region whose runtime type determines the method defi...
Definition: CallEvent.h:140
RuntimeDefinition(const Decl *InD)
Definition: CallEvent.h:126
bool mayHaveOtherDefinitions()
Check if the definition we have is precise.
Definition: CallEvent.h:136
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition: SVals.h:55
Represents a C function or static C++ member function call.
Definition: CallEvent.h:535
static bool classof(const CallEvent *CA)
Definition: CallEvent.h:565
Kind getKind() const override
Returns the kind of call this is.
Definition: CallEvent.h:562
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition: CallEvent.h:556
SimpleFunctionCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition: CallEvent.h:539
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition: CallEvent.h:545
SimpleFunctionCall(const SimpleFunctionCall &Other)=default
StringRef getKindAsString() const override
Definition: CallEvent.h:563
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition: CallEvent.h:558
const CallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:550
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition: CallEvent.cpp:684
const VarDecl * getDecl() const override=0
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
@ CE_CXXMember
Definition: CallEvent.h:62
@ CE_ObjCMessage
Definition: CallEvent.h:76
@ CE_END_CXX_CONSTRUCTOR_CALLS
Definition: CallEvent.h:70
@ CE_CXXInheritedConstructor
Definition: CallEvent.h:68
@ CE_END_FUNCTION_CALLS
Definition: CallEvent.h:74
@ CE_END_CXX_INSTANCE_CALLS
Definition: CallEvent.h:66
@ CE_CXXDestructor
Definition: CallEvent.h:64
@ CE_BEG_CXX_INSTANCE_CALLS
Definition: CallEvent.h:65
@ CE_CXXDeallocator
Definition: CallEvent.h:72
@ CE_CXXAllocator
Definition: CallEvent.h:71
@ CE_CXXConstructor
Definition: CallEvent.h:67
@ CE_BEG_CXX_CONSTRUCTOR_CALLS
Definition: CallEvent.h:69
@ CE_CXXMemberOperator
Definition: CallEvent.h:63
@ CE_BEG_FUNCTION_CALLS
Definition: CallEvent.h:73
ObjCMessageKind
Represents the ways an Objective-C message send can occur.
Definition: CallEvent.h:1166
@ OCM_PropertyAccess
Definition: CallEvent.h:1166
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
ObjCMethodFamily
A family of Objective-C methods.
@ Other
Other implicit parameter.
YAML serialization mapping.
Definition: Dominators.h:30
Definition: Format.h:5304
static SimpleType getSimplifiedValue(clang::ento::CallEventRef< T > Val)
Definition: CallEvent.h:1441