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