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