clang 22.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;
57
58namespace ento {
59
79
80class CallEvent;
81
82template <typename T = CallEvent>
83class CallEventRef : public IntrusiveRefCntPtr<const T> {
84public:
86 CallEventRef(const CallEventRef &Orig) : IntrusiveRefCntPtr<const T>(Orig) {}
87
88 // The copy assignment operator is defined as deleted pending further
89 // motivation.
91
93 return this->get()->template cloneWithState<T>(State);
94 }
95
96 // Allow implicit conversions to a superclass type, since CallEventRef
97 // behaves like a pointer-to-const.
98 template <typename SuperT> 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.
210 virtual void
213
214 /// A state for looking up relevant Environment entries (arguments, return
215 /// value), dynamic type information and similar "stable" things.
216 /// WARNING: During the evaluation of a function call, several state
217 /// transitions happen, so this state can become partially obsolete!
218 ///
219 /// TODO: Instead of storing a complete state object in the CallEvent, only
220 /// store the relevant parts (such as argument/return SVals etc.) that aren't
221 /// allowed to become obsolete until the end of the call evaluation.
222 ProgramStateRef getState() const { return State; }
223
224public:
225 CallEvent &operator=(const CallEvent &) = delete;
226 virtual ~CallEvent() = default;
227
228 /// Returns the kind of call this is.
229 virtual Kind getKind() const = 0;
230 virtual StringRef getKindAsString() const = 0;
231
232 /// Returns the declaration of the function or method that will be
233 /// called. May be null.
234 virtual const Decl *getDecl() const {
235 return Origin.dyn_cast<const Decl *>();
236 }
237
238 bool isForeign() const {
239 assert(Foreign && "Foreign must be set before querying");
240 return *Foreign;
241 }
242 void setForeign(bool B) const { Foreign = B; }
243
244 /// NOTE: There are plans for refactoring that would eliminate this method.
245 /// Prefer to use CheckerContext::getASTContext if possible!
246 const ASTContext &getASTContext() const {
247 return getState()->getStateManager().getContext();
248 }
249
250 /// The context in which the call is being evaluated.
251 const LocationContext *getLocationContext() const { return LCtx; }
252
254 return ElemRef;
255 }
256
257 /// Returns the definition of the function or method that will be
258 /// called.
260
261 /// Returns the expression whose value will be the result of this call.
262 /// May be null.
263 virtual const Expr *getOriginExpr() const {
264 return Origin.dyn_cast<const Expr *>();
265 }
266
267 /// Returns the number of arguments (explicit and implicit).
268 ///
269 /// Note that this may be greater than the number of parameters in the
270 /// callee's declaration, and that it may include arguments not written in
271 /// the source.
272 virtual unsigned getNumArgs() const = 0;
273
274 /// Returns true if the callee is known to be from a system header.
275 bool isInSystemHeader() const {
276 const Decl *D = getDecl();
277 if (!D)
278 return false;
279
281 if (Loc.isValid()) {
282 const SourceManager &SM =
283 getState()->getStateManager().getContext().getSourceManager();
284 return SM.isInSystemHeader(D->getLocation());
285 }
286
287 // Special case for implicitly-declared global operator new/delete.
288 // These should be considered system functions.
289 if (const auto *FD = dyn_cast<FunctionDecl>(D))
290 return FD->isOverloadedOperator() && FD->isImplicit() && FD->isGlobal();
291
292 return false;
293 }
294
295 /// Returns a source range for the entire call, suitable for
296 /// outputting in diagnostics.
297 virtual SourceRange getSourceRange() const {
298 return getOriginExpr()->getSourceRange();
299 }
300
301 /// Returns the value of a given argument at the time of the call.
302 virtual SVal getArgSVal(unsigned Index) const;
303
304 /// Returns the expression associated with a given argument.
305 /// May be null if this expression does not appear in the source.
306 virtual const Expr *getArgExpr(unsigned Index) const { return nullptr; }
307
308 /// Returns the source range for errors associated with this argument.
309 ///
310 /// May be invalid if the argument is not written in the source.
311 virtual SourceRange getArgSourceRange(unsigned Index) const;
312
313 /// Returns the result type, adjusted for references.
314 QualType getResultType() const;
315
316 /// Returns the return value of the call.
317 ///
318 /// This should only be called if the CallEvent was created using a state in
319 /// which the return value has already been bound to the origin expression.
320 SVal getReturnValue() const;
321
322 /// Returns true if the type of any of the non-null arguments satisfies
323 /// the condition.
325
326 /// Returns true if any of the arguments appear to represent callbacks.
327 bool hasNonZeroCallbackArg() const;
328
329 /// Returns true if any of the arguments is void*.
330 bool hasVoidPointerToNonConstArg() const;
331
332 /// Returns true if any of the arguments are known to escape to long-
333 /// term storage, even if this method will not modify them.
334 // NOTE: The exact semantics of this are still being defined!
335 // We don't really want a list of hardcoded exceptions in the long run,
336 // but we don't want duplicated lists of known APIs in the short term either.
337 virtual bool argumentsMayEscape() const { return hasNonZeroCallbackArg(); }
338
339 /// Returns true if the callee is an externally-visible function in the
340 /// top-level namespace, such as \c malloc.
341 ///
342 /// You can use this call to determine that a particular function really is
343 /// a library function and not, say, a C++ member function with the same name.
344 ///
345 /// If a name is provided, the function must additionally match the given
346 /// name.
347 ///
348 /// Note that this deliberately excludes C++ library functions in the \c std
349 /// namespace, but will include C library functions accessed through the
350 /// \c std namespace. This also does not check if the function is declared
351 /// as 'extern "C"', or if it uses C++ name mangling.
352 // FIXME: Add a helper for checking namespaces.
353 // FIXME: Move this down to AnyFunctionCall once checkers have more
354 // precise callbacks.
355 bool isGlobalCFunction(StringRef SpecificName = StringRef()) const;
356
357 /// Returns the name of the callee, if its name is a simple identifier.
358 ///
359 /// Note that this will fail for Objective-C methods, blocks, and C++
360 /// overloaded operators. The former is named by a Selector rather than a
361 /// simple identifier, and the latter two do not have names.
362 // FIXME: Move this down to AnyFunctionCall once checkers have more
363 // precise callbacks.
365 const auto *ND = dyn_cast_or_null<NamedDecl>(getDecl());
366 if (!ND)
367 return nullptr;
368 return ND->getIdentifier();
369 }
370
371 /// Returns an appropriate ProgramPoint for this call.
372 ProgramPoint getProgramPoint(bool IsPreVisit = false,
373 const ProgramPointTag *Tag = nullptr) const;
374
375 /// Returns a new state with all argument regions invalidated.
376 ///
377 /// This accepts an alternate state in case some processing has already
378 /// occurred.
379 ProgramStateRef invalidateRegions(unsigned BlockCount,
380 ProgramStateRef Orig = nullptr) const;
381
382 using FrameBindingTy = std::pair<SVal, SVal>;
384
385 /// Populates the given SmallVector with the bindings in the callee's stack
386 /// frame at the start of this call.
387 virtual void getInitialStackFrameContents(const StackFrameContext *CalleeCtx,
388 BindingsTy &Bindings) const = 0;
389
390 /// Returns a copy of this CallEvent, but using the given state.
391 template <typename T>
393
394 /// Returns a copy of this CallEvent, but using the given state.
396 return cloneWithState<CallEvent>(NewState);
397 }
398
399 /// Returns true if this is a statement is a function or method call
400 /// of some kind.
401 static bool isCallStmt(const Stmt *S);
402
403 /// Returns the result type of a function or method declaration.
404 ///
405 /// This will return a null QualType if the result type cannot be determined.
406 static QualType getDeclaredResultType(const Decl *D);
407
408 /// Returns true if the given decl is known to be variadic.
409 ///
410 /// \p D must not be null.
411 static bool isVariadic(const Decl *D);
412
413 /// Returns AnalysisDeclContext for the callee stack frame.
414 /// Currently may fail; returns null on failure.
416
417 /// Returns the callee stack frame. That stack frame will only be entered
418 /// during analysis if the call is inlined, but it may still be useful
419 /// in intermediate calculations even if the call isn't inlined.
420 /// May fail; returns null on failure.
421 const StackFrameContext *getCalleeStackFrame(unsigned BlockCount) const;
422
423 /// Returns memory location for a parameter variable within the callee stack
424 /// frame. The behavior is undefined if the block count is different from the
425 /// one that is there when call happens. May fail; returns null on failure.
426 const ParamVarRegion *getParameterLocation(unsigned Index,
427 unsigned BlockCount) const;
428
429 /// Returns true if on the current path, the argument was constructed by
430 /// calling a C++ constructor over it. This is an internal detail of the
431 /// analysis which doesn't necessarily represent the program semantics:
432 /// if we are supposed to construct an argument directly, we may still
433 /// not do that because we don't know how (i.e., construction context is
434 /// unavailable in the CFG or not supported by the analyzer).
435 bool isArgumentConstructedDirectly(unsigned Index) const {
436 // This assumes that the object was not yet removed from the state.
439 .has_value();
440 }
441
442 /// Some calls have parameter numbering mismatched from argument numbering.
443 /// This function converts an argument index to the corresponding
444 /// parameter index. Returns std::nullopt is the argument doesn't correspond
445 /// to any parameter variable.
446 virtual std::optional<unsigned>
447 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const {
448 return ASTArgumentIndex;
449 }
450
451 /// Some call event sub-classes conveniently adjust mismatching AST indices
452 /// to match parameter indices. This function converts an argument index
453 /// as understood by CallEvent to the argument index as understood by the AST.
454 virtual unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const {
455 return CallArgumentIndex;
456 }
457
458 /// Returns the construction context of the call, if it is a C++ constructor
459 /// call or a call of a function returning a C++ class instance. Otherwise
460 /// return nullptr.
462
463 /// If the call returns a C++ record type then the region of its return value
464 /// can be retrieved from its construction context.
465 std::optional<SVal> getReturnValueUnderConstruction() const;
466
467 // Returns the CallEvent representing the caller of this function
468 const CallEventRef<> getCaller() const;
469
470 // Returns true if the function was called from a standard library function.
471 // If not or could not get the caller (it may be a top level function)
472 // returns false.
473 bool isCalledFromSystemHeader() const;
474
475 // Iterator access to formal parameters and their types.
476private:
477 struct GetTypeFn {
478 QualType operator()(ParmVarDecl *PD) const { return PD->getType(); }
479 };
480
481public:
482 /// Return call's formal parameters.
483 ///
484 /// Remember that the number of formal parameters may not match the number
485 /// of arguments for all calls. However, the first parameter will always
486 /// correspond with the argument value returned by \c getArgSVal(0).
488
490 llvm::mapped_iterator<ArrayRef<ParmVarDecl *>::iterator, GetTypeFn>;
491
492 /// Returns an iterator over the types of the call's formal parameters.
493 ///
494 /// This uses the callee decl found by default name lookup rather than the
495 /// definition because it represents a public interface, and probably has
496 /// more annotations.
498 return llvm::map_iterator(parameters().begin(), GetTypeFn());
499 }
500 /// \sa param_type_begin()
502 return llvm::map_iterator(parameters().end(), GetTypeFn());
503 }
504
505 // For debugging purposes only
506 void dump(raw_ostream &Out) const;
507 void dump() const;
508};
509
510/// Represents a call to any sort of function that might have a
511/// FunctionDecl.
513protected:
515 const LocationContext *LCtx,
517 : CallEvent(E, St, LCtx, ElemRef) {}
519 const LocationContext *LCtx,
521 : CallEvent(D, St, LCtx, ElemRef) {}
523
524public:
525 // This function is overridden by subclasses, but they must return
526 // a FunctionDecl.
527 const FunctionDecl *getDecl() const override {
529 }
530
532
533 bool argumentsMayEscape() const override;
534
536 BindingsTy &Bindings) const override;
537
538 ArrayRef<ParmVarDecl *> parameters() const override;
539
540 static bool classof(const CallEvent *CA) {
541 return CA->getKind() >= CE_BEG_FUNCTION_CALLS &&
543 }
544};
545
546/// Represents a C function or static C++ member function call.
547///
548/// Example: \c fun()
550 friend class CallEventManager;
551
552protected:
554 const LocationContext *LCtx,
556 : AnyFunctionCall(CE, St, LCtx, ElemRef) {}
558
559 void cloneTo(void *Dest) const override {
560 new (Dest) SimpleFunctionCall(*this);
561 }
562
563public:
564 const CallExpr *getOriginExpr() const override {
566 }
567
568 const FunctionDecl *getDecl() const override;
569
571
572 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
573
574 const Expr *getArgExpr(unsigned Index) const override {
575 return getOriginExpr()->getArg(Index);
576 }
577
578 Kind getKind() const override { return CE_Function; }
579 StringRef getKindAsString() const override { return "SimpleFunctionCall"; }
580
581 static bool classof(const CallEvent *CA) {
582 return CA->getKind() == CE_Function;
583 }
584};
585
586/// Represents a call to a block.
587///
588/// Example: <tt>^{ statement-body }()</tt>
589class BlockCall : public CallEvent {
590 friend class CallEventManager;
591
592protected:
595 : CallEvent(CE, St, LCtx, ElemRef) {}
596 BlockCall(const BlockCall &Other) = default;
597
598 void cloneTo(void *Dest) const override { new (Dest) BlockCall(*this); }
599
601 ValueList &Values,
602 RegionAndSymbolInvalidationTraits *ETraits) const override;
603
604public:
605 const CallExpr *getOriginExpr() const override {
607 }
608
609 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
610
611 const Expr *getArgExpr(unsigned Index) const override {
612 return getOriginExpr()->getArg(Index);
613 }
614
615 /// Returns the region associated with this instance of the block.
616 ///
617 /// This may be NULL if the block's origin is unknown.
618 const BlockDataRegion *getBlockRegion() const;
619
620 const BlockDecl *getDecl() const override {
621 const BlockDataRegion *BR = getBlockRegion();
622 if (!BR)
623 return nullptr;
624 return BR->getDecl();
625 }
626
628 const BlockDecl *BD = getDecl();
629 if (!BD)
630 return false;
631
632 return BD->isConversionFromLambda();
633 }
634
635 /// For a block converted from a C++ lambda, returns the block
636 /// VarRegion for the variable holding the captured C++ lambda record.
638 assert(isConversionFromLambda());
639 const BlockDataRegion *BR = getBlockRegion();
640 assert(BR && "Block converted from lambda must have a block region");
641
642 auto ReferencedVars = BR->referenced_vars();
643 assert(!ReferencedVars.empty());
644 return ReferencedVars.begin().getCapturedRegion();
645 }
646
649 return RuntimeDefinition(getDecl());
650
651 // Clang converts lambdas to blocks with an implicit user-defined
652 // conversion operator method on the lambda record that looks (roughly)
653 // like:
654 //
655 // typedef R(^block_type)(P1, P2, ...);
656 // operator block_type() const {
657 // auto Lambda = *this;
658 // return ^(P1 p1, P2 p2, ...){
659 // /* return Lambda(p1, p2, ...); */
660 // };
661 // }
662 //
663 // Here R is the return type of the lambda and P1, P2, ... are
664 // its parameter types. 'Lambda' is a fake VarDecl captured by the block
665 // that is initialized to a copy of the lambda.
666 //
667 // Sema leaves the body of a lambda-converted block empty (it is
668 // produced by CodeGen), so we can't analyze it directly. Instead, we skip
669 // the block body and analyze the operator() method on the captured lambda.
670 const VarDecl *LambdaVD = getRegionStoringCapturedLambda()->getDecl();
671 const CXXRecordDecl *LambdaDecl = LambdaVD->getType()->getAsCXXRecordDecl();
672 CXXMethodDecl *LambdaCallOperator = LambdaDecl->getLambdaCallOperator();
673
674 return RuntimeDefinition(LambdaCallOperator);
675 }
676
677 bool argumentsMayEscape() const override { return true; }
678
680 BindingsTy &Bindings) const override;
681
682 ArrayRef<ParmVarDecl *> parameters() const override;
683
684 Kind getKind() const override { return CE_Block; }
685 StringRef getKindAsString() const override { return "BlockCall"; }
686
687 static bool classof(const CallEvent *CA) { return CA->getKind() == CE_Block; }
688};
689
690/// Represents a non-static C++ member function call, no matter how
691/// it is written.
693protected:
695 const LocationContext *LCtx,
697 : AnyFunctionCall(CE, St, LCtx, ElemRef) {}
699 const LocationContext *LCtx,
701 : AnyFunctionCall(D, St, LCtx, ElemRef) {}
703
705 ValueList &Values,
706 RegionAndSymbolInvalidationTraits *ETraits) const override;
707
708 /// Returns the decl refered to by the "dynamic type" of the current object
709 /// and if the class can be a sub-class or not.
710 /// If the Pointer is null, the flag has no meaning.
711 std::pair<const CXXRecordDecl *, bool> getDeclForDynamicType() const;
712
713public:
714 /// Returns the expression representing the implicit 'this' object.
715 virtual const Expr *getCXXThisExpr() const { return nullptr; }
716
717 /// Returns the value of the implicit 'this' object.
718 virtual SVal getCXXThisVal() const;
719
720 const FunctionDecl *getDecl() const override;
721
723
725 BindingsTy &Bindings) const override;
726
727 static bool classof(const CallEvent *CA) {
728 return CA->getKind() >= CE_BEG_CXX_INSTANCE_CALLS &&
730 }
731};
732
733/// Represents a static C++ operator call.
734///
735/// "A" in this example.
736/// However, "B" and "C" are represented by SimpleFunctionCall.
737/// \code
738/// struct S {
739/// int pad;
740/// static void operator()(int x, int y);
741/// };
742/// S s{10};
743/// void (*fptr)(int, int) = &S::operator();
744///
745/// s(1, 2); // A
746/// S::operator()(1, 2); // B
747/// fptr(1, 2); // C
748/// \endcode
750 friend class CallEventManager;
751
752protected:
754 const LocationContext *LCtx,
756 : SimpleFunctionCall(CE, St, LCtx, ElemRef) {}
758
759 void cloneTo(void *Dest) const override {
760 new (Dest) CXXStaticOperatorCall(*this);
761 }
762
763public:
767
768 unsigned getNumArgs() const override {
769 // Ignore the object parameter that is not used for static member functions.
770 assert(getOriginExpr()->getNumArgs() > 0);
771 return getOriginExpr()->getNumArgs() - 1;
772 }
773
774 const Expr *getArgExpr(unsigned Index) const override {
775 // Ignore the object parameter that is not used for static member functions.
776 return getOriginExpr()->getArg(Index + 1);
777 }
778
779 std::optional<unsigned>
780 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override {
781 // Ignore the object parameter that is not used for static member functions.
782 if (ASTArgumentIndex == 0)
783 return std::nullopt;
784 return ASTArgumentIndex - 1;
785 }
786
787 unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override {
788 // Account for the object parameter for the static member function.
789 return CallArgumentIndex + 1;
790 }
791
795
796 Kind getKind() const override { return CE_CXXStaticOperator; }
797 StringRef getKindAsString() const override { return "CXXStaticOperatorCall"; }
798
799 static bool classof(const CallEvent *CA) {
800 return CA->getKind() == CE_CXXStaticOperator;
801 }
802};
803
804/// Represents a non-static C++ member function call.
805///
806/// Example: \c obj.fun()
808 friend class CallEventManager;
809
810protected:
812 const LocationContext *LCtx,
814 : CXXInstanceCall(CE, St, LCtx, ElemRef) {}
816
817 void cloneTo(void *Dest) const override { new (Dest) CXXMemberCall(*this); }
818
819public:
823
824 unsigned getNumArgs() const override {
825 if (const CallExpr *CE = getOriginExpr())
826 return CE->getNumArgs();
827 return 0;
828 }
829
830 const Expr *getArgExpr(unsigned Index) const override {
831 return getOriginExpr()->getArg(Index);
832 }
833
834 const Expr *getCXXThisExpr() const override;
835
837
838 Kind getKind() const override { return CE_CXXMember; }
839 StringRef getKindAsString() const override { return "CXXMemberCall"; }
840
841 static bool classof(const CallEvent *CA) {
842 return CA->getKind() == CE_CXXMember;
843 }
844};
845
846/// Represents a C++ overloaded operator call where the operator is
847/// implemented as a non-static member function.
848///
849/// Example: <tt>iter + 1</tt>
851 friend class CallEventManager;
852
853protected:
855 const LocationContext *LCtx,
857 : CXXInstanceCall(CE, St, LCtx, ElemRef) {}
859
860 void cloneTo(void *Dest) const override {
861 new (Dest) CXXMemberOperatorCall(*this);
862 }
863
864public:
868
869 unsigned getNumArgs() const override {
870 return getOriginExpr()->getNumArgs() - 1;
871 }
872
873 const Expr *getArgExpr(unsigned Index) const override {
874 return getOriginExpr()->getArg(Index + 1);
875 }
876
877 const Expr *getCXXThisExpr() const override;
878
879 Kind getKind() const override { return CE_CXXMemberOperator; }
880 StringRef getKindAsString() const override { return "CXXMemberOperatorCall"; }
881
882 static bool classof(const CallEvent *CA) {
883 return CA->getKind() == CE_CXXMemberOperator;
884 }
885
886 std::optional<unsigned>
887 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override {
888 // For member operator calls argument 0 on the expression corresponds
889 // to implicit this-parameter on the declaration.
890 return (ASTArgumentIndex > 0)
891 ? std::optional<unsigned>(ASTArgumentIndex - 1)
892 : std::nullopt;
893 }
894
895 unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override {
896 // For member operator calls argument 0 on the expression corresponds
897 // to implicit this-parameter on the declaration.
898 return CallArgumentIndex + 1;
899 }
900
904};
905
906/// Represents an implicit call to a C++ destructor.
907///
908/// This can occur at the end of a scope (for automatic objects), at the end
909/// of a full-expression (for temporaries), or as part of a delete.
911 friend class CallEventManager;
912
913protected:
914 using DtorDataTy = llvm::PointerIntPair<const MemRegion *, 1, bool>;
915
916 /// Creates an implicit destructor.
917 ///
918 /// \param DD The destructor that will be called.
919 /// \param Trigger The statement whose completion causes this destructor call.
920 /// \param Target The object region to be destructed.
921 /// \param St The path-sensitive state at this point in the program.
922 /// \param LCtx The location context at this point in the program.
923 /// \param ElemRef The reference to this destructor in the CFG.
924 ///
925 /// FIXME: Eventually we want to drop \param Target and deduce it from
926 /// \param ElemRef. To do that we need to migrate the logic for target
927 /// region lookup from ExprEngine::ProcessImplicitDtor() and make it
928 /// independent from ExprEngine.
929 CXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger,
930 const MemRegion *Target, bool IsBaseDestructor,
931 ProgramStateRef St, const LocationContext *LCtx,
933 : CXXInstanceCall(DD, St, LCtx, ElemRef) {
934 Data = DtorDataTy(Target, IsBaseDestructor).getOpaqueValue();
935 Location = Trigger->getEndLoc();
936 }
937
939
940 void cloneTo(void *Dest) const override {
941 new (Dest) CXXDestructorCall(*this);
942 }
943
944public:
945 SourceRange getSourceRange() const override { return Location; }
946 unsigned getNumArgs() const override { return 0; }
947
949
950 /// Returns the value of the implicit 'this' object.
951 SVal getCXXThisVal() const override;
952
953 /// Returns true if this is a call to a base class destructor.
954 bool isBaseDestructor() const {
955 return DtorDataTy::getFromOpaqueValue(Data).getInt();
956 }
957
958 Kind getKind() const override { return CE_CXXDestructor; }
959 StringRef getKindAsString() const override { return "CXXDestructorCall"; }
960
961 static bool classof(const CallEvent *CA) {
962 return CA->getKind() == CE_CXXDestructor;
963 }
964};
965
966/// Represents any constructor invocation. This includes regular constructors
967/// and inherited constructors.
969protected:
971 ProgramStateRef St, const LocationContext *LCtx,
973 : AnyFunctionCall(E, St, LCtx, ElemRef) {
975 // Target may be null when the region is unknown.
976 Data = Target;
977 }
978
980 ValueList &Values,
981 RegionAndSymbolInvalidationTraits *ETraits) const override;
982
984 BindingsTy &Bindings) const override;
985
986public:
987 /// Returns the value of the implicit 'this' object.
988 SVal getCXXThisVal() const;
989
990 static bool classof(const CallEvent *Call) {
991 return Call->getKind() >= CE_BEG_CXX_CONSTRUCTOR_CALLS &&
993 }
994};
995
996/// Represents a call to a C++ constructor.
997///
998/// Example: \c T(1)
1000 friend class CallEventManager;
1001
1002protected:
1003 /// Creates a constructor call.
1004 ///
1005 /// \param CE The constructor expression as written in the source.
1006 /// \param Target The region where the object should be constructed. If NULL,
1007 /// a new symbolic region will be used.
1008 /// \param St The path-sensitive state at this point in the program.
1009 /// \param LCtx The location context at this point in the program.
1010 /// \param ElemRef The reference to this constructor in the CFG.
1011 ///
1012 /// FIXME: Eventually we want to drop \param Target and deduce it from
1013 /// \param ElemRef.
1015 ProgramStateRef St, const LocationContext *LCtx,
1017 : AnyCXXConstructorCall(CE, Target, St, LCtx, ElemRef) {}
1018
1020
1021 void cloneTo(void *Dest) const override {
1022 new (Dest) CXXConstructorCall(*this);
1023 }
1024
1025public:
1029
1030 const CXXConstructorDecl *getDecl() const override {
1031 return getOriginExpr()->getConstructor();
1032 }
1033
1034 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
1035
1036 const Expr *getArgExpr(unsigned Index) const override {
1037 return getOriginExpr()->getArg(Index);
1038 }
1039
1040 Kind getKind() const override { return CE_CXXConstructor; }
1041 StringRef getKindAsString() const override { return "CXXConstructorCall"; }
1042
1043 static bool classof(const CallEvent *CA) {
1044 return CA->getKind() == CE_CXXConstructor;
1045 }
1046};
1047
1048/// Represents a call to a C++ inherited constructor.
1049///
1050/// Example: \c class T : public S { using S::S; }; T(1);
1051///
1052// Note, it is difficult to model the parameters. This is one of the reasons
1053// why we skip analysis of inheriting constructors as top-level functions.
1054// CXXInheritedCtorInitExpr doesn't take arguments and doesn't model parameter
1055// initialization because there is none: the arguments in the outer
1056// CXXConstructExpr directly initialize the parameters of the base class
1057// constructor, and no copies are made. (Making a copy of the parameter is
1058// incorrect, at least if it's done in an observable way.) The derived class
1059// constructor doesn't even exist in the formal model.
1060/// E.g., in:
1061///
1062/// struct X { X *p = this; ~X() {} };
1063/// struct A { A(X x) : b(x.p == &x) {} bool b; };
1064/// struct B : A { using A::A; };
1065/// B b = X{};
1066///
1067/// ... b.b is initialized to true.
1069 friend class CallEventManager;
1070
1071protected:
1073 const MemRegion *Target, ProgramStateRef St,
1074 const LocationContext *LCtx,
1076 : AnyCXXConstructorCall(CE, Target, St, LCtx, ElemRef) {}
1077
1079 default;
1080
1081 void cloneTo(void *Dest) const override {
1082 new (Dest) CXXInheritedConstructorCall(*this);
1083 }
1084
1085public:
1089
1090 const CXXConstructorDecl *getDecl() const override {
1091 return getOriginExpr()->getConstructor();
1092 }
1093
1094 /// Obtain the stack frame of the inheriting constructor. Argument expressions
1095 /// can be found on the call site of that stack frame.
1097
1098 /// Obtain the CXXConstructExpr for the sub-class that inherited the current
1099 /// constructor (possibly indirectly). It's the statement that contains
1100 /// argument expressions.
1102 return cast<CXXConstructExpr>(getInheritingStackFrame()->getCallSite());
1103 }
1104
1105 unsigned getNumArgs() const override {
1107 }
1108
1109 const Expr *getArgExpr(unsigned Index) const override {
1110 return getInheritingConstructor()->getArg(Index);
1111 }
1112
1113 SVal getArgSVal(unsigned Index) const override {
1114 return getState()->getSVal(
1115 getArgExpr(Index),
1116 getInheritingStackFrame()->getParent()->getStackFrame());
1117 }
1118
1119 Kind getKind() const override { return CE_CXXInheritedConstructor; }
1120 StringRef getKindAsString() const override {
1121 return "CXXInheritedConstructorCall";
1122 }
1123
1124 static bool classof(const CallEvent *CA) {
1125 return CA->getKind() == CE_CXXInheritedConstructor;
1126 }
1127};
1128
1129/// Represents the memory allocation call in a C++ new-expression.
1130///
1131/// This is a call to "operator new".
1133 friend class CallEventManager;
1134
1135protected:
1137 const LocationContext *LCtx,
1139 : AnyFunctionCall(E, St, LCtx, ElemRef) {}
1141
1142 void cloneTo(void *Dest) const override {
1143 new (Dest) CXXAllocatorCall(*this);
1144 }
1145
1146public:
1147 const CXXNewExpr *getOriginExpr() const override {
1149 }
1150
1151 const FunctionDecl *getDecl() const override {
1152 return getOriginExpr()->getOperatorNew();
1153 }
1154
1159
1160 /// Number of non-placement arguments to the call. It is equal to 2 for
1161 /// C++17 aligned operator new() calls that have alignment implicitly
1162 /// passed as the second argument, and to 1 for other operator new() calls.
1163 unsigned getNumImplicitArgs() const {
1165 }
1166
1167 unsigned getNumArgs() const override {
1169 }
1170
1171 bool isArray() const { return getOriginExpr()->isArray(); }
1172
1173 std::optional<const clang::Expr *> getArraySizeExpr() const {
1174 return getOriginExpr()->getArraySize();
1175 }
1176
1178 assert(isArray() && "The allocator call doesn't allocate and array!");
1179
1180 return getState()->getSVal(*getArraySizeExpr(), getLocationContext());
1181 }
1182
1183 const Expr *getArgExpr(unsigned Index) const override {
1184 // The first argument of an allocator call is the size of the allocation.
1185 if (Index < getNumImplicitArgs())
1186 return nullptr;
1188 }
1189
1190 /// Number of placement arguments to the operator new() call. For example,
1191 /// standard std::nothrow operator new and standard placement new both have
1192 /// 1 implicit argument (size) and 1 placement argument, while regular
1193 /// operator new() has 1 implicit argument and 0 placement arguments.
1194 const Expr *getPlacementArgExpr(unsigned Index) const {
1195 return getOriginExpr()->getPlacementArg(Index);
1196 }
1197
1198 Kind getKind() const override { return CE_CXXAllocator; }
1199 StringRef getKindAsString() const override { return "CXXAllocatorCall"; }
1200
1201 static bool classof(const CallEvent *CE) {
1202 return CE->getKind() == CE_CXXAllocator;
1203 }
1204};
1205
1206/// Represents the memory deallocation call in a C++ delete-expression.
1207///
1208/// This is a call to "operator delete".
1209// FIXME: CXXDeleteExpr isn't present for custom delete operators, or even for
1210// some those that are in the standard library, like the no-throw or align_val
1211// versions.
1212// Some pointers:
1213// http://lists.llvm.org/pipermail/cfe-dev/2020-April/065080.html
1214// clang/test/Analysis/cxx-dynamic-memory-analysis-order.cpp
1215// clang/unittests/StaticAnalyzer/CallEventTest.cpp
1217 friend class CallEventManager;
1218
1219protected:
1221 const LocationContext *LCtx,
1223 : AnyFunctionCall(E, St, LCtx, ElemRef) {}
1225
1226 void cloneTo(void *Dest) const override {
1227 new (Dest) CXXDeallocatorCall(*this);
1228 }
1229
1230public:
1231 const CXXDeleteExpr *getOriginExpr() const override {
1233 }
1234
1235 const FunctionDecl *getDecl() const override {
1236 return getOriginExpr()->getOperatorDelete();
1237 }
1238
1239 unsigned getNumArgs() const override { return getDecl()->getNumParams(); }
1240
1241 const Expr *getArgExpr(unsigned Index) const override {
1242 // CXXDeleteExpr's only have a single argument.
1243 return getOriginExpr()->getArgument();
1244 }
1245
1246 Kind getKind() const override { return CE_CXXDeallocator; }
1247 StringRef getKindAsString() const override { return "CXXDeallocatorCall"; }
1248
1249 static bool classof(const CallEvent *CE) {
1250 return CE->getKind() == CE_CXXDeallocator;
1251 }
1252};
1253
1254/// Represents the ways an Objective-C message send can occur.
1255//
1256// Note to maintainers: OCM_Message should always be last, since it does not
1257// need to fit in the Data field's low bits.
1259
1260/// Represents any expression that calls an Objective-C method.
1261///
1262/// This includes all of the kinds listed in ObjCMessageKind.
1264 friend class CallEventManager;
1265
1266 const PseudoObjectExpr *getContainingPseudoObjectExpr() const;
1267
1268protected:
1270 const LocationContext *LCtx,
1272 : CallEvent(Msg, St, LCtx, ElemRef) {
1273 Data = nullptr;
1274 }
1275
1277
1278 void cloneTo(void *Dest) const override { new (Dest) ObjCMethodCall(*this); }
1279
1281 ValueList &Values,
1282 RegionAndSymbolInvalidationTraits *ETraits) const override;
1283
1284 /// Check if the selector may have multiple definitions (may have overrides).
1285 virtual bool canBeOverridenInSubclass(ObjCInterfaceDecl *IDecl,
1286 Selector Sel) const;
1287
1288public:
1289 const ObjCMessageExpr *getOriginExpr() const override {
1291 }
1292
1293 const ObjCMethodDecl *getDecl() const override {
1294 return getOriginExpr()->getMethodDecl();
1295 }
1296
1297 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
1298
1299 const Expr *getArgExpr(unsigned Index) const override {
1300 return getOriginExpr()->getArg(Index);
1301 }
1302
1303 bool isInstanceMessage() const {
1304 return getOriginExpr()->isInstanceMessage();
1305 }
1306
1310
1312
1313 SourceRange getSourceRange() const override;
1314
1315 /// Returns the value of the receiver at the time of this call.
1316 SVal getReceiverSVal() const;
1317
1318 /// Get the interface for the receiver.
1319 ///
1320 /// This works whether this is an instance message or a class message.
1321 /// However, it currently just uses the static type of the receiver.
1325
1326 /// Checks if the receiver refers to 'self' or 'super'.
1327 bool isReceiverSelfOrSuper() const;
1328
1329 /// Returns how the message was written in the source (property access,
1330 /// subscript, or explicit message send).
1332
1333 /// Returns true if this property access or subscript is a setter (has the
1334 /// form of an assignment).
1335 bool isSetter() const {
1336 switch (getMessageKind()) {
1337 case OCM_Message:
1338 llvm_unreachable("This is not a pseudo-object access!");
1339 case OCM_PropertyAccess:
1340 return getNumArgs() > 0;
1341 case OCM_Subscript:
1342 return getNumArgs() > 1;
1343 }
1344 llvm_unreachable("Unknown message kind");
1345 }
1346
1347 // Returns the property accessed by this method, either explicitly via
1348 // property syntax or implicitly via a getter or setter method. Returns
1349 // nullptr if the call is not a prooperty access.
1351
1352 RuntimeDefinition getRuntimeDefinition() const override;
1353
1354 bool argumentsMayEscape() const override;
1355
1356 void getInitialStackFrameContents(const StackFrameContext *CalleeCtx,
1357 BindingsTy &Bindings) const override;
1358
1359 ArrayRef<ParmVarDecl *> parameters() const override;
1360
1361 Kind getKind() const override { return CE_ObjCMessage; }
1362 StringRef getKindAsString() const override { return "ObjCMethodCall"; }
1363
1364 static bool classof(const CallEvent *CA) {
1365 return CA->getKind() == CE_ObjCMessage;
1366 }
1367};
1368
1369/// Manages the lifetime of CallEvent objects.
1370///
1371/// CallEventManager provides a way to create arbitrary CallEvents "on the
1372/// stack" as if they were value objects by keeping a cache of CallEvent-sized
1373/// memory blocks. The CallEvents created by CallEventManager are only valid
1374/// for the lifetime of the OwnedCallEvent that holds them; right now these
1375/// objects cannot be copied and ownership cannot be transferred.
1377 friend class CallEvent;
1378
1379 llvm::BumpPtrAllocator &Alloc;
1381
1382 using CallEventTemplateTy = SimpleFunctionCall;
1383
1384 void reclaim(const void *Memory) {
1385 Cache.push_back(const_cast<void *>(Memory));
1386 }
1387
1388 /// Returns memory that can be initialized as a CallEvent.
1389 void *allocate() {
1390 if (Cache.empty())
1391 return Alloc.Allocate<CallEventTemplateTy>();
1392 else
1393 return Cache.pop_back_val();
1394 }
1395
1396 template <typename T, typename Arg>
1397 T *create(Arg A, ProgramStateRef St, const LocationContext *LCtx,
1399 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1400 "CallEvent subclasses are not all the same size");
1401 return new (allocate()) T(A, St, LCtx, ElemRef);
1402 }
1403
1404 template <typename T, typename Arg1, typename Arg2>
1405 T *create(Arg1 A1, Arg2 A2, ProgramStateRef St, const LocationContext *LCtx,
1407 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1408 "CallEvent subclasses are not all the same size");
1409 return new (allocate()) T(A1, A2, St, LCtx, ElemRef);
1410 }
1411
1412 template <typename T, typename Arg1, typename Arg2, typename Arg3>
1413 T *create(Arg1 A1, Arg2 A2, Arg3 A3, ProgramStateRef St,
1414 const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef) {
1415 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1416 "CallEvent subclasses are not all the same size");
1417 return new (allocate()) T(A1, A2, A3, St, LCtx, ElemRef);
1418 }
1419
1420 template <typename T, typename Arg1, typename Arg2, typename Arg3,
1421 typename Arg4>
1422 T *create(Arg1 A1, Arg2 A2, Arg3 A3, Arg4 A4, ProgramStateRef St,
1423 const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef) {
1424 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1425 "CallEvent subclasses are not all the same size");
1426 return new (allocate()) T(A1, A2, A3, A4, St, LCtx, ElemRef);
1427 }
1428
1429public:
1430 CallEventManager(llvm::BumpPtrAllocator &alloc);
1431
1432 /// Gets an outside caller given a callee context.
1433 CallEventRef<> getCaller(const StackFrameContext *CalleeCtx,
1434 ProgramStateRef State);
1435
1436 /// Gets a call event for a function call, Objective-C method call,
1437 /// a 'new', or a 'delete' call.
1438 CallEventRef<> getCall(const Stmt *S, ProgramStateRef State,
1439 const LocationContext *LC,
1441
1442 CallEventRef<> getSimpleCall(const CallExpr *E, ProgramStateRef State,
1443 const LocationContext *LCtx,
1445
1446 CallEventRef<ObjCMethodCall>
1448 const LocationContext *LCtx,
1450 return create<ObjCMethodCall>(E, State, LCtx, ElemRef);
1451 }
1452
1455 ProgramStateRef State, const LocationContext *LCtx,
1457 return create<CXXConstructorCall>(E, Target, State, LCtx, ElemRef);
1458 }
1459
1462 const MemRegion *Target, ProgramStateRef State,
1463 const LocationContext *LCtx,
1465 return create<CXXInheritedConstructorCall>(E, Target, State, LCtx, ElemRef);
1466 }
1467
1470 const MemRegion *Target, bool IsBase,
1471 ProgramStateRef State, const LocationContext *LCtx,
1473 return create<CXXDestructorCall>(DD, Trigger, Target, IsBase, State, LCtx,
1474 ElemRef);
1475 }
1476
1479 const LocationContext *LCtx,
1481 return create<CXXAllocatorCall>(E, State, LCtx, ElemRef);
1482 }
1483
1486 const LocationContext *LCtx,
1488 return create<CXXDeallocatorCall>(E, State, LCtx, ElemRef);
1489 }
1490};
1491
1492template <typename T>
1494 assert(isa<T>(*this) && "Cloning to unrelated type");
1495 static_assert(sizeof(T) == sizeof(CallEvent),
1496 "Subclasses may not add fields");
1497
1498 if (NewState == State)
1499 return cast<T>(this);
1500
1501 CallEventManager &Mgr = State->getStateManager().getCallEventManager();
1502 T *Copy = static_cast<T *>(Mgr.allocate());
1503 cloneTo(Copy);
1504 assert(Copy->getKind() == this->getKind() && "Bad copy");
1505
1506 Copy->State = NewState;
1507 return Copy;
1508}
1509
1510inline void CallEvent::Release() const {
1511 assert(RefCount > 0 && "Reference count is already zero.");
1512 --RefCount;
1513
1514 if (RefCount > 0)
1515 return;
1516
1517 CallEventManager &Mgr = State->getStateManager().getCallEventManager();
1518 Mgr.reclaim(this);
1519
1520 this->~CallEvent();
1521}
1522
1523} // namespace ento
1524
1525} // namespace clang
1526
1527namespace llvm {
1528
1529// Support isa<>, cast<>, and dyn_cast<> for CallEventRef.
1530template <class T> struct simplify_type<clang::ento::CallEventRef<T>> {
1531 using SimpleType = const T *;
1532
1534 return Val.get();
1535 }
1536};
1537
1538} // namespace llvm
1539
1540#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H
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.
#define SM(sm)
ArrayRef< SVal > ValueList
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:220
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:4654
bool isConversionFromLambda() const
Definition Decl.h:4797
ElementRefImpl< true > ConstCFGElementRef
Definition CFG.h:921
Represents a call to a C++ constructor.
Definition ExprCXX.h:1549
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition ExprCXX.h:1692
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1612
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1689
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2628
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2667
Represents a C++ destructor within a class.
Definition DeclCXX.h:2869
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1753
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1790
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:179
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2129
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2357
bool isArray() const
Definition ExprCXX.h:2466
unsigned getNumImplicitArgs() const
Definition ExprCXX.h:2513
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:2471
Expr * getPlacementArg(unsigned I)
Definition ExprCXX.h:2505
unsigned getNumPlacementArgs() const
Definition ExprCXX.h:2496
FunctionDecl * getOperatorNew() const
Definition ExprCXX.h:2461
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:84
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Definition ExprCXX.h:114
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:1736
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2877
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition Expr.h:3081
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3068
ConstructionContext's subclasses describe different ways of constructing an object in C++.
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
SourceLocation getLocation() const
Definition DeclBase.h:439
This represents one expression.
Definition Expr.h:112
Represents a function declaration or definition.
Definition Decl.h:2000
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3815
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:1154
An expression that sends a message to the given Objective-C object or class.
Definition ExprObjC.h:940
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition ExprObjC.h:1403
ObjCMethodFamily getMethodFamily() const
Definition ExprObjC.h:1383
Selector getSelector() const
Definition ExprObjC.cpp:289
bool isInstanceMessage() const
Determine whether this is an instance message to either a computed object or to super.
Definition ExprObjC.h:1256
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
Definition ExprObjC.cpp:310
const ObjCMethodDecl * getMethodDecl() const
Definition ExprObjC.h:1364
unsigned getNumArgs() const
Return the number of actual arguments in this message, not counting the receiver.
Definition ExprObjC.h:1390
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:731
Represents a parameter to a function.
Definition Decl.h:1790
ProgramPoints can be "tagged" as representing points specific to a given analysis entity.
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6690
A (possibly-)qualified type.
Definition TypeBase.h:937
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:85
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:362
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:338
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
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...
AnyCXXConstructorCall(const Expr *E, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:970
void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override
Used to specify non-argument regions that will be invalidated as a result of this call.
SVal getCXXThisVal() const
Returns the value of the implicit 'this' object.
static bool classof(const CallEvent *Call)
Definition CallEvent.h:990
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:527
AnyFunctionCall(const Expr *E, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:514
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
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...
static bool classof(const CallEvent *CA)
Definition CallEvent.h:540
AnyFunctionCall(const Decl *D, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:518
bool argumentsMayEscape() const override
Returns true if any of the arguments are known to escape to long- term storage, even if this method w...
AnyFunctionCall(const AnyFunctionCall &Other)=default
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
const BlockDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:620
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:598
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:677
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:609
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
Definition CallEvent.h:647
const BlockDataRegion * getBlockRegion() const
Returns the region associated with this instance of the block.
bool isConversionFromLambda() const
Definition CallEvent.h:627
friend class CallEventManager
Definition CallEvent.h:590
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:684
void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override
Used to specify non-argument regions that will be invalidated as a result of this call.
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:637
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:611
BlockCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:593
BlockCall(const BlockCall &Other)=default
static bool classof(const CallEvent *CA)
Definition CallEvent.h:687
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...
StringRef getKindAsString() const override
Definition CallEvent.h:685
const CallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:605
BlockDataRegion - A region that represents a block instance.
Definition MemRegion.h:706
LLVM_ATTRIBUTE_RETURNS_NONNULL const BlockDecl * getDecl() const
Definition MemRegion.h:736
llvm::iterator_range< referenced_vars_iterator > referenced_vars() const
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1167
unsigned getNumImplicitArgs() const
Number of non-placement arguments to the call.
Definition CallEvent.h:1163
const CXXNewExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1147
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1198
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1183
std::optional< const clang::Expr * > getArraySizeExpr() const
Definition CallEvent.h:1173
static bool classof(const CallEvent *CE)
Definition CallEvent.h:1201
const Expr * getPlacementArgExpr(unsigned Index) const
Number of placement arguments to the operator new() call.
Definition CallEvent.h:1194
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:1151
StringRef getKindAsString() const override
Definition CallEvent.h:1199
SVal getObjectUnderConstruction() const
Definition CallEvent.h:1155
CXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1136
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1142
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:1030
const CXXConstructExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1026
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1040
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1021
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1036
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1034
CXXConstructorCall(const CXXConstructExpr *CE, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Creates a constructor call.
Definition CallEvent.h:1014
StringRef getKindAsString() const override
Definition CallEvent.h:1041
static bool classof(const CallEvent *CA)
Definition CallEvent.h:1043
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1246
const CXXDeleteExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1231
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1241
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1239
CXXDeallocatorCall(const CXXDeallocatorCall &Other)=default
static bool classof(const CallEvent *CE)
Definition CallEvent.h:1249
StringRef getKindAsString() const override
Definition CallEvent.h:1247
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:1235
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1226
CXXDeallocatorCall(const CXXDeleteExpr *E, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1220
static bool classof(const CallEvent *CA)
Definition CallEvent.h:961
SVal getCXXThisVal() const override
Returns the value of the implicit 'this' object.
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
bool isBaseDestructor() const
Returns true if this is a call to a base class destructor.
Definition CallEvent.h:954
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:946
llvm::PointerIntPair< const MemRegion *, 1, bool > DtorDataTy
Definition CallEvent.h:914
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:945
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:929
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:940
StringRef getKindAsString() const override
Definition CallEvent.h:959
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:958
CXXInheritedConstructorCall(const CXXInheritedCtorInitExpr *CE, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1072
CXXInheritedConstructorCall(const CXXInheritedConstructorCall &Other)=default
static bool classof(const CallEvent *CA)
Definition CallEvent.h:1124
const CXXInheritedCtorInitExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1086
const StackFrameContext * getInheritingStackFrame() const
Obtain the stack frame of the inheriting constructor.
StringRef getKindAsString() const override
Definition CallEvent.h:1120
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1119
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1105
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1109
const CXXConstructorDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:1090
const CXXConstructExpr * getInheritingConstructor() const
Obtain the CXXConstructExpr for the sub-class that inherited the current constructor (possibly indire...
Definition CallEvent.h:1101
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1081
SVal getArgSVal(unsigned Index) const override
Returns the value of a given argument at the time of the call.
Definition CallEvent.h:1113
std::pair< const CXXRecordDecl *, bool > getDeclForDynamicType() const
Returns the decl refered to by the "dynamic type" of the current object and if the class can be a sub...
CXXInstanceCall(const CXXInstanceCall &Other)=default
CXXInstanceCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:694
CXXInstanceCall(const FunctionDecl *D, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:698
void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override
Used to specify non-argument regions that will be invalidated as a result of this call.
virtual SVal getCXXThisVal() const
Returns the value of the implicit 'this' object.
static bool classof(const CallEvent *CA)
Definition CallEvent.h:727
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
virtual const Expr * getCXXThisExpr() const
Returns the expression representing the implicit 'this' object.
Definition CallEvent.h:715
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
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...
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:830
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:820
static bool classof(const CallEvent *CA)
Definition CallEvent.h:841
friend class CallEventManager
Definition CallEvent.h:808
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:824
CXXMemberCall(const CXXMemberCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:811
const Expr * getCXXThisExpr() const override
Returns the expression representing the implicit 'this' object.
StringRef getKindAsString() const override
Definition CallEvent.h:839
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:817
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:838
std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override
Some calls have parameter numbering mismatched from argument numbering.
Definition CallEvent.h:887
OverloadedOperatorKind getOverloadedOperator() const
Definition CallEvent.h:901
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:873
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:869
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:879
StringRef getKindAsString() const override
Definition CallEvent.h:880
const Expr * getCXXThisExpr() const override
Returns the expression representing the implicit 'this' object.
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:860
CXXMemberOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:854
const CXXOperatorCallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:865
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:895
static bool classof(const CallEvent *CA)
Definition CallEvent.h:882
std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override
Some calls have parameter numbering mismatched from argument numbering.
Definition CallEvent.h:780
CXXStaticOperatorCall(const CXXStaticOperatorCall &Other)=default
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:759
OverloadedOperatorKind getOverloadedOperator() const
Definition CallEvent.h:792
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:768
StringRef getKindAsString() const override
Definition CallEvent.h:797
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:796
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:774
const CXXOperatorCallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:764
CXXStaticOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:753
static bool classof(const CallEvent *CA)
Definition CallEvent.h:799
unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override
Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices.
Definition CallEvent.h:787
Manages the lifetime of CallEvent objects.
Definition CallEvent.h:1376
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:1469
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.
CallEventRef< CXXDeallocatorCall > getCXXDeallocatorCall(const CXXDeleteExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1485
CallEventRef getSimpleCall(const CallExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
CallEventRef< ObjCMethodCall > getObjCMethodCall(const ObjCMessageExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1447
CallEventManager(llvm::BumpPtrAllocator &alloc)
CallEventRef< CXXAllocatorCall > getCXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1478
CallEventRef< CXXConstructorCall > getCXXConstructorCall(const CXXConstructExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1454
CallEventRef< CXXInheritedConstructorCall > getCXXInheritedConstructorCall(const CXXInheritedCtorInitExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1461
CallEventRef getCaller(const StackFrameContext *CalleeCtx, ProgramStateRef State)
Gets an outside caller given a callee context.
CallEventRef(const T *Call)
Definition CallEvent.h:85
CallEventRef(const CallEventRef &Orig)
Definition CallEvent.h:86
CallEventRef & operator=(const CallEventRef &)=delete
CallEventRef< T > cloneWithState(ProgramStateRef State) const
Definition CallEvent.h:92
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.
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:211
virtual StringRef getKindAsString() const =0
void setForeign(bool B) const
Definition CallEvent.h:242
virtual const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:263
virtual RuntimeDefinition getRuntimeDefinition() const =0
Returns the definition of the function or method that will be called.
ProgramStateRef getState() const
A state for looking up relevant Environment entries (arguments, return value), dynamic type informati...
Definition CallEvent.h:222
CallEventKind Kind
Definition CallEvent.h:155
CallEventRef cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
Definition CallEvent.h:395
static bool isCallStmt(const Stmt *S)
Returns true if this is a statement is a function or method call of some kind.
CallEvent & operator=(const CallEvent &)=delete
const ConstructionContext * getConstructionContext() const
Returns the construction context of the call, if it is a C++ constructor call or a call of a function...
param_type_iterator param_type_end() const
Definition CallEvent.h:501
const ParamVarRegion * getParameterLocation(unsigned Index, unsigned BlockCount) const
Returns memory location for a parameter variable within the callee stack frame.
bool isCalledFromSystemHeader() const
const IdentifierInfo * getCalleeIdentifier() const
Returns the name of the callee, if its name is a simple identifier.
Definition CallEvent.h:364
AnalysisDeclContext * getCalleeAnalysisDeclContext() const
Returns AnalysisDeclContext for the callee stack frame.
ProgramStateRef invalidateRegions(unsigned BlockCount, ProgramStateRef Orig=nullptr) const
Returns a new state with all argument regions invalidated.
virtual std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const
Some calls have parameter numbering mismatched from argument numbering.
Definition CallEvent.h:447
QualType getResultType() const
Returns the result type, adjusted for references.
Definition CallEvent.cpp:70
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:1493
friend class CallEventManager
Definition CallEvent.h:182
llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn > param_type_iterator
Definition CallEvent.h:489
bool isInSystemHeader() const
Returns true if the callee is known to be from a system header.
Definition CallEvent.h:275
bool isForeign() const
Definition CallEvent.h:238
bool isGlobalCFunction(StringRef SpecificName=StringRef()) const
Returns true if the callee is an externally-visible function in the top-level namespace,...
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:337
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:497
SourceLocation Location
Definition CallEvent.h:171
std::pair< SVal, SVal > FrameBindingTy
Definition CallEvent.h:382
ProgramPoint getProgramPoint(bool IsPreVisit=false, const ProgramPointTag *Tag=nullptr) const
Returns an appropriate ProgramPoint for this call.
virtual ~CallEvent()=default
const StackFrameContext * getCalleeStackFrame(unsigned BlockCount) const
Returns the callee stack frame.
static QualType getDeclaredResultType(const Decl *D)
Returns the result type of a function or method declaration.
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.
virtual SVal getArgSVal(unsigned Index) const
Returns the value of a given argument at the time of the call.
bool hasNonNullArgumentsWithType(bool(*Condition)(QualType)) const
Returns true if the type of any of the non-null arguments satisfies the condition.
const ASTContext & getASTContext() const
NOTE: There are plans for refactoring that would eliminate this method.
Definition CallEvent.h:246
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...
virtual const Expr * getArgExpr(unsigned Index) const
Returns the expression associated with a given argument.
Definition CallEvent.h:306
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*.
const CallEventRef getCaller() const
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:435
SmallVectorImpl< FrameBindingTy > BindingsTy
Definition CallEvent.h:383
SVal getReturnValue() const
Returns the return value of the call.
virtual const Decl * getDecl() const
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:234
const LocationContext * getLocationContext() const
The context in which the call is being evaluated.
Definition CallEvent.h:251
const CFGBlock::ConstCFGElementRef & getCFGElementRef() const
Definition CallEvent.h:253
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.
virtual Kind getKind() const =0
Returns the kind of call this is.
SmallVectorImpl< SVal > ValueList
Definition CallEvent.h:206
virtual SourceRange getSourceRange() const
Returns a source range for the entire call, suitable for outputting in diagnostics.
Definition CallEvent.h:297
virtual unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const
Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices.
Definition CallEvent.h:454
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,...
MemRegion - The root abstract class for all memory regions.
Definition MemRegion.h:98
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:1293
void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override
Used to specify non-argument regions that will be invalidated as a result of this call.
static bool classof(const CallEvent *CA)
Definition CallEvent.h:1364
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1299
ObjCMessageKind getMessageKind() const
Returns how the message was written in the source (property access, subscript, or explicit message se...
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1297
bool isSetter() const
Returns true if this property access or subscript is a setter (has the form of an assignment).
Definition CallEvent.h:1335
const ObjCMessageExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1289
ObjCMethodFamily getMethodFamily() const
Definition CallEvent.h:1307
ObjCMethodCall(const ObjCMessageExpr *Msg, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1269
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
StringRef getKindAsString() const override
Definition CallEvent.h:1362
SourceRange getSourceRange() const override
Returns a source range for the entire call, suitable for outputting in diagnostics.
virtual bool canBeOverridenInSubclass(ObjCInterfaceDecl *IDecl, Selector Sel) const
Check if the selector may have multiple definitions (may have overrides).
bool argumentsMayEscape() const override
Returns true if any of the arguments are known to escape to long- term storage, even if this method w...
SVal getReceiverSVal() const
Returns the value of the receiver at the time of this call.
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1278
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
Definition CallEvent.h:1322
bool isReceiverSelfOrSuper() const
Checks if the receiver refers to 'self' or 'super'.
Selector getSelector() const
Definition CallEvent.h:1311
const ObjCPropertyDecl * getAccessedProperty() const
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1361
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...
ParamVarRegion - Represents a region for parameters.
Definition MemRegion.h:1062
Information about invalidation for a particular region/symbol.
Definition MemRegion.h:1657
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:56
Represents a C function or static C++ member function call.
Definition CallEvent.h:549
static bool classof(const CallEvent *CA)
Definition CallEvent.h:581
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:578
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:572
SimpleFunctionCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:553
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:559
SimpleFunctionCall(const SimpleFunctionCall &Other)=default
StringRef getKindAsString() const override
Definition CallEvent.h:579
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:574
const CallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:564
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
const VarDecl * getDecl() const override=0
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
@ CE_END_CXX_CONSTRUCTOR_CALLS
Definition CallEvent.h:71
@ CE_CXXInheritedConstructor
Definition CallEvent.h:69
@ CE_END_FUNCTION_CALLS
Definition CallEvent.h:75
@ CE_CXXStaticOperator
Definition CallEvent.h:62
@ CE_END_CXX_INSTANCE_CALLS
Definition CallEvent.h:67
@ CE_CXXDestructor
Definition CallEvent.h:65
@ CE_BEG_CXX_INSTANCE_CALLS
Definition CallEvent.h:66
@ CE_CXXDeallocator
Definition CallEvent.h:73
@ CE_CXXAllocator
Definition CallEvent.h:72
@ CE_CXXConstructor
Definition CallEvent.h:68
@ CE_BEG_CXX_CONSTRUCTOR_CALLS
Definition CallEvent.h:70
@ CE_CXXMemberOperator
Definition CallEvent.h:64
@ CE_BEG_FUNCTION_CALLS
Definition CallEvent.h:74
ObjCMessageKind
Represents the ways an Objective-C message send can occur.
Definition CallEvent.h:1258
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
bool isa(CodeGen::Address addr)
Definition Address.h:330
ObjCMethodFamily
A family of Objective-C methods.
const FunctionProtoType * T
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Other
Other implicit parameter.
Definition Decl.h:1746
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
static SimpleType getSimplifiedValue(clang::ento::CallEventRef< T > Val)
Definition CallEvent.h:1533