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 /// Invalidates the regions (arguments, globals, special regions like 'this')
376 /// that may have been written by this call, returning the updated state.
377 ProgramStateRef invalidateRegions(unsigned BlockCount,
378 ProgramStateRef State) const;
379
380 using FrameBindingTy = std::pair<SVal, SVal>;
382
383 /// Populates the given SmallVector with the bindings in the callee's stack
384 /// frame at the start of this call.
385 virtual void getInitialStackFrameContents(const StackFrameContext *CalleeCtx,
386 BindingsTy &Bindings) const = 0;
387
388 /// Returns a copy of this CallEvent, but using the given state.
389 template <typename T>
391
392 /// Returns a copy of this CallEvent, but using the given state.
394 return cloneWithState<CallEvent>(NewState);
395 }
396
397 /// Returns true if this is a statement is a function or method call
398 /// of some kind.
399 static bool isCallStmt(const Stmt *S);
400
401 /// Returns the result type of a function or method declaration.
402 ///
403 /// This will return a null QualType if the result type cannot be determined.
404 static QualType getDeclaredResultType(const Decl *D);
405
406 /// Returns true if the given decl is known to be variadic.
407 ///
408 /// \p D must not be null.
409 static bool isVariadic(const Decl *D);
410
411 /// Returns AnalysisDeclContext for the callee stack frame.
412 /// Currently may fail; returns null on failure.
414
415 /// Returns the callee stack frame. That stack frame will only be entered
416 /// during analysis if the call is inlined, but it may still be useful
417 /// in intermediate calculations even if the call isn't inlined.
418 /// May fail; returns null on failure.
419 const StackFrameContext *getCalleeStackFrame(unsigned BlockCount) const;
420
421 /// Returns memory location for a parameter variable within the callee stack
422 /// frame. The behavior is undefined if the block count is different from the
423 /// one that is there when call happens. May fail; returns null on failure.
424 const ParamVarRegion *getParameterLocation(unsigned Index,
425 unsigned BlockCount) const;
426
427 /// Returns true if on the current path, the argument was constructed by
428 /// calling a C++ constructor over it. This is an internal detail of the
429 /// analysis which doesn't necessarily represent the program semantics:
430 /// if we are supposed to construct an argument directly, we may still
431 /// not do that because we don't know how (i.e., construction context is
432 /// unavailable in the CFG or not supported by the analyzer).
433 bool isArgumentConstructedDirectly(unsigned Index) const {
434 // This assumes that the object was not yet removed from the state.
437 .has_value();
438 }
439
440 /// Some calls have parameter numbering mismatched from argument numbering.
441 /// This function converts an argument index to the corresponding
442 /// parameter index. Returns std::nullopt is the argument doesn't correspond
443 /// to any parameter variable.
444 virtual std::optional<unsigned>
445 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const {
446 return ASTArgumentIndex;
447 }
448
449 /// Some call event sub-classes conveniently adjust mismatching AST indices
450 /// to match parameter indices. This function converts an argument index
451 /// as understood by CallEvent to the argument index as understood by the AST.
452 virtual unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const {
453 return CallArgumentIndex;
454 }
455
456 /// Returns the construction context of the call, if it is a C++ constructor
457 /// call or a call of a function returning a C++ class instance. Otherwise
458 /// return nullptr.
460
461 /// If the call returns a C++ record type then the region of its return value
462 /// can be retrieved from its construction context.
463 std::optional<SVal> getReturnValueUnderConstruction() const;
464
465 // Returns the CallEvent representing the caller of this function
466 const CallEventRef<> getCaller() const;
467
468 // Returns true if the function was called from a standard library function.
469 // If not or could not get the caller (it may be a top level function)
470 // returns false.
471 bool isCalledFromSystemHeader() const;
472
473 // Iterator access to formal parameters and their types.
474private:
475 struct GetTypeFn {
476 QualType operator()(ParmVarDecl *PD) const { return PD->getType(); }
477 };
478
479public:
480 /// Return call's formal parameters.
481 ///
482 /// Remember that the number of formal parameters may not match the number
483 /// of arguments for all calls. However, the first parameter will always
484 /// correspond with the argument value returned by \c getArgSVal(0).
486
488 llvm::mapped_iterator<ArrayRef<ParmVarDecl *>::iterator, GetTypeFn>;
489
490 /// Returns an iterator over the types of the call's formal parameters.
491 ///
492 /// This uses the callee decl found by default name lookup rather than the
493 /// definition because it represents a public interface, and probably has
494 /// more annotations.
496 return llvm::map_iterator(parameters().begin(), GetTypeFn());
497 }
498 /// \sa param_type_begin()
500 return llvm::map_iterator(parameters().end(), GetTypeFn());
501 }
502
503 // For debugging purposes only
504 void dump(raw_ostream &Out) const;
505 void dump() const;
506};
507
508/// Represents a call to any sort of function that might have a
509/// FunctionDecl.
511protected:
513 const LocationContext *LCtx,
515 : CallEvent(E, St, LCtx, ElemRef) {}
517 const LocationContext *LCtx,
519 : CallEvent(D, St, LCtx, ElemRef) {}
521
522public:
523 // This function is overridden by subclasses, but they must return
524 // a FunctionDecl.
525 const FunctionDecl *getDecl() const override {
527 }
528
530
531 bool argumentsMayEscape() const override;
532
534 BindingsTy &Bindings) const override;
535
536 ArrayRef<ParmVarDecl *> parameters() const override;
537
538 static bool classof(const CallEvent *CA) {
539 return CA->getKind() >= CE_BEG_FUNCTION_CALLS &&
541 }
542};
543
544/// Represents a C function or static C++ member function call.
545///
546/// Example: \c fun()
548 friend class CallEventManager;
549
550protected:
552 const LocationContext *LCtx,
554 : AnyFunctionCall(CE, St, LCtx, ElemRef) {}
556
557 void cloneTo(void *Dest) const override {
558 new (Dest) SimpleFunctionCall(*this);
559 }
560
561public:
562 const CallExpr *getOriginExpr() const override {
564 }
565
566 const FunctionDecl *getDecl() const override;
567
569
570 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
571
572 const Expr *getArgExpr(unsigned Index) const override {
573 return getOriginExpr()->getArg(Index);
574 }
575
576 Kind getKind() const override { return CE_Function; }
577 StringRef getKindAsString() const override { return "SimpleFunctionCall"; }
578
579 static bool classof(const CallEvent *CA) {
580 return CA->getKind() == CE_Function;
581 }
582};
583
584/// Represents a call to a block.
585///
586/// Example: <tt>^{ statement-body }()</tt>
587class BlockCall : public CallEvent {
588 friend class CallEventManager;
589
590protected:
593 : CallEvent(CE, St, LCtx, ElemRef) {}
594 BlockCall(const BlockCall &Other) = default;
595
596 void cloneTo(void *Dest) const override { new (Dest) BlockCall(*this); }
597
599 ValueList &Values,
600 RegionAndSymbolInvalidationTraits *ETraits) const override;
601
602public:
603 const CallExpr *getOriginExpr() const override {
605 }
606
607 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
608
609 const Expr *getArgExpr(unsigned Index) const override {
610 return getOriginExpr()->getArg(Index);
611 }
612
613 /// Returns the region associated with this instance of the block.
614 ///
615 /// This may be NULL if the block's origin is unknown.
616 const BlockDataRegion *getBlockRegion() const;
617
618 const BlockDecl *getDecl() const override {
619 const BlockDataRegion *BR = getBlockRegion();
620 if (!BR)
621 return nullptr;
622 return BR->getDecl();
623 }
624
626 const BlockDecl *BD = getDecl();
627 if (!BD)
628 return false;
629
630 return BD->isConversionFromLambda();
631 }
632
633 /// For a block converted from a C++ lambda, returns the block
634 /// VarRegion for the variable holding the captured C++ lambda record.
636 assert(isConversionFromLambda());
637 const BlockDataRegion *BR = getBlockRegion();
638 assert(BR && "Block converted from lambda must have a block region");
639
640 auto ReferencedVars = BR->referenced_vars();
641 assert(!ReferencedVars.empty());
642 return ReferencedVars.begin().getCapturedRegion();
643 }
644
647 return RuntimeDefinition(getDecl());
648
649 // Clang converts lambdas to blocks with an implicit user-defined
650 // conversion operator method on the lambda record that looks (roughly)
651 // like:
652 //
653 // typedef R(^block_type)(P1, P2, ...);
654 // operator block_type() const {
655 // auto Lambda = *this;
656 // return ^(P1 p1, P2 p2, ...){
657 // /* return Lambda(p1, p2, ...); */
658 // };
659 // }
660 //
661 // Here R is the return type of the lambda and P1, P2, ... are
662 // its parameter types. 'Lambda' is a fake VarDecl captured by the block
663 // that is initialized to a copy of the lambda.
664 //
665 // Sema leaves the body of a lambda-converted block empty (it is
666 // produced by CodeGen), so we can't analyze it directly. Instead, we skip
667 // the block body and analyze the operator() method on the captured lambda.
668 const VarDecl *LambdaVD = getRegionStoringCapturedLambda()->getDecl();
669 const CXXRecordDecl *LambdaDecl = LambdaVD->getType()->getAsCXXRecordDecl();
670 CXXMethodDecl *LambdaCallOperator = LambdaDecl->getLambdaCallOperator();
671
672 return RuntimeDefinition(LambdaCallOperator);
673 }
674
675 bool argumentsMayEscape() const override { return true; }
676
678 BindingsTy &Bindings) const override;
679
680 ArrayRef<ParmVarDecl *> parameters() const override;
681
682 Kind getKind() const override { return CE_Block; }
683 StringRef getKindAsString() const override { return "BlockCall"; }
684
685 static bool classof(const CallEvent *CA) { return CA->getKind() == CE_Block; }
686};
687
688/// Represents a non-static C++ member function call, no matter how
689/// it is written.
691protected:
693 const LocationContext *LCtx,
695 : AnyFunctionCall(CE, St, LCtx, ElemRef) {}
697 const LocationContext *LCtx,
699 : AnyFunctionCall(D, St, LCtx, ElemRef) {}
701
703 ValueList &Values,
704 RegionAndSymbolInvalidationTraits *ETraits) const override;
705
706 /// Returns the decl refered to by the "dynamic type" of the current object
707 /// and if the class can be a sub-class or not.
708 /// If the Pointer is null, the flag has no meaning.
709 std::pair<const CXXRecordDecl *, bool> getDeclForDynamicType() const;
710
711public:
712 /// Returns the expression representing the implicit 'this' object.
713 virtual const Expr *getCXXThisExpr() const { return nullptr; }
714
715 /// Returns the value of the implicit 'this' object.
716 virtual SVal getCXXThisVal() const;
717
718 const FunctionDecl *getDecl() const override;
719
721
723 BindingsTy &Bindings) const override;
724
725 static bool classof(const CallEvent *CA) {
726 return CA->getKind() >= CE_BEG_CXX_INSTANCE_CALLS &&
728 }
729};
730
731/// Represents a static C++ operator call.
732///
733/// "A" in this example.
734/// However, "B" and "C" are represented by SimpleFunctionCall.
735/// \code
736/// struct S {
737/// int pad;
738/// static void operator()(int x, int y);
739/// };
740/// S s{10};
741/// void (*fptr)(int, int) = &S::operator();
742///
743/// s(1, 2); // A
744/// S::operator()(1, 2); // B
745/// fptr(1, 2); // C
746/// \endcode
748 friend class CallEventManager;
749
750protected:
752 const LocationContext *LCtx,
754 : SimpleFunctionCall(CE, St, LCtx, ElemRef) {}
756
757 void cloneTo(void *Dest) const override {
758 new (Dest) CXXStaticOperatorCall(*this);
759 }
760
761public:
765
766 unsigned getNumArgs() const override {
767 // Ignore the object parameter that is not used for static member functions.
768 assert(getOriginExpr()->getNumArgs() > 0);
769 return getOriginExpr()->getNumArgs() - 1;
770 }
771
772 const Expr *getArgExpr(unsigned Index) const override {
773 // Ignore the object parameter that is not used for static member functions.
774 return getOriginExpr()->getArg(Index + 1);
775 }
776
777 std::optional<unsigned>
778 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override {
779 // Ignore the object parameter that is not used for static member functions.
780 if (ASTArgumentIndex == 0)
781 return std::nullopt;
782 return ASTArgumentIndex - 1;
783 }
784
785 unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override {
786 // Account for the object parameter for the static member function.
787 return CallArgumentIndex + 1;
788 }
789
793
794 Kind getKind() const override { return CE_CXXStaticOperator; }
795 StringRef getKindAsString() const override { return "CXXStaticOperatorCall"; }
796
797 static bool classof(const CallEvent *CA) {
798 return CA->getKind() == CE_CXXStaticOperator;
799 }
800};
801
802/// Represents a non-static C++ member function call.
803///
804/// Example: \c obj.fun()
806 friend class CallEventManager;
807
808protected:
810 const LocationContext *LCtx,
812 : CXXInstanceCall(CE, St, LCtx, ElemRef) {}
814
815 void cloneTo(void *Dest) const override { new (Dest) CXXMemberCall(*this); }
816
817public:
821
822 unsigned getNumArgs() const override {
823 if (const CallExpr *CE = getOriginExpr())
824 return CE->getNumArgs();
825 return 0;
826 }
827
828 const Expr *getArgExpr(unsigned Index) const override {
829 return getOriginExpr()->getArg(Index);
830 }
831
832 const Expr *getCXXThisExpr() const override;
833
835
836 Kind getKind() const override { return CE_CXXMember; }
837 StringRef getKindAsString() const override { return "CXXMemberCall"; }
838
839 static bool classof(const CallEvent *CA) {
840 return CA->getKind() == CE_CXXMember;
841 }
842};
843
844/// Represents a C++ overloaded operator call where the operator is
845/// implemented as a non-static member function.
846///
847/// Example: <tt>iter + 1</tt>
849 friend class CallEventManager;
850
851protected:
853 const LocationContext *LCtx,
855 : CXXInstanceCall(CE, St, LCtx, ElemRef) {}
857
858 void cloneTo(void *Dest) const override {
859 new (Dest) CXXMemberOperatorCall(*this);
860 }
861
862public:
866
867 unsigned getNumArgs() const override {
868 return getOriginExpr()->getNumArgs() - 1;
869 }
870
871 const Expr *getArgExpr(unsigned Index) const override {
872 return getOriginExpr()->getArg(Index + 1);
873 }
874
875 const Expr *getCXXThisExpr() const override;
876
877 Kind getKind() const override { return CE_CXXMemberOperator; }
878 StringRef getKindAsString() const override { return "CXXMemberOperatorCall"; }
879
880 static bool classof(const CallEvent *CA) {
881 return CA->getKind() == CE_CXXMemberOperator;
882 }
883
884 std::optional<unsigned>
885 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override {
886 // For member operator calls argument 0 on the expression corresponds
887 // to implicit this-parameter on the declaration.
888 return (ASTArgumentIndex > 0)
889 ? std::optional<unsigned>(ASTArgumentIndex - 1)
890 : std::nullopt;
891 }
892
893 unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override {
894 // For member operator calls argument 0 on the expression corresponds
895 // to implicit this-parameter on the declaration.
896 return CallArgumentIndex + 1;
897 }
898
902};
903
904/// Represents an implicit call to a C++ destructor.
905///
906/// This can occur at the end of a scope (for automatic objects), at the end
907/// of a full-expression (for temporaries), or as part of a delete.
909 friend class CallEventManager;
910
911protected:
912 using DtorDataTy = llvm::PointerIntPair<const MemRegion *, 1, bool>;
913
914 /// Creates an implicit destructor.
915 ///
916 /// \param DD The destructor that will be called.
917 /// \param Trigger The statement whose completion causes this destructor call.
918 /// \param Target The object region to be destructed.
919 /// \param St The path-sensitive state at this point in the program.
920 /// \param LCtx The location context at this point in the program.
921 /// \param ElemRef The reference to this destructor in the CFG.
922 ///
923 /// FIXME: Eventually we want to drop \param Target and deduce it from
924 /// \param ElemRef. To do that we need to migrate the logic for target
925 /// region lookup from ExprEngine::ProcessImplicitDtor() and make it
926 /// independent from ExprEngine.
927 CXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger,
928 const MemRegion *Target, bool IsBaseDestructor,
929 ProgramStateRef St, const LocationContext *LCtx,
931 : CXXInstanceCall(DD, St, LCtx, ElemRef) {
932 Data = DtorDataTy(Target, IsBaseDestructor).getOpaqueValue();
933 Location = Trigger->getEndLoc();
934 }
935
937
938 void cloneTo(void *Dest) const override {
939 new (Dest) CXXDestructorCall(*this);
940 }
941
942public:
943 SourceRange getSourceRange() const override { return Location; }
944 unsigned getNumArgs() const override { return 0; }
945
947
948 /// Returns the value of the implicit 'this' object.
949 SVal getCXXThisVal() const override;
950
951 /// Returns true if this is a call to a base class destructor.
952 bool isBaseDestructor() const {
953 return DtorDataTy::getFromOpaqueValue(Data).getInt();
954 }
955
956 Kind getKind() const override { return CE_CXXDestructor; }
957 StringRef getKindAsString() const override { return "CXXDestructorCall"; }
958
959 static bool classof(const CallEvent *CA) {
960 return CA->getKind() == CE_CXXDestructor;
961 }
962};
963
964/// Represents any constructor invocation. This includes regular constructors
965/// and inherited constructors.
967protected:
969 ProgramStateRef St, const LocationContext *LCtx,
971 : AnyFunctionCall(E, St, LCtx, ElemRef) {
973 // Target may be null when the region is unknown.
974 Data = Target;
975 }
976
978 ValueList &Values,
979 RegionAndSymbolInvalidationTraits *ETraits) const override;
980
982 BindingsTy &Bindings) const override;
983
984public:
985 /// Returns the value of the implicit 'this' object.
986 SVal getCXXThisVal() const;
987
988 static bool classof(const CallEvent *Call) {
989 return Call->getKind() >= CE_BEG_CXX_CONSTRUCTOR_CALLS &&
991 }
992};
993
994/// Represents a call to a C++ constructor.
995///
996/// Example: \c T(1)
998 friend class CallEventManager;
999
1000protected:
1001 /// Creates a constructor call.
1002 ///
1003 /// \param CE The constructor expression as written in the source.
1004 /// \param Target The region where the object should be constructed. If NULL,
1005 /// a new symbolic region will be used.
1006 /// \param St The path-sensitive state at this point in the program.
1007 /// \param LCtx The location context at this point in the program.
1008 /// \param ElemRef The reference to this constructor in the CFG.
1009 ///
1010 /// FIXME: Eventually we want to drop \param Target and deduce it from
1011 /// \param ElemRef.
1013 ProgramStateRef St, const LocationContext *LCtx,
1015 : AnyCXXConstructorCall(CE, Target, St, LCtx, ElemRef) {}
1016
1018
1019 void cloneTo(void *Dest) const override {
1020 new (Dest) CXXConstructorCall(*this);
1021 }
1022
1023public:
1027
1028 const CXXConstructorDecl *getDecl() const override {
1029 return getOriginExpr()->getConstructor();
1030 }
1031
1032 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
1033
1034 const Expr *getArgExpr(unsigned Index) const override {
1035 return getOriginExpr()->getArg(Index);
1036 }
1037
1038 Kind getKind() const override { return CE_CXXConstructor; }
1039 StringRef getKindAsString() const override { return "CXXConstructorCall"; }
1040
1041 static bool classof(const CallEvent *CA) {
1042 return CA->getKind() == CE_CXXConstructor;
1043 }
1044};
1045
1046/// Represents a call to a C++ inherited constructor.
1047///
1048/// Example: \c class T : public S { using S::S; }; T(1);
1049///
1050// Note, it is difficult to model the parameters. This is one of the reasons
1051// why we skip analysis of inheriting constructors as top-level functions.
1052// CXXInheritedCtorInitExpr doesn't take arguments and doesn't model parameter
1053// initialization because there is none: the arguments in the outer
1054// CXXConstructExpr directly initialize the parameters of the base class
1055// constructor, and no copies are made. (Making a copy of the parameter is
1056// incorrect, at least if it's done in an observable way.) The derived class
1057// constructor doesn't even exist in the formal model.
1058/// E.g., in:
1059///
1060/// struct X { X *p = this; ~X() {} };
1061/// struct A { A(X x) : b(x.p == &x) {} bool b; };
1062/// struct B : A { using A::A; };
1063/// B b = X{};
1064///
1065/// ... b.b is initialized to true.
1067 friend class CallEventManager;
1068
1069protected:
1071 const MemRegion *Target, ProgramStateRef St,
1072 const LocationContext *LCtx,
1074 : AnyCXXConstructorCall(CE, Target, St, LCtx, ElemRef) {}
1075
1077 default;
1078
1079 void cloneTo(void *Dest) const override {
1080 new (Dest) CXXInheritedConstructorCall(*this);
1081 }
1082
1083public:
1087
1088 const CXXConstructorDecl *getDecl() const override {
1089 return getOriginExpr()->getConstructor();
1090 }
1091
1092 /// Obtain the stack frame of the inheriting constructor. Argument expressions
1093 /// can be found on the call site of that stack frame.
1095
1096 /// Obtain the CXXConstructExpr for the sub-class that inherited the current
1097 /// constructor (possibly indirectly). It's the statement that contains
1098 /// argument expressions.
1100 return cast<CXXConstructExpr>(getInheritingStackFrame()->getCallSite());
1101 }
1102
1103 unsigned getNumArgs() const override {
1105 }
1106
1107 const Expr *getArgExpr(unsigned Index) const override {
1108 return getInheritingConstructor()->getArg(Index);
1109 }
1110
1111 SVal getArgSVal(unsigned Index) const override {
1112 return getState()->getSVal(
1113 getArgExpr(Index),
1114 getInheritingStackFrame()->getParent()->getStackFrame());
1115 }
1116
1117 Kind getKind() const override { return CE_CXXInheritedConstructor; }
1118 StringRef getKindAsString() const override {
1119 return "CXXInheritedConstructorCall";
1120 }
1121
1122 static bool classof(const CallEvent *CA) {
1123 return CA->getKind() == CE_CXXInheritedConstructor;
1124 }
1125};
1126
1127/// Represents the memory allocation call in a C++ new-expression.
1128///
1129/// This is a call to "operator new".
1131 friend class CallEventManager;
1132
1133protected:
1135 const LocationContext *LCtx,
1137 : AnyFunctionCall(E, St, LCtx, ElemRef) {}
1139
1140 void cloneTo(void *Dest) const override {
1141 new (Dest) CXXAllocatorCall(*this);
1142 }
1143
1144public:
1145 const CXXNewExpr *getOriginExpr() const override {
1147 }
1148
1149 const FunctionDecl *getDecl() const override {
1150 return getOriginExpr()->getOperatorNew();
1151 }
1152
1157
1158 /// Number of non-placement arguments to the call. It is equal to 2 for
1159 /// C++17 aligned operator new() calls that have alignment implicitly
1160 /// passed as the second argument, and to 1 for other operator new() calls.
1161 unsigned getNumImplicitArgs() const {
1163 }
1164
1165 unsigned getNumArgs() const override {
1167 }
1168
1169 bool isArray() const { return getOriginExpr()->isArray(); }
1170
1171 std::optional<const clang::Expr *> getArraySizeExpr() const {
1172 return getOriginExpr()->getArraySize();
1173 }
1174
1176 assert(isArray() && "The allocator call doesn't allocate and array!");
1177
1178 return getState()->getSVal(*getArraySizeExpr(), getLocationContext());
1179 }
1180
1181 const Expr *getArgExpr(unsigned Index) const override {
1182 // The first argument of an allocator call is the size of the allocation.
1183 if (Index < getNumImplicitArgs())
1184 return nullptr;
1186 }
1187
1188 /// Number of placement arguments to the operator new() call. For example,
1189 /// standard std::nothrow operator new and standard placement new both have
1190 /// 1 implicit argument (size) and 1 placement argument, while regular
1191 /// operator new() has 1 implicit argument and 0 placement arguments.
1192 const Expr *getPlacementArgExpr(unsigned Index) const {
1193 return getOriginExpr()->getPlacementArg(Index);
1194 }
1195
1196 Kind getKind() const override { return CE_CXXAllocator; }
1197 StringRef getKindAsString() const override { return "CXXAllocatorCall"; }
1198
1199 static bool classof(const CallEvent *CE) {
1200 return CE->getKind() == CE_CXXAllocator;
1201 }
1202};
1203
1204/// Represents the memory deallocation call in a C++ delete-expression.
1205///
1206/// This is a call to "operator delete".
1207// FIXME: CXXDeleteExpr isn't present for custom delete operators, or even for
1208// some those that are in the standard library, like the no-throw or align_val
1209// versions.
1210// Some pointers:
1211// http://lists.llvm.org/pipermail/cfe-dev/2020-April/065080.html
1212// clang/test/Analysis/cxx-dynamic-memory-analysis-order.cpp
1213// clang/unittests/StaticAnalyzer/CallEventTest.cpp
1215 friend class CallEventManager;
1216
1217protected:
1219 const LocationContext *LCtx,
1221 : AnyFunctionCall(E, St, LCtx, ElemRef) {}
1223
1224 void cloneTo(void *Dest) const override {
1225 new (Dest) CXXDeallocatorCall(*this);
1226 }
1227
1228public:
1229 const CXXDeleteExpr *getOriginExpr() const override {
1231 }
1232
1233 const FunctionDecl *getDecl() const override {
1234 return getOriginExpr()->getOperatorDelete();
1235 }
1236
1237 unsigned getNumArgs() const override { return getDecl()->getNumParams(); }
1238
1239 const Expr *getArgExpr(unsigned Index) const override {
1240 // CXXDeleteExpr's only have a single argument.
1241 return getOriginExpr()->getArgument();
1242 }
1243
1244 Kind getKind() const override { return CE_CXXDeallocator; }
1245 StringRef getKindAsString() const override { return "CXXDeallocatorCall"; }
1246
1247 static bool classof(const CallEvent *CE) {
1248 return CE->getKind() == CE_CXXDeallocator;
1249 }
1250};
1251
1252/// Represents the ways an Objective-C message send can occur.
1253//
1254// Note to maintainers: OCM_Message should always be last, since it does not
1255// need to fit in the Data field's low bits.
1257
1258/// Represents any expression that calls an Objective-C method.
1259///
1260/// This includes all of the kinds listed in ObjCMessageKind.
1262 friend class CallEventManager;
1263
1264 const PseudoObjectExpr *getContainingPseudoObjectExpr() const;
1265
1266protected:
1268 const LocationContext *LCtx,
1270 : CallEvent(Msg, St, LCtx, ElemRef) {
1271 Data = nullptr;
1272 }
1273
1275
1276 void cloneTo(void *Dest) const override { new (Dest) ObjCMethodCall(*this); }
1277
1279 ValueList &Values,
1280 RegionAndSymbolInvalidationTraits *ETraits) const override;
1281
1282 /// Check if the selector may have multiple definitions (may have overrides).
1283 virtual bool canBeOverridenInSubclass(ObjCInterfaceDecl *IDecl,
1284 Selector Sel) const;
1285
1286public:
1287 const ObjCMessageExpr *getOriginExpr() const override {
1289 }
1290
1291 const ObjCMethodDecl *getDecl() const override {
1292 return getOriginExpr()->getMethodDecl();
1293 }
1294
1295 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
1296
1297 const Expr *getArgExpr(unsigned Index) const override {
1298 return getOriginExpr()->getArg(Index);
1299 }
1300
1301 bool isInstanceMessage() const {
1302 return getOriginExpr()->isInstanceMessage();
1303 }
1304
1308
1310
1311 SourceRange getSourceRange() const override;
1312
1313 /// Returns the value of the receiver at the time of this call.
1314 SVal getReceiverSVal() const;
1315
1316 /// Get the interface for the receiver.
1317 ///
1318 /// This works whether this is an instance message or a class message.
1319 /// However, it currently just uses the static type of the receiver.
1323
1324 /// Checks if the receiver refers to 'self' or 'super'.
1325 bool isReceiverSelfOrSuper() const;
1326
1327 /// Returns how the message was written in the source (property access,
1328 /// subscript, or explicit message send).
1330
1331 /// Returns true if this property access or subscript is a setter (has the
1332 /// form of an assignment).
1333 bool isSetter() const {
1334 switch (getMessageKind()) {
1335 case OCM_Message:
1336 llvm_unreachable("This is not a pseudo-object access!");
1337 case OCM_PropertyAccess:
1338 return getNumArgs() > 0;
1339 case OCM_Subscript:
1340 return getNumArgs() > 1;
1341 }
1342 llvm_unreachable("Unknown message kind");
1343 }
1344
1345 // Returns the property accessed by this method, either explicitly via
1346 // property syntax or implicitly via a getter or setter method. Returns
1347 // nullptr if the call is not a prooperty access.
1349
1350 RuntimeDefinition getRuntimeDefinition() const override;
1351
1352 bool argumentsMayEscape() const override;
1353
1354 void getInitialStackFrameContents(const StackFrameContext *CalleeCtx,
1355 BindingsTy &Bindings) const override;
1356
1357 ArrayRef<ParmVarDecl *> parameters() const override;
1358
1359 Kind getKind() const override { return CE_ObjCMessage; }
1360 StringRef getKindAsString() const override { return "ObjCMethodCall"; }
1361
1362 static bool classof(const CallEvent *CA) {
1363 return CA->getKind() == CE_ObjCMessage;
1364 }
1365};
1366
1367/// Manages the lifetime of CallEvent objects.
1368///
1369/// CallEventManager provides a way to create arbitrary CallEvents "on the
1370/// stack" as if they were value objects by keeping a cache of CallEvent-sized
1371/// memory blocks. The CallEvents created by CallEventManager are only valid
1372/// for the lifetime of the OwnedCallEvent that holds them; right now these
1373/// objects cannot be copied and ownership cannot be transferred.
1375 friend class CallEvent;
1376
1377 llvm::BumpPtrAllocator &Alloc;
1379
1380 using CallEventTemplateTy = SimpleFunctionCall;
1381
1382 void reclaim(const void *Memory) {
1383 Cache.push_back(const_cast<void *>(Memory));
1384 }
1385
1386 /// Returns memory that can be initialized as a CallEvent.
1387 void *allocate() {
1388 if (Cache.empty())
1389 return Alloc.Allocate<CallEventTemplateTy>();
1390 else
1391 return Cache.pop_back_val();
1392 }
1393
1394 template <typename T, typename Arg>
1395 T *create(Arg A, ProgramStateRef St, const LocationContext *LCtx,
1397 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1398 "CallEvent subclasses are not all the same size");
1399 return new (allocate()) T(A, St, LCtx, ElemRef);
1400 }
1401
1402 template <typename T, typename Arg1, typename Arg2>
1403 T *create(Arg1 A1, Arg2 A2, ProgramStateRef St, const LocationContext *LCtx,
1405 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1406 "CallEvent subclasses are not all the same size");
1407 return new (allocate()) T(A1, A2, St, LCtx, ElemRef);
1408 }
1409
1410 template <typename T, typename Arg1, typename Arg2, typename Arg3>
1411 T *create(Arg1 A1, Arg2 A2, Arg3 A3, ProgramStateRef St,
1412 const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef) {
1413 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1414 "CallEvent subclasses are not all the same size");
1415 return new (allocate()) T(A1, A2, A3, St, LCtx, ElemRef);
1416 }
1417
1418 template <typename T, typename Arg1, typename Arg2, typename Arg3,
1419 typename Arg4>
1420 T *create(Arg1 A1, Arg2 A2, Arg3 A3, Arg4 A4, ProgramStateRef St,
1421 const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef) {
1422 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1423 "CallEvent subclasses are not all the same size");
1424 return new (allocate()) T(A1, A2, A3, A4, St, LCtx, ElemRef);
1425 }
1426
1427public:
1428 CallEventManager(llvm::BumpPtrAllocator &alloc);
1429
1430 /// Gets an outside caller given a callee context.
1431 CallEventRef<> getCaller(const StackFrameContext *CalleeCtx,
1432 ProgramStateRef State);
1433
1434 /// Gets a call event for a function call, Objective-C method call,
1435 /// a 'new', or a 'delete' call.
1436 CallEventRef<> getCall(const Stmt *S, ProgramStateRef State,
1437 const LocationContext *LC,
1439
1440 CallEventRef<> getSimpleCall(const CallExpr *E, ProgramStateRef State,
1441 const LocationContext *LCtx,
1443
1444 CallEventRef<ObjCMethodCall>
1446 const LocationContext *LCtx,
1448 return create<ObjCMethodCall>(E, State, LCtx, ElemRef);
1449 }
1450
1453 ProgramStateRef State, const LocationContext *LCtx,
1455 return create<CXXConstructorCall>(E, Target, State, LCtx, ElemRef);
1456 }
1457
1460 const MemRegion *Target, ProgramStateRef State,
1461 const LocationContext *LCtx,
1463 return create<CXXInheritedConstructorCall>(E, Target, State, LCtx, ElemRef);
1464 }
1465
1468 const MemRegion *Target, bool IsBase,
1469 ProgramStateRef State, const LocationContext *LCtx,
1471 return create<CXXDestructorCall>(DD, Trigger, Target, IsBase, State, LCtx,
1472 ElemRef);
1473 }
1474
1477 const LocationContext *LCtx,
1479 return create<CXXAllocatorCall>(E, State, LCtx, ElemRef);
1480 }
1481
1484 const LocationContext *LCtx,
1486 return create<CXXDeallocatorCall>(E, State, LCtx, ElemRef);
1487 }
1488};
1489
1490template <typename T>
1492 assert(isa<T>(*this) && "Cloning to unrelated type");
1493 static_assert(sizeof(T) == sizeof(CallEvent),
1494 "Subclasses may not add fields");
1495
1496 if (NewState == State)
1497 return cast<T>(this);
1498
1499 CallEventManager &Mgr = State->getStateManager().getCallEventManager();
1500 T *Copy = static_cast<T *>(Mgr.allocate());
1501 cloneTo(Copy);
1502 assert(Copy->getKind() == this->getKind() && "Bad copy");
1503
1504 Copy->State = NewState;
1505 return Copy;
1506}
1507
1508inline void CallEvent::Release() const {
1509 assert(RefCount > 0 && "Reference count is already zero.");
1510 --RefCount;
1511
1512 if (RefCount > 0)
1513 return;
1514
1515 CallEventManager &Mgr = State->getStateManager().getCallEventManager();
1516 Mgr.reclaim(this);
1517
1518 this->~CallEvent();
1519}
1520
1521} // namespace ento
1522
1523} // namespace clang
1524
1525namespace llvm {
1526
1527// Support isa<>, cast<>, and dyn_cast<> for CallEventRef.
1528template <class T> struct simplify_type<clang::ento::CallEventRef<T>> {
1529 using SimpleType = const T *;
1530
1532 return Val.get();
1533 }
1534};
1535
1536} // namespace llvm
1537
1538#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:968
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:988
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:525
AnyFunctionCall(const Expr *E, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:512
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:538
AnyFunctionCall(const Decl *D, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:516
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:618
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:596
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:675
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:607
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
Definition CallEvent.h:645
const BlockDataRegion * getBlockRegion() const
Returns the region associated with this instance of the block.
bool isConversionFromLambda() const
Definition CallEvent.h:625
friend class CallEventManager
Definition CallEvent.h:588
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:682
void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const override
Used to specify non-argument regions that will be invalidated as a result of this call.
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:635
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:609
BlockCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:591
BlockCall(const BlockCall &Other)=default
static bool classof(const CallEvent *CA)
Definition CallEvent.h:685
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:683
const CallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:603
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:1165
unsigned getNumImplicitArgs() const
Number of non-placement arguments to the call.
Definition CallEvent.h:1161
const CXXNewExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1145
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1196
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1181
std::optional< const clang::Expr * > getArraySizeExpr() const
Definition CallEvent.h:1171
static bool classof(const CallEvent *CE)
Definition CallEvent.h:1199
const Expr * getPlacementArgExpr(unsigned Index) const
Number of placement arguments to the operator new() call.
Definition CallEvent.h:1192
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:1149
StringRef getKindAsString() const override
Definition CallEvent.h:1197
SVal getObjectUnderConstruction() const
Definition CallEvent.h:1153
CXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
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:1140
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:1028
const CXXConstructExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1024
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1038
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1019
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1034
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1032
CXXConstructorCall(const CXXConstructExpr *CE, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Creates a constructor call.
Definition CallEvent.h:1012
StringRef getKindAsString() const override
Definition CallEvent.h:1039
static bool classof(const CallEvent *CA)
Definition CallEvent.h:1041
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1244
const CXXDeleteExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1229
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1239
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1237
CXXDeallocatorCall(const CXXDeallocatorCall &Other)=default
static bool classof(const CallEvent *CE)
Definition CallEvent.h:1247
StringRef getKindAsString() const override
Definition CallEvent.h:1245
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:1233
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1224
CXXDeallocatorCall(const CXXDeleteExpr *E, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1218
static bool classof(const CallEvent *CA)
Definition CallEvent.h:959
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:952
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:944
llvm::PointerIntPair< const MemRegion *, 1, bool > DtorDataTy
Definition CallEvent.h:912
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:943
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:927
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:938
StringRef getKindAsString() const override
Definition CallEvent.h:957
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:956
CXXInheritedConstructorCall(const CXXInheritedCtorInitExpr *CE, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1070
CXXInheritedConstructorCall(const CXXInheritedConstructorCall &Other)=default
static bool classof(const CallEvent *CA)
Definition CallEvent.h:1122
const CXXInheritedCtorInitExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1084
const StackFrameContext * getInheritingStackFrame() const
Obtain the stack frame of the inheriting constructor.
StringRef getKindAsString() const override
Definition CallEvent.h:1118
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1117
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1103
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1107
const CXXConstructorDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:1088
const CXXConstructExpr * getInheritingConstructor() const
Obtain the CXXConstructExpr for the sub-class that inherited the current constructor (possibly indire...
Definition CallEvent.h:1099
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1079
SVal getArgSVal(unsigned Index) const override
Returns the value of a given argument at the time of the call.
Definition CallEvent.h:1111
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:692
CXXInstanceCall(const FunctionDecl *D, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:696
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:725
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:713
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:828
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:818
static bool classof(const CallEvent *CA)
Definition CallEvent.h:839
friend class CallEventManager
Definition CallEvent.h:806
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:822
CXXMemberCall(const CXXMemberCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:809
const Expr * getCXXThisExpr() const override
Returns the expression representing the implicit 'this' object.
StringRef getKindAsString() const override
Definition CallEvent.h:837
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:815
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:836
std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override
Some calls have parameter numbering mismatched from argument numbering.
Definition CallEvent.h:885
OverloadedOperatorKind getOverloadedOperator() const
Definition CallEvent.h:899
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:871
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:867
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:877
StringRef getKindAsString() const override
Definition CallEvent.h:878
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:858
CXXMemberOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:852
const CXXOperatorCallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:863
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:893
static bool classof(const CallEvent *CA)
Definition CallEvent.h:880
std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override
Some calls have parameter numbering mismatched from argument numbering.
Definition CallEvent.h:778
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:757
OverloadedOperatorKind getOverloadedOperator() const
Definition CallEvent.h:790
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:766
StringRef getKindAsString() const override
Definition CallEvent.h:795
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:794
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:772
const CXXOperatorCallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:762
CXXStaticOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:751
static bool classof(const CallEvent *CA)
Definition CallEvent.h:797
unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override
Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices.
Definition CallEvent.h:785
Manages the lifetime of CallEvent objects.
Definition CallEvent.h:1374
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:1467
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:1483
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:1445
CallEventManager(llvm::BumpPtrAllocator &alloc)
CallEventRef< CXXAllocatorCall > getCXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1476
CallEventRef< CXXConstructorCall > getCXXConstructorCall(const CXXConstructExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1452
CallEventRef< CXXInheritedConstructorCall > getCXXInheritedConstructorCall(const CXXInheritedCtorInitExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1459
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:393
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:499
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.
virtual std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const
Some calls have parameter numbering mismatched from argument numbering.
Definition CallEvent.h:445
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:1491
ProgramStateRef invalidateRegions(unsigned BlockCount, ProgramStateRef State) const
Invalidates the regions (arguments, globals, special regions like 'this') that may have been written ...
friend class CallEventManager
Definition CallEvent.h:182
llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn > param_type_iterator
Definition CallEvent.h:487
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:495
SourceLocation Location
Definition CallEvent.h:171
std::pair< SVal, SVal > FrameBindingTy
Definition CallEvent.h:380
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:433
SmallVectorImpl< FrameBindingTy > BindingsTy
Definition CallEvent.h:381
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:452
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:1291
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:1362
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1297
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:1295
bool isSetter() const
Returns true if this property access or subscript is a setter (has the form of an assignment).
Definition CallEvent.h:1333
const ObjCMessageExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1287
ObjCMethodFamily getMethodFamily() const
Definition CallEvent.h:1305
ObjCMethodCall(const ObjCMessageExpr *Msg, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1267
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
StringRef getKindAsString() const override
Definition CallEvent.h:1360
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:1276
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
Definition CallEvent.h:1320
bool isReceiverSelfOrSuper() const
Checks if the receiver refers to 'self' or 'super'.
Selector getSelector() const
Definition CallEvent.h:1309
const ObjCPropertyDecl * getAccessedProperty() const
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1359
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:547
static bool classof(const CallEvent *CA)
Definition CallEvent.h:579
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:576
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:570
SimpleFunctionCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:551
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:557
SimpleFunctionCall(const SimpleFunctionCall &Other)=default
StringRef getKindAsString() const override
Definition CallEvent.h:577
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:572
const CallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:562
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:1256
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:1531