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