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