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