llvm/clang/lib/StaticAnalyzer/Core/CallEvent.cpp

//===- CallEvent.cpp - Wrapper for all function and method calls ----------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
/// \file This file defines CallEvent and its subclasses, which represent path-
/// sensitive instances of different kinds of function and method calls
/// (C, C++, and Objective-C).
//
//===----------------------------------------------------------------------===//

#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/ParentMap.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/Type.h"
#include "clang/Analysis/AnalysisDeclContext.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/CFGStmtMap.h"
#include "clang/Analysis/PathDiagnostic.h"
#include "clang/Analysis/ProgramPoint.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "clang/CrossTU/CrossTranslationUnit.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/ImmutableList.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <optional>
#include <utility>

#define DEBUG_TYPE

usingnamespaceclang;
usingnamespaceento;

QualType CallEvent::getResultType() const {}

static bool isCallback(QualType T) {}

static bool isVoidPointerToNonConst(QualType T) {}

bool CallEvent::hasNonNullArgumentsWithType(bool (*Condition)(QualType)) const {}

bool CallEvent::hasNonZeroCallbackArg() const {}

bool CallEvent::hasVoidPointerToNonConstArg() const {}

bool CallEvent::isGlobalCFunction(StringRef FunctionName) const {}

AnalysisDeclContext *CallEvent::getCalleeAnalysisDeclContext() const {}

const StackFrameContext *
CallEvent::getCalleeStackFrame(unsigned BlockCount) const {}

const ParamVarRegion
*CallEvent::getParameterLocation(unsigned Index, unsigned BlockCount) const {}

/// Returns true if a type is a pointer-to-const or reference-to-const
/// with no further indirection.
static bool isPointerToConst(QualType Ty) {}

// Try to retrieve the function declaration and find the function parameter
// types which are pointers/references to a non-pointer const.
// We will not invalidate the corresponding argument regions.
static void findPtrToConstParams(llvm::SmallSet<unsigned, 4> &PreserveArgs,
                                 const CallEvent &Call) {}

ProgramStateRef CallEvent::invalidateRegions(unsigned BlockCount,
                                             ProgramStateRef Orig) const {}

ProgramPoint CallEvent::getProgramPoint(bool IsPreVisit,
                                        const ProgramPointTag *Tag) const {}

SVal CallEvent::getArgSVal(unsigned Index) const {}

SourceRange CallEvent::getArgSourceRange(unsigned Index) const {}

SVal CallEvent::getReturnValue() const {}

LLVM_DUMP_METHOD void CallEvent::dump() const {}

void CallEvent::dump(raw_ostream &Out) const {}

bool CallEvent::isCallStmt(const Stmt *S) {}

QualType CallEvent::getDeclaredResultType(const Decl *D) {}

bool CallEvent::isVariadic(const Decl *D) {}

static bool isTransparentUnion(QualType T) {}

// In some cases, symbolic cases should be transformed before we associate
// them with parameters.  This function incapsulates such cases.
static SVal processArgument(SVal Value, const Expr *ArgumentExpr,
                            const ParmVarDecl *Parameter, SValBuilder &SVB) {}

/// Cast the argument value to the type of the parameter at the function
/// declaration.
/// Returns the argument value if it didn't need a cast.
/// Or returns the cast argument if it needed a cast.
/// Or returns 'Unknown' if it would need a cast but the callsite and the
/// runtime definition don't match in terms of argument and parameter count.
static SVal castArgToParamTypeIfNeeded(const CallEvent &Call, unsigned ArgIdx,
                                       SVal ArgVal, SValBuilder &SVB) {}

static void addParameterValuesToBindings(const StackFrameContext *CalleeCtx,
                                         CallEvent::BindingsTy &Bindings,
                                         SValBuilder &SVB,
                                         const CallEvent &Call,
                                         ArrayRef<ParmVarDecl*> parameters) {}

const ConstructionContext *CallEvent::getConstructionContext() const {}

const CallEventRef<> CallEvent::getCaller() const {}

bool CallEvent::isCalledFromSystemHeader() const {}

std::optional<SVal> CallEvent::getReturnValueUnderConstruction() const {}

ArrayRef<ParmVarDecl*> AnyFunctionCall::parameters() const {}

RuntimeDefinition AnyFunctionCall::getRuntimeDefinition() const {}

void AnyFunctionCall::getInitialStackFrameContents(
                                        const StackFrameContext *CalleeCtx,
                                        BindingsTy &Bindings) const {}

bool AnyFunctionCall::argumentsMayEscape() const {}

const FunctionDecl *SimpleFunctionCall::getDecl() const {}

const FunctionDecl *CXXInstanceCall::getDecl() const {}

void CXXInstanceCall::getExtraInvalidatedValues(
    ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const {}

SVal CXXInstanceCall::getCXXThisVal() const {}

RuntimeDefinition CXXInstanceCall::getRuntimeDefinition() const {}

void CXXInstanceCall::getInitialStackFrameContents(
                                            const StackFrameContext *CalleeCtx,
                                            BindingsTy &Bindings) const {}

const Expr *CXXMemberCall::getCXXThisExpr() const {}

RuntimeDefinition CXXMemberCall::getRuntimeDefinition() const {}

const Expr *CXXMemberOperatorCall::getCXXThisExpr() const {}

const BlockDataRegion *BlockCall::getBlockRegion() const {}

ArrayRef<ParmVarDecl*> BlockCall::parameters() const {}

void BlockCall::getExtraInvalidatedValues(ValueList &Values,
                  RegionAndSymbolInvalidationTraits *ETraits) const {}

void BlockCall::getInitialStackFrameContents(const StackFrameContext *CalleeCtx,
                                             BindingsTy &Bindings) const {}

SVal AnyCXXConstructorCall::getCXXThisVal() const {}

void AnyCXXConstructorCall::getExtraInvalidatedValues(ValueList &Values,
                           RegionAndSymbolInvalidationTraits *ETraits) const {}

void AnyCXXConstructorCall::getInitialStackFrameContents(
                                             const StackFrameContext *CalleeCtx,
                                             BindingsTy &Bindings) const {}

const StackFrameContext *
CXXInheritedConstructorCall::getInheritingStackFrame() const {}

SVal CXXDestructorCall::getCXXThisVal() const {}

RuntimeDefinition CXXDestructorCall::getRuntimeDefinition() const {}

ArrayRef<ParmVarDecl*> ObjCMethodCall::parameters() const {}

void ObjCMethodCall::getExtraInvalidatedValues(
    ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const {}

SVal ObjCMethodCall::getReceiverSVal() const {}

bool ObjCMethodCall::isReceiverSelfOrSuper() const {}

SourceRange ObjCMethodCall::getSourceRange() const {}

ObjCMessageDataTy;

const PseudoObjectExpr *ObjCMethodCall::getContainingPseudoObjectExpr() const {}

static const Expr *
getSyntacticFromForPseudoObjectExpr(const PseudoObjectExpr *POE) {}

ObjCMessageKind ObjCMethodCall::getMessageKind() const {}

const ObjCPropertyDecl *ObjCMethodCall::getAccessedProperty() const {}

bool ObjCMethodCall::canBeOverridenInSubclass(ObjCInterfaceDecl *IDecl,
                                             Selector Sel) const {}

static const ObjCMethodDecl *findDefiningRedecl(const ObjCMethodDecl *MD) {}

struct PrivateMethodKey {};

namespace llvm {
template <> struct DenseMapInfo<PrivateMethodKey> {};
} // end namespace llvm

static const ObjCMethodDecl *
lookupRuntimeDefinition(const ObjCInterfaceDecl *Interface,
                        Selector LookupSelector, bool InstanceMethod) {}

RuntimeDefinition ObjCMethodCall::getRuntimeDefinition() const {}

bool ObjCMethodCall::argumentsMayEscape() const {}

void ObjCMethodCall::getInitialStackFrameContents(
                                             const StackFrameContext *CalleeCtx,
                                             BindingsTy &Bindings) const {}

CallEventRef<>
CallEventManager::getSimpleCall(const CallExpr *CE, ProgramStateRef State,
                                const LocationContext *LCtx,
                                CFGBlock::ConstCFGElementRef ElemRef) {}

CallEventRef<>
CallEventManager::getCaller(const StackFrameContext *CalleeCtx,
                            ProgramStateRef State) {}

CallEventRef<> CallEventManager::getCall(const Stmt *S, ProgramStateRef State,
                                         const LocationContext *LC,
                                         CFGBlock::ConstCFGElementRef ElemRef) {}