clang 24.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 ProgramPoint;
54class ProgramPointTag;
55class StackFrame;
56
57namespace ento {
58
78
79class CallEvent;
80
81template <typename T = CallEvent>
82class CallEventRef : public IntrusiveRefCntPtr<const T> {
83public:
85 CallEventRef(const CallEventRef &Orig) : IntrusiveRefCntPtr<const T>(Orig) {}
86
87 // The copy assignment operator is defined as deleted pending further
88 // motivation.
90
92 return this->get()->template cloneWithState<T>(State);
93 }
94
95 // Allow implicit conversions to a superclass type, since CallEventRef
96 // behaves like a pointer-to-const.
97 template <typename SuperT> operator CallEventRef<SuperT>() const {
98 return this->get();
99 }
100};
101
102/// \class RuntimeDefinition
103/// Defines the runtime definition of the called function.
104///
105/// Encapsulates the information we have about which Decl will be used
106/// when the call is executed on the given path. When dealing with dynamic
107/// dispatch, the information is based on DynamicTypeInfo and might not be
108/// precise.
110 /// The Declaration of the function which could be called at runtime.
111 /// NULL if not available.
112 const Decl *D = nullptr;
113
114 /// The region representing an object (ObjC/C++) on which the method is
115 /// called. With dynamic dispatch, the method definition depends on the
116 /// runtime type of this object. NULL when the DynamicTypeInfo is
117 /// precise.
118 const MemRegion *R = nullptr;
119
120 /// A definition is foreign if it has been imported and newly created by the
121 /// ASTImporter. This can be true only if CTU is enabled.
122 const bool Foreign = false;
123
124public:
125 RuntimeDefinition() = default;
126 RuntimeDefinition(const Decl *InD) : D(InD) {}
127 RuntimeDefinition(const Decl *InD, bool Foreign) : D(InD), Foreign(Foreign) {}
128 RuntimeDefinition(const Decl *InD, const MemRegion *InR) : D(InD), R(InR) {}
129
130 const Decl *getDecl() { return D; }
131 bool isForeign() const { return Foreign; }
132
133 /// Check if the definition we have is precise.
134 /// If not, it is possible that the call dispatches to another definition at
135 /// execution time.
136 bool mayHaveOtherDefinitions() { return R != nullptr; }
137
138 /// When other definitions are possible, returns the region whose runtime type
139 /// determines the method definition.
140 const MemRegion *getDispatchRegion() { return R; }
141};
142
143/// Represents an abstract call to a function or method along a
144/// particular path.
145///
146/// CallEvents are created through the factory methods of CallEventManager.
147///
148/// CallEvents should always be cheap to create and destroy. In order for
149/// CallEventManager to be able to re-use CallEvent-sized memory blocks,
150/// subclasses of CallEvent may not add any data members to the base class.
151/// Use the "Data" and "Location" fields instead.
153public:
155
156private:
157 ProgramStateRef State;
158 const StackFrame *SF;
159 llvm::PointerUnion<const Expr *, const Decl *> Origin;
160 CFGBlock::ConstCFGElementRef ElemRef = {nullptr, 0};
161 mutable std::optional<bool> Foreign; // Set by CTU analysis.
162
163protected:
164 // This is user data for subclasses.
165 const void *Data = nullptr;
166
167 // This is user data for subclasses.
168 // This should come right before RefCount, so that the two fields can be
169 // packed together on LP64 platforms.
171
172private:
173 template <typename T> friend struct llvm::IntrusiveRefCntPtrInfo;
174
175 mutable unsigned RefCount = 0;
176
177 void Retain() const { ++RefCount; }
178 void Release() const;
179
180protected:
181 friend class CallEventManager;
182
183 CallEvent(const Expr *E, ProgramStateRef state, const StackFrame *SF,
185 : State(std::move(state)), SF(SF), Origin(E), ElemRef(ElemRef) {}
186
187 CallEvent(const Decl *D, ProgramStateRef state, const StackFrame *SF,
189 : State(std::move(state)), SF(SF), Origin(D), ElemRef(ElemRef) {}
190
191 // DO NOT MAKE PUBLIC
192 CallEvent(const CallEvent &Original)
193 : State(Original.State), SF(Original.SF), Origin(Original.Origin),
194 ElemRef(Original.ElemRef), Data(Original.Data),
195 Location(Original.Location) {}
196
197 /// Copies this CallEvent, with vtable intact, into a new block of memory.
198 virtual void cloneTo(void *Dest) const = 0;
199
200 /// Get the value of arbitrary expressions at this point in the path.
201 SVal getSVal(const Expr *E) const {
202 return getState()->getSVal(E, getStackFrame());
203 }
204
206
207 /// Used to specify non-argument regions that will be invalidated as a
208 /// result of this call.
209 virtual void
212
213 /// A state for looking up relevant Environment entries (arguments, return
214 /// value), dynamic type information and similar "stable" things.
215 /// WARNING: During the evaluation of a function call, several state
216 /// transitions happen, so this state can become partially obsolete!
217 ///
218 /// TODO: Instead of storing a complete state object in the CallEvent, only
219 /// store the relevant parts (such as argument/return SVals etc.) that aren't
220 /// allowed to become obsolete until the end of the call evaluation.
221 ProgramStateRef getState() const { return State; }
222
223public:
224 CallEvent &operator=(const CallEvent &) = delete;
225 virtual ~CallEvent() = default;
226
227 /// Returns the kind of call this is.
228 virtual Kind getKind() const = 0;
229 virtual StringRef getKindAsString() const = 0;
230
231 /// Returns the declaration of the function or method that will be
232 /// called. May be null.
233 virtual const Decl *getDecl() const { return dyn_cast<const Decl *>(Origin); }
234
235 bool isForeign() const {
236 assert(Foreign && "Foreign must be set before querying");
237 return *Foreign;
238 }
239 void setForeign(bool B) const { Foreign = B; }
240
241 /// NOTE: There are plans for refactoring that would eliminate this method.
242 /// Prefer to use CheckerContext::getASTContext if possible!
243 const ASTContext &getASTContext() const {
244 return getState()->getStateManager().getContext();
245 }
246
247 /// The stack frame in which the call is being evaluated.
248 const StackFrame *getStackFrame() const { return SF; }
249
251 return ElemRef;
252 }
253
254 /// Returns the definition of the function or method that will be
255 /// called.
257
258 /// Returns the expression whose value will be the result of this call.
259 /// Null if and only if 'this' is a CXXDestructorCall.
260 virtual const Expr *getOriginExpr() const {
261 return dyn_cast<const Expr *>(Origin);
262 }
263
264 /// Returns the number of arguments (explicit and implicit).
265 ///
266 /// Note that this may be greater than the number of parameters in the
267 /// callee's declaration, and that it may include arguments not written in
268 /// the source.
269 virtual unsigned getNumArgs() const = 0;
270
271 /// Returns true if the callee is known to be from a system header.
272 bool isInSystemHeader() const {
273 const Decl *D = getDecl();
274 if (!D)
275 return false;
276
278 if (Loc.isValid()) {
279 const SourceManager &SM =
280 getState()->getStateManager().getContext().getSourceManager();
281 return SM.isInSystemHeader(D->getLocation());
282 }
283
284 // Special case for implicitly-declared global operator new/delete.
285 // These should be considered system functions.
286 if (const auto *FD = dyn_cast<FunctionDecl>(D))
287 return FD->isOverloadedOperator() && FD->isImplicit() && FD->isGlobal();
288
289 return false;
290 }
291
292 /// Returns a source range for the entire call, suitable for
293 /// outputting in diagnostics.
294 virtual SourceRange getSourceRange() const {
295 return getOriginExpr()->getSourceRange();
296 }
297
298 /// Returns the value of a given argument at the time of the call.
299 virtual SVal getArgSVal(unsigned Index) const;
300
301 /// Returns the expression associated with a given argument.
302 /// May be null if this expression does not appear in the source.
303 virtual const Expr *getArgExpr(unsigned Index) const { return nullptr; }
304
305 /// Returns the source range for errors associated with this argument.
306 ///
307 /// May be invalid if the argument is not written in the source.
308 virtual SourceRange getArgSourceRange(unsigned Index) const;
309
310 /// Returns the result type, adjusted for references.
311 QualType getResultType() const;
312
313 /// Returns the return value of the call.
314 ///
315 /// This should only be called if the CallEvent was created using a state in
316 /// which the return value has already been bound to the origin expression.
317 SVal getReturnValue() const;
318
319 /// Returns true if the type of any of the non-null arguments satisfies
320 /// the condition.
322
323 /// Returns true if any of the arguments appear to represent callbacks.
324 bool hasNonZeroCallbackArg() const;
325
326 /// Returns true if any of the arguments is void*.
327 bool hasVoidPointerToNonConstArg() const;
328
329 /// Returns true if any of the arguments are known to escape to long-
330 /// term storage, even if this method will not modify them.
331 // NOTE: The exact semantics of this are still being defined!
332 // We don't really want a list of hardcoded exceptions in the long run,
333 // but we don't want duplicated lists of known APIs in the short term either.
334 virtual bool argumentsMayEscape() const { return hasNonZeroCallbackArg(); }
335
336 /// Returns true if the callee is an externally-visible function in the
337 /// top-level namespace, such as \c malloc.
338 ///
339 /// You can use this call to determine that a particular function really is
340 /// a library function and not, say, a C++ member function with the same name.
341 ///
342 /// If a name is provided, the function must additionally match the given
343 /// name.
344 ///
345 /// Note that this deliberately excludes C++ library functions in the \c std
346 /// namespace, but will include C library functions accessed through the
347 /// \c std namespace. This also does not check if the function is declared
348 /// as 'extern "C"', or if it uses C++ name mangling.
349 // FIXME: Add a helper for checking namespaces.
350 // FIXME: Move this down to AnyFunctionCall once checkers have more
351 // precise callbacks.
352 bool isGlobalCFunction(StringRef SpecificName = StringRef()) const;
353
354 /// Returns the name of the callee, if its name is a simple identifier.
355 ///
356 /// Note that this will fail for Objective-C methods, blocks, and C++
357 /// overloaded operators. The former is named by a Selector rather than a
358 /// simple identifier, and the latter two do not have names.
359 // FIXME: Move this down to AnyFunctionCall once checkers have more
360 // precise callbacks.
362 const auto *ND = dyn_cast_or_null<NamedDecl>(getDecl());
363 if (!ND)
364 return nullptr;
365 return ND->getIdentifier();
366 }
367
368 /// Returns an appropriate ProgramPoint for this call.
369 ProgramPoint getProgramPoint(bool IsPreVisit = false,
370 const ProgramPointTag *Tag = nullptr) const;
371
372 /// Invalidates the regions (arguments, globals, special regions like 'this')
373 /// that may have been written by this call, returning the updated state.
374 ProgramStateRef invalidateRegions(unsigned BlockCount,
375 ProgramStateRef State) const;
376
377 using FrameBindingTy = std::pair<SVal, SVal>;
379
380 /// Populates the given SmallVector with the bindings in the callee's stack
381 /// frame at the start of this call.
382 virtual void getInitialStackFrameContents(const StackFrame *CalleeSF,
383 BindingsTy &Bindings) const = 0;
384
385 /// Returns a copy of this CallEvent, but using the given state.
386 template <typename T>
388
389 /// Returns a copy of this CallEvent, but using the given state.
391 return cloneWithState<CallEvent>(NewState);
392 }
393
394 /// Returns true if this is a statement is a function or method call
395 /// of some kind.
396 static bool isCallStmt(const Stmt *S);
397
398 /// Returns the result type of a function or method declaration.
399 ///
400 /// This will return a null QualType if the result type cannot be determined.
401 static QualType getDeclaredResultType(const Decl *D);
402
403 /// Returns true if the given decl is known to be variadic.
404 ///
405 /// \p D must not be null.
406 static bool isVariadic(const Decl *D);
407
408 /// Returns AnalysisDeclContext for the callee stack frame.
409 /// Currently may fail; returns null on failure.
411
412 /// Returns the callee stack frame. That stack frame will only be entered
413 /// during analysis if the call is inlined, but it may still be useful
414 /// in intermediate calculations even if the call isn't inlined.
415 /// May fail; returns null on failure.
416 const StackFrame *getCalleeStackFrame(unsigned BlockCount) const;
417
418 /// Returns memory location for a parameter variable within the callee stack
419 /// frame. The behavior is undefined if the block count is different from the
420 /// one that is there when call happens. May fail; returns null on failure.
421 const ParamVarRegion *getParameterLocation(unsigned Index,
422 unsigned BlockCount) const;
423
424 /// Returns true if on the current path, the argument was constructed by
425 /// calling a C++ constructor over it. This is an internal detail of the
426 /// analysis which doesn't necessarily represent the program semantics:
427 /// if we are supposed to construct an argument directly, we may still
428 /// not do that because we don't know how (i.e., construction context is
429 /// unavailable in the CFG or not supported by the analyzer).
430 bool isArgumentConstructedDirectly(unsigned Index) const {
431 // This assumes that the object was not yet removed from the state.
433 getState(), {getOriginExpr(), Index}, getStackFrame())
434 .has_value();
435 }
436
437 /// Some calls have parameter numbering mismatched from argument numbering.
438 /// This function converts an argument index to the corresponding
439 /// parameter index. Returns std::nullopt is the argument doesn't correspond
440 /// to any parameter variable.
441 virtual std::optional<unsigned>
442 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const {
443 return ASTArgumentIndex;
444 }
445
446 /// Some call event sub-classes conveniently adjust mismatching AST indices
447 /// to match parameter indices. This function converts an argument index
448 /// as understood by CallEvent to the argument index as understood by the AST.
449 virtual unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const {
450 return CallArgumentIndex;
451 }
452
453 /// Returns the construction context of the call, if it is a C++ constructor
454 /// call or a call of a function returning a C++ class instance. Otherwise
455 /// return nullptr.
457
458 /// If the call returns a C++ record type then the region of its return value
459 /// can be retrieved from its construction context.
460 std::optional<SVal> getReturnValueUnderConstruction() const;
461
462 // Returns the CallEvent representing the caller of this function
463 const CallEventRef<> getCaller() const;
464
465 // Returns true if the function was called from a standard library function.
466 // If not or could not get the caller (it may be a top level function)
467 // returns false.
468 bool isCalledFromSystemHeader() const;
469
470 // Iterator access to formal parameters and their types.
471private:
472 struct GetTypeFn {
473 QualType operator()(ParmVarDecl *PD) const { return PD->getType(); }
474 };
475
476public:
477 /// Return call's formal parameters.
478 ///
479 /// Remember that the number of formal parameters may not match the number
480 /// of arguments for all calls. However, the first parameter will always
481 /// correspond with the argument value returned by \c getArgSVal(0).
483
485 llvm::mapped_iterator<ArrayRef<ParmVarDecl *>::iterator, GetTypeFn>;
486
487 /// Returns an iterator over the types of the call's formal parameters.
488 ///
489 /// This uses the callee decl found by default name lookup rather than the
490 /// definition because it represents a public interface, and probably has
491 /// more annotations.
493 return llvm::map_iterator(parameters().begin(), GetTypeFn());
494 }
495 /// \sa param_type_begin()
497 return llvm::map_iterator(parameters().end(), GetTypeFn());
498 }
499
500 // For debugging purposes only
501 void dump(raw_ostream &Out) const;
502 void dump() const;
503};
504
505/// Represents a call to any sort of function that might have a
506/// FunctionDecl.
508protected:
511 : CallEvent(E, St, SF, ElemRef) {}
514 : CallEvent(D, St, SF, ElemRef) {}
516
517public:
518 // This function is overridden by subclasses, but they must return
519 // a FunctionDecl.
520 const FunctionDecl *getDecl() const override {
522 }
523
525
526 bool argumentsMayEscape() const override;
527
528 void getInitialStackFrameContents(const StackFrame *CalleeSF,
529 BindingsTy &Bindings) const override;
530
531 ArrayRef<ParmVarDecl *> parameters() const override;
532
533 static bool classof(const CallEvent *CA) {
534 return CA->getKind() >= CE_BEG_FUNCTION_CALLS &&
536 }
537};
538
539/// Represents a C function or static C++ member function call.
540///
541/// Example: \c fun()
543 friend class CallEventManager;
544
545protected:
547 const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
548 : AnyFunctionCall(CE, St, SF, ElemRef) {}
550
551 void cloneTo(void *Dest) const override {
552 new (Dest) SimpleFunctionCall(*this);
553 }
554
555public:
556 const CallExpr *getOriginExpr() const override {
558 }
559
560 const FunctionDecl *getDecl() const override;
561
563
564 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
565
566 const Expr *getArgExpr(unsigned Index) const override {
567 return getOriginExpr()->getArg(Index);
568 }
569
570 Kind getKind() const override { return CE_Function; }
571 StringRef getKindAsString() const override { return "SimpleFunctionCall"; }
572
573 static bool classof(const CallEvent *CA) {
574 return CA->getKind() == CE_Function;
575 }
576};
577
578/// Represents a call to a block.
579///
580/// Example: <tt>^{ statement-body }()</tt>
581class BlockCall : public CallEvent {
582 friend class CallEventManager;
583
584protected:
587 : CallEvent(CE, St, SF, ElemRef) {}
588 BlockCall(const BlockCall &Other) = default;
589
590 void cloneTo(void *Dest) const override { new (Dest) BlockCall(*this); }
591
593 ValueList &Values,
594 RegionAndSymbolInvalidationTraits *ETraits) const override;
595
596public:
597 const CallExpr *getOriginExpr() const override {
599 }
600
601 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
602
603 const Expr *getArgExpr(unsigned Index) const override {
604 return getOriginExpr()->getArg(Index);
605 }
606
607 /// Returns the region associated with this instance of the block.
608 ///
609 /// This may be NULL if the block's origin is unknown.
610 const BlockDataRegion *getBlockRegion() const;
611
612 const BlockDecl *getDecl() const override {
613 const BlockDataRegion *BR = getBlockRegion();
614 if (!BR)
615 return nullptr;
616 return BR->getDecl();
617 }
618
620 const BlockDecl *BD = getDecl();
621 if (!BD)
622 return false;
623
624 return BD->isConversionFromLambda();
625 }
626
627 /// For a block converted from a C++ lambda, returns the block
628 /// VarRegion for the variable holding the captured C++ lambda record.
630 assert(isConversionFromLambda());
631 const BlockDataRegion *BR = getBlockRegion();
632 assert(BR && "Block converted from lambda must have a block region");
633
634 auto ReferencedVars = BR->referenced_vars();
635 assert(!ReferencedVars.empty());
636 return ReferencedVars.begin().getCapturedRegion();
637 }
638
641 return RuntimeDefinition(getDecl());
642
643 // Clang converts lambdas to blocks with an implicit user-defined
644 // conversion operator method on the lambda record that looks (roughly)
645 // like:
646 //
647 // typedef R(^block_type)(P1, P2, ...);
648 // operator block_type() const {
649 // auto Lambda = *this;
650 // return ^(P1 p1, P2 p2, ...){
651 // /* return Lambda(p1, p2, ...); */
652 // };
653 // }
654 //
655 // Here R is the return type of the lambda and P1, P2, ... are
656 // its parameter types. 'Lambda' is a fake VarDecl captured by the block
657 // that is initialized to a copy of the lambda.
658 //
659 // Sema leaves the body of a lambda-converted block empty (it is
660 // produced by CodeGen), so we can't analyze it directly. Instead, we skip
661 // the block body and analyze the operator() method on the captured lambda.
662 const VarDecl *LambdaVD = getRegionStoringCapturedLambda()->getDecl();
663 const CXXRecordDecl *LambdaDecl = LambdaVD->getType()->getAsCXXRecordDecl();
664 CXXMethodDecl *LambdaCallOperator = LambdaDecl->getLambdaCallOperator();
665
666 return RuntimeDefinition(LambdaCallOperator);
667 }
668
669 bool argumentsMayEscape() const override { return true; }
670
671 void getInitialStackFrameContents(const StackFrame *CalleeSF,
672 BindingsTy &Bindings) const override;
673
674 ArrayRef<ParmVarDecl *> parameters() const override;
675
676 Kind getKind() const override { return CE_Block; }
677 StringRef getKindAsString() const override { return "BlockCall"; }
678
679 static bool classof(const CallEvent *CA) { return CA->getKind() == CE_Block; }
680};
681
682/// Represents a non-static C++ member function call, no matter how
683/// it is written.
685protected:
688 : AnyFunctionCall(CE, St, SF, ElemRef) {}
690 const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
691 : AnyFunctionCall(D, St, SF, ElemRef) {}
693
695 ValueList &Values,
696 RegionAndSymbolInvalidationTraits *ETraits) const override;
697
698 /// Returns the decl refered to by the "dynamic type" of the current object
699 /// and if the class can be a sub-class or not.
700 /// If the Pointer is null, the flag has no meaning.
701 std::pair<const CXXRecordDecl *, bool> getDeclForDynamicType() const;
702
703public:
704 /// Returns the expression representing the implicit 'this' object.
705 virtual const Expr *getCXXThisExpr() const { return nullptr; }
706
707 /// Returns the value of the implicit 'this' object.
708 virtual SVal getCXXThisVal() const;
709
710 const FunctionDecl *getDecl() const override;
711
713
714 void getInitialStackFrameContents(const StackFrame *CalleeSF,
715 BindingsTy &Bindings) const override;
716
717 static bool classof(const CallEvent *CA) {
718 return CA->getKind() >= CE_BEG_CXX_INSTANCE_CALLS &&
720 }
721};
722
723/// Represents a static C++ operator call.
724///
725/// "A" in this example.
726/// However, "B" and "C" are represented by SimpleFunctionCall.
727/// \code
728/// struct S {
729/// int pad;
730/// static void operator()(int x, int y);
731/// };
732/// S s{10};
733/// void (*fptr)(int, int) = &S::operator();
734///
735/// s(1, 2); // A
736/// S::operator()(1, 2); // B
737/// fptr(1, 2); // C
738/// \endcode
740 friend class CallEventManager;
741
742protected:
744 const StackFrame *SF,
746 : SimpleFunctionCall(CE, St, SF, ElemRef) {}
748
749 void cloneTo(void *Dest) const override {
750 new (Dest) CXXStaticOperatorCall(*this);
751 }
752
753public:
757
758 unsigned getNumArgs() const override {
759 // Ignore the object parameter that is not used for static member functions.
760 assert(getOriginExpr()->getNumArgs() > 0);
761 return getOriginExpr()->getNumArgs() - 1;
762 }
763
764 const Expr *getArgExpr(unsigned Index) const override {
765 // Ignore the object parameter that is not used for static member functions.
766 return getOriginExpr()->getArg(Index + 1);
767 }
768
769 std::optional<unsigned>
770 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override {
771 // Ignore the object parameter that is not used for static member functions.
772 if (ASTArgumentIndex == 0)
773 return std::nullopt;
774 return ASTArgumentIndex - 1;
775 }
776
777 unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override {
778 // Account for the object parameter for the static member function.
779 return CallArgumentIndex + 1;
780 }
781
785
786 Kind getKind() const override { return CE_CXXStaticOperator; }
787 StringRef getKindAsString() const override { return "CXXStaticOperatorCall"; }
788
789 static bool classof(const CallEvent *CA) {
790 return CA->getKind() == CE_CXXStaticOperator;
791 }
792};
793
794/// Represents a non-static C++ member function call.
795///
796/// Example: \c obj.fun()
798 friend class CallEventManager;
799
800protected:
802 const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
803 : CXXInstanceCall(CE, St, SF, ElemRef) {}
805
806 void cloneTo(void *Dest) const override { new (Dest) CXXMemberCall(*this); }
807
808public:
812
813 unsigned getNumArgs() const override {
814 if (const CallExpr *CE = getOriginExpr())
815 return CE->getNumArgs();
816 return 0;
817 }
818
819 const Expr *getArgExpr(unsigned Index) const override {
820 return getOriginExpr()->getArg(Index);
821 }
822
823 const Expr *getCXXThisExpr() const override;
824
826
827 Kind getKind() const override { return CE_CXXMember; }
828 StringRef getKindAsString() const override { return "CXXMemberCall"; }
829
830 static bool classof(const CallEvent *CA) {
831 return CA->getKind() == CE_CXXMember;
832 }
833};
834
835/// Represents a C++ overloaded operator call where the operator is
836/// implemented as a non-static member function.
837///
838/// Example: <tt>iter + 1</tt>
840 friend class CallEventManager;
841
842protected:
844 const StackFrame *SF,
846 : CXXInstanceCall(CE, St, SF, ElemRef) {}
848
849 void cloneTo(void *Dest) const override {
850 new (Dest) CXXMemberOperatorCall(*this);
851 }
852
853public:
857
858 unsigned getNumArgs() const override {
859 return getOriginExpr()->getNumArgs() - 1;
860 }
861
862 const Expr *getArgExpr(unsigned Index) const override {
863 return getOriginExpr()->getArg(Index + 1);
864 }
865
866 const Expr *getCXXThisExpr() const override;
867
868 Kind getKind() const override { return CE_CXXMemberOperator; }
869 StringRef getKindAsString() const override { return "CXXMemberOperatorCall"; }
870
871 static bool classof(const CallEvent *CA) {
872 return CA->getKind() == CE_CXXMemberOperator;
873 }
874
875 std::optional<unsigned>
876 getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override {
877 // For member operator calls argument 0 on the expression corresponds
878 // to implicit this-parameter on the declaration.
879 return (ASTArgumentIndex > 0)
880 ? std::optional<unsigned>(ASTArgumentIndex - 1)
881 : std::nullopt;
882 }
883
884 unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override {
885 // For member operator calls argument 0 on the expression corresponds
886 // to implicit this-parameter on the declaration.
887 return CallArgumentIndex + 1;
888 }
889
893};
894
895/// Represents an implicit call to a C++ destructor.
896///
897/// This can occur at the end of a scope (for automatic objects), at the end
898/// of a full-expression (for temporaries), or as part of a delete.
900 friend class CallEventManager;
901
902protected:
903 using DtorDataTy = llvm::PointerIntPair<const MemRegion *, 1, bool>;
904
905 /// Creates an implicit destructor.
906 ///
907 /// \param DD The destructor that will be called.
908 /// \param Trigger The statement whose completion causes this destructor call.
909 /// \param Target The object region to be destructed.
910 /// \param St The path-sensitive state at this point in the program.
911 /// \param SF The stack frame at this point in the program.
912 /// \param ElemRef The reference to this destructor in the CFG.
913 ///
914 /// FIXME: Eventually we want to drop \param Target and deduce it from
915 /// \param ElemRef. To do that we need to migrate the logic for target
916 /// region lookup from ExprEngine::ProcessImplicitDtor() and make it
917 /// independent from ExprEngine.
918 CXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger,
919 const MemRegion *Target, bool IsBaseDestructor,
920 ProgramStateRef St, const StackFrame *SF,
922 : CXXInstanceCall(DD, St, SF, ElemRef) {
923 Data = DtorDataTy(Target, IsBaseDestructor).getOpaqueValue();
924 Location = Trigger->getEndLoc();
925 }
926
928
929 void cloneTo(void *Dest) const override {
930 new (Dest) CXXDestructorCall(*this);
931 }
932
933public:
934 SourceRange getSourceRange() const override { return Location; }
935 unsigned getNumArgs() const override { return 0; }
936
938
939 /// Returns the value of the implicit 'this' object.
940 SVal getCXXThisVal() const override;
941
942 /// Returns true if this is a call to a base class destructor.
943 bool isBaseDestructor() const {
944 return DtorDataTy::getFromOpaqueValue(Data).getInt();
945 }
946
947 Kind getKind() const override { return CE_CXXDestructor; }
948 StringRef getKindAsString() const override { return "CXXDestructorCall"; }
949
950 static bool classof(const CallEvent *CA) {
951 return CA->getKind() == CE_CXXDestructor;
952 }
953};
954
955/// Represents any constructor invocation. This includes regular constructors
956/// and inherited constructors.
958protected:
960 ProgramStateRef St, const StackFrame *SF,
962 : AnyFunctionCall(E, St, SF, ElemRef) {
964 // Target may be null when the region is unknown.
965 Data = Target;
966 }
967
969 ValueList &Values,
970 RegionAndSymbolInvalidationTraits *ETraits) const override;
971
972 void getInitialStackFrameContents(const StackFrame *CalleeSF,
973 BindingsTy &Bindings) const override;
974
975public:
976 /// Returns the value of the implicit 'this' object.
977 SVal getCXXThisVal() const;
978
979 static bool classof(const CallEvent *Call) {
980 return Call->getKind() >= CE_BEG_CXX_CONSTRUCTOR_CALLS &&
982 }
983};
984
985/// Represents a call to a C++ constructor.
986///
987/// Example: \c T(1)
989 friend class CallEventManager;
990
991protected:
992 /// Creates a constructor call.
993 ///
994 /// \param CE The constructor expression as written in the source.
995 /// \param Target The region where the object should be constructed. If NULL,
996 /// a new symbolic region will be used.
997 /// \param St The path-sensitive state at this point in the program.
998 /// \param SF The stack frame at this point in the program.
999 /// \param ElemRef The reference to this constructor in the CFG.
1000 ///
1001 /// FIXME: Eventually we want to drop \param Target and deduce it from
1002 /// \param ElemRef.
1004 ProgramStateRef St, const StackFrame *SF,
1006 : AnyCXXConstructorCall(CE, Target, St, SF, ElemRef) {}
1007
1009
1010 void cloneTo(void *Dest) const override {
1011 new (Dest) CXXConstructorCall(*this);
1012 }
1013
1014public:
1018
1019 const CXXConstructorDecl *getDecl() const override {
1020 return getOriginExpr()->getConstructor();
1021 }
1022
1023 unsigned getNumArgs() const override { return getOriginExpr()->getNumArgs(); }
1024
1025 const Expr *getArgExpr(unsigned Index) const override {
1026 return getOriginExpr()->getArg(Index);
1027 }
1028
1029 Kind getKind() const override { return CE_CXXConstructor; }
1030 StringRef getKindAsString() const override { return "CXXConstructorCall"; }
1031
1032 static bool classof(const CallEvent *CA) {
1033 return CA->getKind() == CE_CXXConstructor;
1034 }
1035};
1036
1037/// Represents a call to a C++ inherited constructor.
1038///
1039/// Example: \c class T : public S { using S::S; }; T(1);
1040///
1041// Note, it is difficult to model the parameters. This is one of the reasons
1042// why we skip analysis of inheriting constructors as top-level functions.
1043// CXXInheritedCtorInitExpr doesn't take arguments and doesn't model parameter
1044// initialization because there is none: the arguments in the outer
1045// CXXConstructExpr directly initialize the parameters of the base class
1046// constructor, and no copies are made. (Making a copy of the parameter is
1047// incorrect, at least if it's done in an observable way.) The derived class
1048// constructor doesn't even exist in the formal model.
1049/// E.g., in:
1050///
1051/// struct X { X *p = this; ~X() {} };
1052/// struct A { A(X x) : b(x.p == &x) {} bool b; };
1053/// struct B : A { using A::A; };
1054/// B b = X{};
1055///
1056/// ... b.b is initialized to true.
1058 friend class CallEventManager;
1059
1060protected:
1066
1068 default;
1069
1070 void cloneTo(void *Dest) const override {
1071 new (Dest) CXXInheritedConstructorCall(*this);
1072 }
1073
1074public:
1078
1079 const CXXConstructorDecl *getDecl() const override {
1080 return getOriginExpr()->getConstructor();
1081 }
1082
1083 /// Obtain the stack frame of the inheriting constructor. Argument expressions
1084 /// can be found on the call site of that stack frame.
1085 const StackFrame *getInheritingStackFrame() const;
1086
1087 /// Obtain the CXXConstructExpr for the sub-class that inherited the current
1088 /// constructor (possibly indirectly). It's the statement that contains
1089 /// argument expressions.
1091 return cast<CXXConstructExpr>(getInheritingStackFrame()->getCallSite());
1092 }
1093
1094 unsigned getNumArgs() const override {
1096 }
1097
1098 const Expr *getArgExpr(unsigned Index) const override {
1099 return getInheritingConstructor()->getArg(Index);
1100 }
1101
1102 SVal getArgSVal(unsigned Index) const override {
1103 return getState()->getSVal(getArgExpr(Index),
1104 getInheritingStackFrame()->getParent());
1105 }
1106
1107 Kind getKind() const override { return CE_CXXInheritedConstructor; }
1108 StringRef getKindAsString() const override {
1109 return "CXXInheritedConstructorCall";
1110 }
1111
1112 static bool classof(const CallEvent *CA) {
1113 return CA->getKind() == CE_CXXInheritedConstructor;
1114 }
1115};
1116
1117/// Represents the memory allocation call in a C++ new-expression.
1118///
1119/// This is a call to "operator new".
1121 friend class CallEventManager;
1122
1123protected:
1125 const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
1126 : AnyFunctionCall(E, St, SF, ElemRef) {}
1128
1129 void cloneTo(void *Dest) const override {
1130 new (Dest) CXXAllocatorCall(*this);
1131 }
1132
1133public:
1134 const CXXNewExpr *getOriginExpr() const override {
1136 }
1137
1138 const FunctionDecl *getDecl() const override {
1139 return getOriginExpr()->getOperatorNew();
1140 }
1141
1146
1147 /// Number of non-placement arguments to the call. It is equal to 2 for
1148 /// C++17 aligned operator new() calls that have alignment implicitly
1149 /// passed as the second argument, and to 1 for other operator new() calls.
1150 unsigned getNumImplicitArgs() const {
1152 }
1153
1154 unsigned getNumArgs() const override {
1156 }
1157
1158 bool isArray() const { return getOriginExpr()->isArray(); }
1159
1160 std::optional<const clang::Expr *> getArraySizeExpr() const {
1161 return getOriginExpr()->getArraySize();
1162 }
1163
1165 assert(isArray() && "The allocator call doesn't allocate and array!");
1166
1167 return getState()->getSVal(*getArraySizeExpr(), getStackFrame());
1168 }
1169
1170 const Expr *getArgExpr(unsigned Index) const override {
1171 // The first argument of an allocator call is the size of the allocation.
1172 if (Index < getNumImplicitArgs())
1173 return nullptr;
1175 }
1176
1177 /// Number of placement arguments to the operator new() call. For example,
1178 /// standard std::nothrow operator new and standard placement new both have
1179 /// 1 implicit argument (size) and 1 placement argument, while regular
1180 /// operator new() has 1 implicit argument and 0 placement arguments.
1181 const Expr *getPlacementArgExpr(unsigned Index) const {
1182 return getOriginExpr()->getPlacementArg(Index);
1183 }
1184
1185 Kind getKind() const override { return CE_CXXAllocator; }
1186 StringRef getKindAsString() const override { return "CXXAllocatorCall"; }
1187
1188 static bool classof(const CallEvent *CE) {
1189 return CE->getKind() == CE_CXXAllocator;
1190 }
1191};
1192
1193/// Represents the memory deallocation call in a C++ delete-expression.
1194///
1195/// This is a call to "operator delete".
1196// FIXME: CXXDeleteExpr isn't present for custom delete operators, or even for
1197// some those that are in the standard library, like the no-throw or align_val
1198// versions.
1199// Some pointers:
1200// http://lists.llvm.org/pipermail/cfe-dev/2020-April/065080.html
1201// clang/test/Analysis/cxx-dynamic-memory-analysis-order.cpp
1202// clang/unittests/StaticAnalyzer/CallEventTest.cpp
1204 friend class CallEventManager;
1205
1206protected:
1208 const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
1209 : AnyFunctionCall(E, St, SF, ElemRef) {}
1211
1212 void cloneTo(void *Dest) const override {
1213 new (Dest) CXXDeallocatorCall(*this);
1214 }
1215
1216public:
1217 const CXXDeleteExpr *getOriginExpr() const override {
1219 }
1220
1221 const FunctionDecl *getDecl() const override {
1222 return getOriginExpr()->getOperatorDelete();
1223 }
1224
1225 unsigned getNumArgs() const override { return getDecl()->getNumParams(); }
1226
1227 const Expr *getArgExpr(unsigned Index) const override {
1228 // CXXDeleteExpr's only have a single argument.
1229 return getOriginExpr()->getArgument();
1230 }
1231
1232 Kind getKind() const override { return CE_CXXDeallocator; }
1233 StringRef getKindAsString() const override { return "CXXDeallocatorCall"; }
1234
1235 static bool classof(const CallEvent *CE) {
1236 return CE->getKind() == CE_CXXDeallocator;
1237 }
1238};
1239
1240/// Represents the ways an Objective-C message send can occur.
1241//
1242// Note to maintainers: OCM_Message should always be last, since it does not
1243// need to fit in the Data field's low bits.
1245
1246/// Represents any expression that calls an Objective-C method.
1247///
1248/// This includes all of the kinds listed in ObjCMessageKind.
1250 friend class CallEventManager;
1251
1252 const PseudoObjectExpr *getContainingPseudoObjectExpr() const;
1253
1254protected:
1256 const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
1257 : CallEvent(Msg, St, SF, 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 {
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
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.
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 StackFrame *CalleeSF,
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
1367 using CallEventTemplateTy = SimpleFunctionCall;
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 StackFrame *SF,
1384 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1385 "CallEvent subclasses are not all the same size");
1386 return new (allocate()) T(A, St, SF, ElemRef);
1387 }
1388
1389 template <typename T, typename Arg1, typename Arg2>
1390 T *create(Arg1 A1, Arg2 A2, ProgramStateRef St, const StackFrame *SF,
1392 static_assert(sizeof(T) == sizeof(CallEventTemplateTy),
1393 "CallEvent subclasses are not all the same size");
1394 return new (allocate()) T(A1, A2, St, SF, ElemRef);
1395 }
1396
1397 template <typename T, typename Arg1, typename Arg2, typename Arg3>
1398 T *create(Arg1 A1, Arg2 A2, Arg3 A3, ProgramStateRef St, const StackFrame *SF,
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, SF, 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 StackFrame *SF, 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, SF, ElemRef);
1412 }
1413
1414public:
1415 CallEventManager(llvm::BumpPtrAllocator &alloc);
1416
1417 /// Gets an outside caller given a callee context.
1418 CallEventRef<> getCaller(const StackFrame *CalleeSF, ProgramStateRef State);
1419
1420 /// Gets a call event for a function call, Objective-C method call,
1421 /// a 'new', or a 'delete' call.
1422 CallEventRef<> getCall(const Stmt *S, ProgramStateRef State,
1423 const StackFrame *SF,
1425
1426 CallEventRef<> getSimpleCall(const CallExpr *E, ProgramStateRef State,
1427 const StackFrame *SF,
1429
1430 CallEventRef<ObjCMethodCall>
1432 const StackFrame *SF,
1434 return create<ObjCMethodCall>(E, State, SF, ElemRef);
1435 }
1436
1439 ProgramStateRef State, const StackFrame *SF,
1441 return create<CXXConstructorCall>(E, Target, State, SF, ElemRef);
1442 }
1443
1446 const MemRegion *Target, ProgramStateRef State,
1447 const StackFrame *SF,
1449 return create<CXXInheritedConstructorCall>(E, Target, State, SF, ElemRef);
1450 }
1451
1454 const MemRegion *Target, bool IsBase,
1455 ProgramStateRef State, const StackFrame *SF,
1457 return create<CXXDestructorCall>(DD, Trigger, Target, IsBase, State, SF,
1458 ElemRef);
1459 }
1460
1463 const StackFrame *SF,
1465 return create<CXXAllocatorCall>(E, State, SF, ElemRef);
1466 }
1467
1470 const StackFrame *SF,
1472 return create<CXXDeallocatorCall>(E, State, SF, ElemRef);
1473 }
1474};
1475
1476template <typename T>
1478 assert(isa<T>(*this) && "Cloning to unrelated type");
1479 static_assert(sizeof(T) == sizeof(CallEvent),
1480 "Subclasses may not add fields");
1481
1482 if (NewState == State)
1483 return cast<T>(this);
1484
1485 CallEventManager &Mgr = State->getStateManager().getCallEventManager();
1486 T *Copy = static_cast<T *>(Mgr.allocate());
1487 cloneTo(Copy);
1488 assert(Copy->getKind() == this->getKind() && "Bad copy");
1489
1490 Copy->State = NewState;
1491 return Copy;
1492}
1493
1494inline void CallEvent::Release() const {
1495 assert(RefCount > 0 && "Reference count is already zero.");
1496 --RefCount;
1497
1498 if (RefCount > 0)
1499 return;
1500
1501 CallEventManager &Mgr = State->getStateManager().getCallEventManager();
1502 Mgr.reclaim(this);
1503
1504 this->~CallEvent();
1505}
1506
1507} // namespace ento
1508
1509} // namespace clang
1510
1511namespace llvm {
1512
1513// Support isa<>, cast<>, and dyn_cast<> for CallEventRef.
1514template <class T> struct simplify_type<clang::ento::CallEventRef<T>> {
1515 using SimpleType = const T *;
1516
1518 return Val.get();
1519 }
1520};
1521
1522} // namespace llvm
1523
1524#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.
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:245
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:4826
bool isConversionFromLambda() const
Definition Decl.h:4969
ElementRefImpl< true > ConstCFGElementRef
Definition CFG.h:976
Represents a call to a C++ constructor.
Definition ExprCXX.h:1553
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition ExprCXX.h:1696
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1616
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1693
Represents a C++ constructor within a class.
Definition DeclCXX.h:2642
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2631
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2670
Represents a C++ destructor within a class.
Definition DeclCXX.h:2907
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1756
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1793
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:184
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2150
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2360
bool isArray() const
Definition ExprCXX.h:2469
unsigned getNumImplicitArgs() const
Definition ExprCXX.h:2516
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:2474
Expr * getPlacementArg(unsigned I)
Definition ExprCXX.h:2508
unsigned getNumPlacementArgs() const
Definition ExprCXX.h:2499
FunctionDecl * getOperatorNew() const
Definition ExprCXX.h:2464
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:86
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Definition ExprCXX.h:116
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:1744
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:3012
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition Expr.h:3216
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3203
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:448
This represents one expression.
Definition Expr.h:114
Represents a function declaration or definition.
Definition Decl.h:2071
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3888
One of these records is kept for each identifier that is lexed.
Represents an ObjC class declaration.
Definition DeclObjC.h:1160
An expression that sends a message to the given Objective-C object or class.
Definition ExprObjC.h:972
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition ExprObjC.h:1435
ObjCMethodFamily getMethodFamily() const
Definition ExprObjC.h:1415
Selector getSelector() const
Definition ExprObjC.cpp:301
bool isInstanceMessage() const
Determine whether this is an instance message to either a computed object or to super.
Definition ExprObjC.h:1288
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
Definition ExprObjC.cpp:322
const ObjCMethodDecl * getMethodDecl() const
Definition ExprObjC.h:1396
unsigned getNumArgs() const
Return the number of actual arguments in this message, not counting the receiver.
Definition ExprObjC.h:1422
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:734
Represents a parameter to a function.
Definition Decl.h:1832
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:6890
A (possibly-)qualified type.
Definition TypeBase.h:938
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.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
A trivial tuple used to represent a source range.
It represents a stack frame of the call stack.
Stmt - This represents one statement.
Definition Stmt.h:85
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:367
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
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:725
Represents a variable declaration or definition.
Definition Decl.h:934
AnyCXXConstructorCall(const Expr *E, const MemRegion *Target, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:959
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.
void getInitialStackFrameContents(const StackFrame *CalleeSF, 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 *Call)
Definition CallEvent.h:979
AnyFunctionCall(const Decl *D, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:512
void getInitialStackFrameContents(const StackFrame *CalleeSF, BindingsTy &Bindings) const override
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:520
AnyFunctionCall(const Expr *E, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:509
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
static bool classof(const CallEvent *CA)
Definition CallEvent.h:533
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:612
BlockCall(const CallExpr *CE, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:585
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:590
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:669
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:601
RuntimeDefinition getRuntimeDefinition() const override
Returns the definition of the function or method that will be called.
Definition CallEvent.h:639
void getInitialStackFrameContents(const StackFrame *CalleeSF, BindingsTy &Bindings) const override
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
const BlockDataRegion * getBlockRegion() const
Returns the region associated with this instance of the block.
bool isConversionFromLambda() const
Definition CallEvent.h:619
friend class CallEventManager
Definition CallEvent.h:582
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:676
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:629
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:603
BlockCall(const BlockCall &Other)=default
static bool classof(const CallEvent *CA)
Definition CallEvent.h:679
StringRef getKindAsString() const override
Definition CallEvent.h:677
const CallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:597
BlockDataRegion - A region that represents a block instance.
Definition MemRegion.h:712
LLVM_ATTRIBUTE_RETURNS_NONNULL const BlockDecl * getDecl() const
Definition MemRegion.h:741
llvm::iterator_range< referenced_vars_iterator > referenced_vars() const
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1154
unsigned getNumImplicitArgs() const
Number of non-placement arguments to the call.
Definition CallEvent.h:1150
const CXXNewExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1134
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1185
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1170
std::optional< const clang::Expr * > getArraySizeExpr() const
Definition CallEvent.h:1160
static bool classof(const CallEvent *CE)
Definition CallEvent.h:1188
const Expr * getPlacementArgExpr(unsigned Index) const
Number of placement arguments to the operator new() call.
Definition CallEvent.h:1181
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:1138
StringRef getKindAsString() const override
Definition CallEvent.h:1186
CXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1124
SVal getObjectUnderConstruction() const
Definition CallEvent.h:1142
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1129
CXXConstructorCall(const CXXConstructExpr *CE, const MemRegion *Target, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Creates a constructor call.
Definition CallEvent.h:1003
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:1019
const CXXConstructExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1015
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1029
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1010
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1025
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1023
StringRef getKindAsString() const override
Definition CallEvent.h:1030
static bool classof(const CallEvent *CA)
Definition CallEvent.h:1032
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1232
const CXXDeleteExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1217
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1227
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1225
CXXDeallocatorCall(const CXXDeallocatorCall &Other)=default
static bool classof(const CallEvent *CE)
Definition CallEvent.h:1235
StringRef getKindAsString() const override
Definition CallEvent.h:1233
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:1221
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1212
CXXDeallocatorCall(const CXXDeleteExpr *E, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1207
static bool classof(const CallEvent *CA)
Definition CallEvent.h:950
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:943
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:935
CXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBaseDestructor, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Creates an implicit destructor.
Definition CallEvent.h:918
llvm::PointerIntPair< const MemRegion *, 1, bool > DtorDataTy
Definition CallEvent.h:903
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:934
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:929
StringRef getKindAsString() const override
Definition CallEvent.h:948
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:947
CXXInheritedConstructorCall(const CXXInheritedConstructorCall &Other)=default
static bool classof(const CallEvent *CA)
Definition CallEvent.h:1112
const CXXInheritedCtorInitExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:1075
const StackFrame * getInheritingStackFrame() const
Obtain the stack frame of the inheriting constructor.
StringRef getKindAsString() const override
Definition CallEvent.h:1108
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1107
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:1094
CXXInheritedConstructorCall(const CXXInheritedCtorInitExpr *CE, const MemRegion *Target, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1061
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:1098
const CXXConstructorDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
Definition CallEvent.h:1079
const CXXConstructExpr * getInheritingConstructor() const
Obtain the CXXConstructExpr for the sub-class that inherited the current constructor (possibly indire...
Definition CallEvent.h:1090
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:1070
SVal getArgSVal(unsigned Index) const override
Returns the value of a given argument at the time of the call.
Definition CallEvent.h:1102
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 CallExpr *CE, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:686
CXXInstanceCall(const CXXInstanceCall &Other)=default
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:717
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:705
CXXInstanceCall(const FunctionDecl *D, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:689
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
void getInitialStackFrameContents(const StackFrame *CalleeSF, 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:819
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:809
static bool classof(const CallEvent *CA)
Definition CallEvent.h:830
friend class CallEventManager
Definition CallEvent.h:798
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:813
const Expr * getCXXThisExpr() const override
Returns the expression representing the implicit 'this' object.
StringRef getKindAsString() const override
Definition CallEvent.h:828
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:806
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:827
CXXMemberCall(const CXXMemberCallExpr *CE, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:801
std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override
Some calls have parameter numbering mismatched from argument numbering.
Definition CallEvent.h:876
OverloadedOperatorKind getOverloadedOperator() const
Definition CallEvent.h:890
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:862
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:858
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:868
StringRef getKindAsString() const override
Definition CallEvent.h:869
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:849
const CXXOperatorCallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:854
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:884
static bool classof(const CallEvent *CA)
Definition CallEvent.h:871
CXXMemberOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:843
std::optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override
Some calls have parameter numbering mismatched from argument numbering.
Definition CallEvent.h:770
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:749
OverloadedOperatorKind getOverloadedOperator() const
Definition CallEvent.h:782
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:758
StringRef getKindAsString() const override
Definition CallEvent.h:787
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:786
CXXStaticOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:743
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
Definition CallEvent.h:764
const CXXOperatorCallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:754
static bool classof(const CallEvent *CA)
Definition CallEvent.h:789
unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override
Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices.
Definition CallEvent.h:777
Manages the lifetime of CallEvent objects.
Definition CallEvent.h:1361
CallEventRef getCaller(const StackFrame *CalleeSF, ProgramStateRef State)
Gets an outside caller given a callee context.
CallEventRef< CXXConstructorCall > getCXXConstructorCall(const CXXConstructExpr *E, const MemRegion *Target, ProgramStateRef State, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1438
CallEventRef< CXXAllocatorCall > getCXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef State, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1462
CallEventRef< CXXInheritedConstructorCall > getCXXInheritedConstructorCall(const CXXInheritedCtorInitExpr *E, const MemRegion *Target, ProgramStateRef State, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1445
CallEventManager(llvm::BumpPtrAllocator &alloc)
CallEventRef< CXXDeallocatorCall > getCXXDeallocatorCall(const CXXDeleteExpr *E, ProgramStateRef State, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1469
CallEventRef< CXXDestructorCall > getCXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBase, ProgramStateRef State, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1453
CallEventRef< ObjCMethodCall > getObjCMethodCall(const ObjCMessageExpr *E, ProgramStateRef State, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1431
CallEventRef getCall(const Stmt *S, ProgramStateRef State, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Gets a call event for a function call, Objective-C method call, a 'new', or a 'delete' call.
CallEventRef getSimpleCall(const CallExpr *E, ProgramStateRef State, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
CallEventRef(const T *Call)
Definition CallEvent.h:84
CallEventRef(const CallEventRef &Orig)
Definition CallEvent.h:85
CallEventRef & operator=(const CallEventRef &)=delete
CallEventRef< T > cloneWithState(ProgramStateRef State) const
Definition CallEvent.h:91
Represents an abstract call to a function or method along a particular path.
Definition CallEvent.h:152
virtual SourceRange getArgSourceRange(unsigned Index) const
Returns the source range for errors associated with this argument.
virtual void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const
Used to specify non-argument regions that will be invalidated as a result of this call.
Definition CallEvent.h:210
virtual StringRef getKindAsString() const =0
void setForeign(bool B) const
Definition CallEvent.h:239
SVal getSVal(const Expr *E) const
Get the value of arbitrary expressions at this point in the path.
Definition CallEvent.h:201
virtual const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:260
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:221
CallEventKind Kind
Definition CallEvent.h:154
CallEventRef cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
Definition CallEvent.h:390
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:496
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:361
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:442
QualType getResultType() const
Returns the result type, adjusted for references.
Definition CallEvent.cpp:70
CallEventRef< T > cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
Definition CallEvent.h:1477
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:181
llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn > param_type_iterator
Definition CallEvent.h:484
const StackFrame * getCalleeStackFrame(unsigned BlockCount) const
Returns the callee stack frame.
bool isInSystemHeader() const
Returns true if the callee is known to be from a system header.
Definition CallEvent.h:272
bool isForeign() const
Definition CallEvent.h:235
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:334
CallEvent(const CallEvent &Original)
Definition CallEvent.h:192
param_type_iterator param_type_begin() const
Returns an iterator over the types of the call's formal parameters.
Definition CallEvent.h:492
SourceLocation Location
Definition CallEvent.h:170
std::pair< SVal, SVal > FrameBindingTy
Definition CallEvent.h:377
const StackFrame * getStackFrame() const
The stack frame in which the call is being evaluated.
Definition CallEvent.h:248
ProgramPoint getProgramPoint(bool IsPreVisit=false, const ProgramPointTag *Tag=nullptr) const
Returns an appropriate ProgramPoint for this call.
virtual ~CallEvent()=default
CallEvent(const Decl *D, ProgramStateRef state, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:187
static QualType getDeclaredResultType(const Decl *D)
Returns the result type of a function or method declaration.
CallEvent(const Expr *E, ProgramStateRef state, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:183
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:243
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:303
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
virtual void getInitialStackFrameContents(const StackFrame *CalleeSF, BindingsTy &Bindings) const =0
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
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:430
SmallVectorImpl< FrameBindingTy > BindingsTy
Definition CallEvent.h:378
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:233
const CFGBlock::ConstCFGElementRef & getCFGElementRef() const
Definition CallEvent.h:250
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:205
virtual SourceRange getSourceRange() const
Returns a source range for the entire call, suitable for outputting in diagnostics.
Definition CallEvent.h:294
virtual unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const
Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices.
Definition CallEvent.h:449
bool isValid() const =delete
static std::optional< SVal > getObjectUnderConstruction(ProgramStateRef State, const ConstructionContextItem &Item, const StackFrame *SF)
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:97
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.
static bool classof(const CallEvent *CA)
Definition CallEvent.h:1349
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...
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
ArrayRef< ParmVarDecl * > parameters() const override
Return call's formal parameters.
StringRef getKindAsString() const override
Definition CallEvent.h:1347
void getInitialStackFrameContents(const StackFrame *CalleeSF, BindingsTy &Bindings) const override
Populates the given SmallVector with the bindings in the callee's stack frame at the start of this ca...
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:1263
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
Definition CallEvent.h:1307
ObjCMethodCall(const ObjCMessageExpr *Msg, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:1255
bool isReceiverSelfOrSuper() const
Checks if the receiver refers to 'self' or 'super'.
Selector getSelector() const
Definition CallEvent.h:1296
const ObjCPropertyDecl * getAccessedProperty() const
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:1346
ParamVarRegion - Represents a region for parameters.
Definition MemRegion.h:1072
Information about invalidation for a particular region/symbol.
Definition MemRegion.h:1663
Defines the runtime definition of the called function.
Definition CallEvent.h:109
RuntimeDefinition(const Decl *InD, const MemRegion *InR)
Definition CallEvent.h:128
RuntimeDefinition(const Decl *InD, bool Foreign)
Definition CallEvent.h:127
const MemRegion * getDispatchRegion()
When other definitions are possible, returns the region whose runtime type determines the method defi...
Definition CallEvent.h:140
RuntimeDefinition(const Decl *InD)
Definition CallEvent.h:126
bool mayHaveOtherDefinitions()
Check if the definition we have is precise.
Definition CallEvent.h:136
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition SVals.h:57
Represents a C function or static C++ member function call.
Definition CallEvent.h:542
static bool classof(const CallEvent *CA)
Definition CallEvent.h:573
Kind getKind() const override
Returns the kind of call this is.
Definition CallEvent.h:570
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
Definition CallEvent.h:564
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
Definition CallEvent.h:551
SimpleFunctionCall(const SimpleFunctionCall &Other)=default
StringRef getKindAsString() const override
Definition CallEvent.h:571
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:566
const CallExpr * getOriginExpr() const override
Returns the expression whose value will be the result of this call.
Definition CallEvent.h:556
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
SimpleFunctionCall(const CallExpr *CE, ProgramStateRef St, const StackFrame *SF, CFGBlock::ConstCFGElementRef ElemRef)
Definition CallEvent.h:546
const VarDecl * getDecl() const override=0
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
@ CE_END_CXX_CONSTRUCTOR_CALLS
Definition CallEvent.h:70
@ CE_CXXInheritedConstructor
Definition CallEvent.h:68
@ CE_END_FUNCTION_CALLS
Definition CallEvent.h:74
@ CE_CXXStaticOperator
Definition CallEvent.h:61
@ CE_END_CXX_INSTANCE_CALLS
Definition CallEvent.h:66
@ CE_CXXDestructor
Definition CallEvent.h:64
@ CE_BEG_CXX_INSTANCE_CALLS
Definition CallEvent.h:65
@ CE_CXXDeallocator
Definition CallEvent.h:72
@ CE_CXXAllocator
Definition CallEvent.h:71
@ CE_CXXConstructor
Definition CallEvent.h:67
@ CE_BEG_CXX_CONSTRUCTOR_CALLS
Definition CallEvent.h:69
@ CE_CXXMemberOperator
Definition CallEvent.h:63
@ CE_BEG_FUNCTION_CALLS
Definition CallEvent.h:73
ObjCMessageKind
Represents the ways an Objective-C message send can occur.
Definition CallEvent.h:1244
Top level wrappers for InstallAPI frontend operations.
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:1787
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
static SimpleType getSimplifiedValue(clang::ento::CallEventRef< T > Val)
Definition CallEvent.h:1517