clang
10.0.0git
|
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "InterCheckerAPI.h"
#include "clang/AST/Attr.h"
#include "clang/AST/ParentMap.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Lexer.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "AllocationState.h"
#include <climits>
#include <utility>
Go to the source code of this file.
Namespaces | |
clang | |
Dataflow Directional Tag Classes. | |
clang::ento | |
clang::ento::allocation_state | |
Macros | |
#define | CASE(ID) case ID: OS << #ID; break; |
#define | REGISTER_CHECKER(name) |
Enumerations | |
enum | AllocationFamily |
enum | OwnershipAfterReallocKind |
The state of 'fromPtr' after reallocation is known to have failed. More... | |
enum | MemoryOperationKind |
Functions | |
static AllocationFamily | getAllocationFamily (const MemFunctionInfoTy &MemFunctionInfo, CheckerContext &C, const Stmt *S) |
Determine family of a deallocation expression. More... | |
static bool | printAllocDeallocName (raw_ostream &os, CheckerContext &C, const Expr *E) |
Print names of allocators and deallocators. More... | |
static void | printExpectedAllocName (raw_ostream &os, const MemFunctionInfoTy &MemFunctionInfo, CheckerContext &C, const Expr *E) |
Print expected name of an allocator based on the deallocator's family derived from the DeallocExpr. More... | |
static void | printExpectedDeallocName (raw_ostream &os, AllocationFamily Family) |
Print expected name of a deallocator based on the allocator's family. More... | |
static bool | isReleased (SymbolRef Sym, CheckerContext &C) |
Check if the memory associated with this symbol was released. More... | |
static ProgramStateRef | MallocUpdateRefState (CheckerContext &C, const Expr *E, ProgramStateRef State, AllocationFamily Family=AF_Malloc, Optional< SVal > RetVal=None) |
Update the RefState to reflect the new memory allocation. More... | |
static QualType | getDeepPointeeType (QualType T) |
static bool | hasNonTrivialConstructorCall (const CXXNewExpr *NE) |
static bool | isKnownDeallocObjCMethodName (const ObjCMethodCall &Call) |
static Optional< bool > | getFreeWhenDoneArg (const ObjCMethodCall &Call) |
static bool | didPreviousFreeFail (ProgramStateRef State, SymbolRef Sym, SymbolRef &RetStatusSymbol) |
Checks if the previous call to free on the given symbol failed - if free failed, returns true. More... | |
static bool | checkIfNewOrNewArrayFamily (const RefState *RS) |
static SymbolRef | findFailedReallocSymbol (ProgramStateRef currState, ProgramStateRef prevState) |
static bool | isReferenceCountingPointerDestructor (const CXXDestructorDecl *DD) |
ProgramStateRef | clang::ento::allocation_state::markReleased (ProgramStateRef State, SymbolRef Sym, const Expr *Origin) |
#define CASE | ( | ID | ) | case ID: OS << #ID; break; |
#define REGISTER_CHECKER | ( | name | ) |
Definition at line 3415 of file MallocChecker.cpp.
enum AllocationFamily |
Definition at line 80 of file MallocChecker.cpp.
|
strong |
Definition at line 274 of file MallocChecker.cpp.
The state of 'fromPtr' after reallocation is known to have failed.
Definition at line 225 of file MallocChecker.cpp.
|
static |
Definition at line 3110 of file MallocChecker.cpp.
References clang::ento::PSK_DirectEscapeOnCall, and State.
|
static |
Checks if the previous call to free on the given symbol failed - if free failed, returns true.
Also, returns the corresponding return value symbol.
Definition at line 1619 of file MallocChecker.cpp.
References Ret().
Referenced by printExpectedDeallocName().
|
static |
Definition at line 3145 of file MallocChecker.cpp.
Referenced by isReferenceCountingPointerDestructor().
|
static |
Determine family of a deallocation expression.
Definition at line 1633 of file MallocChecker.cpp.
References clang::CallExpr::getCalleeDecl(), clang::FunctionDecl::getOverloadedOperator(), clang::CXXNewExpr::isArray(), and clang::CXXDeleteExpr::isArrayForm().
Referenced by printExpectedAllocName(), and printExpectedDeallocName().
Definition at line 1295 of file MallocChecker.cpp.
References clang::Type::getPointeeType().
Referenced by hasNonTrivialConstructorCall().
|
static |
Definition at line 1449 of file MallocChecker.cpp.
References clang::CallExpr::getArg(), clang::ObjCMethodCall::getArgExpr(), clang::Selector::getNameForSlot(), clang::Selector::getNumArgs(), clang::ObjCMethodCall::getOriginExpr(), clang::ObjCMethodCall::getSelector(), clang::Expr::getType(), isKnownDeallocObjCMethodName(), clang::ento::Loc::isLocType(), MallocUpdateRefState(), and State.
Referenced by isReleased().
|
static |
NE
has an argument of a pointer/reference to a record type. Definition at line 1306 of file MallocChecker.cpp.
References clang::CXXNewExpr::getAllocatedType(), clang::CXXDeleteExpr::getArgument(), clang::CXXNewExpr::getArraySize(), clang::Type::getAsCXXRecordDecl(), clang::Decl::getASTContext(), clang::CXXNewExpr::getConstructExpr(), clang::CXXConstructExpr::getConstructor(), getDeepPointeeType(), clang::CXXDeleteExpr::getOperatorDelete(), clang::CXXNewExpr::getOperatorNew(), clang::Type::getPointeeType(), clang::CharUnits::getQuantity(), clang::ASTContext::getTypeSizeInChars(), clang::CXXNewExpr::isArray(), clang::ParentMap::isConsumedExpr(), clang::QualType::isNull(), MallocUpdateRefState(), clang::interp::NE(), clang::FunctionDecl::parameters(), State, and clang::Target.
|
static |
Definition at line 1437 of file MallocChecker.cpp.
References clang::Selector::getNameForSlot(), and clang::ObjCMethodCall::getSelector().
Referenced by getFreeWhenDoneArg(), and isReleased().
|
static |
Definition at line 3159 of file MallocChecker.cpp.
References findFailedReallocSymbol(), clang::ento::allocation_state::getContainerObjRegion(), clang::NamedDecl::getIdentifier(), getName(), clang::LocationContext::getParent(), clang::CXXMethodDecl::getParent(), clang::LocationContext::isParentOf(), isReleased(), clang::Normal, clang::ento::OS, P, clang::ProgramPoint::PostImplicitCallKind, clang::CodeGen::state, and State.
|
static |
Check if the memory associated with this symbol was released.
Definition at line 2803 of file MallocChecker.cpp.
References clang::CallExpr::arguments(), clang::DeclaratorDecl::getBeginLoc(), clang::FunctionDecl::getBody(), getFreeWhenDoneArg(), clang::NamedDecl::getIdentifier(), clang::IdentifierInfo::getName(), clang::CallExpr::getNumArgs(), clang::NamedDecl::getQualifiedNameAsString(), clang::Stmt::getSourceRange(), clang::Lexer::getSourceText(), clang::CharSourceRange::getTokenRange(), isKnownDeallocObjCMethodName(), clang::OMF_init, clang::CodeGen::state, and State.
Referenced by isReferenceCountingPointerDestructor().
|
static |
Update the RefState to reflect the new memory allocation.
The optional RetVal
parameter specifies the newly allocated pointer value; if unspecified, the value of expression E
is used.
Definition at line 1557 of file MallocChecker.cpp.
References clang::CallExpr::getArg(), clang::CallExpr::getNumArgs(), and State.
Referenced by getFreeWhenDoneArg(), and hasNonTrivialConstructorCall().
Print names of allocators and deallocators.
Definition at line 1682 of file MallocChecker.cpp.
References clang::CallExpr::getDirectCallee(), clang::CXXDeleteExpr::getOperatorDelete(), clang::CXXNewExpr::getOperatorNew(), clang::getOperatorSpelling(), clang::FunctionDecl::getOverloadedOperator(), and clang::Decl::print().
Referenced by printExpectedDeallocName().
|
static |
Print expected name of an allocator based on the deallocator's family derived from the DeallocExpr.
Definition at line 1722 of file MallocChecker.cpp.
References getAllocationFamily().
Referenced by printExpectedDeallocName().
|
static |
Print expected name of a deallocator based on the allocator's family.
Definition at line 1738 of file MallocChecker.cpp.
References abs(), clang::ento::PathDiagnosticLocation::createBegin(), didPreviousFreeFail(), getAllocationFamily(), clang::CallExpr::getArg(), clang::BlockExpr::getBlockDecl(), clang::ASTContext::getCharWidth(), clang::ento::allocation_state::getInnerPointerBRVisitor(), clang::NamedDecl::getName(), clang::CallExpr::getNumArgs(), clang::ReturnStmt::getRetValue(), clang::Stmt::getSourceRange(), clang::LocationContext::getStackFrame(), clang::BlockDecl::hasCaptures(), clang::LocationContext::isParentOf(), Label, clang::ento::categories::MemoryError, Offset, printAllocDeallocName(), printExpectedAllocName(), clang::CodeGen::state, State, and V.