20#include "llvm/ADT/SmallString.h"
21#include "llvm/Support/raw_ostream.h"
29 const CheckerBase *Checker;
30 AnalysisDeclContext* AC;
35 inline bool isPointerSize(
const Type *
T) {
44 inline bool hasPointerToPointerSizedType(
const Expr *E) {
48 const Type *TP =
T.getTypePtr();
55 if (isPointerSize(TElem))
63 return isPointerSize(TElem);
68 return static_cast<bool>(
73 WalkAST(BugReporter &br,
const CheckerBase *checker, AnalysisDeclContext *ac)
74 : BR(br), Checker(checker), AC(ac), ASTC(AC->getASTContext()),
75 PtrWidth(ASTC.getTargetInfo().getPointerWidth(
LangAS::
Default)) {}
78 void VisitChildren(Stmt *S);
79 void VisitStmt(Stmt *S) { VisitChildren(S); }
80 void VisitCallExpr(CallExpr *CE);
96void WalkAST::VisitCallExpr(
CallExpr *CE) {
101 const Expr *Arg =
nullptr;
104 if (Name ==
"CFArrayCreate" || Name ==
"CFSetCreate") {
109 if (hasPointerToPointerSizedType(Arg))
111 }
else if (Name ==
"CFDictionaryCreate") {
117 if (hasPointerToPointerSizedType(Arg)) {
121 if (hasPointerToPointerSizedType(Arg))
128 assert(ArgNum == 1 || ArgNum == 2);
130 SmallString<64> BufName;
131 llvm::raw_svector_ostream OsName(BufName);
132 OsName <<
" Invalid use of '" << Name <<
"'" ;
134 SmallString<256> Buf;
135 llvm::raw_svector_ostream Os(Buf);
138 Os <<
" The " << ((ArgNum == 1) ?
"second" :
"third") <<
" argument to '"
139 << Name <<
"' must be a C array of pointer-sized values, not '"
142 PathDiagnosticLocation CELoc =
153void WalkAST::VisitChildren(Stmt *S) {
160class ObjCContainersASTChecker :
public Checker<check::ASTCodeBody> {
163 void checkASTCodeBody(
const Decl *D, AnalysisManager& Mgr,
164 BugReporter &BR)
const {
171void ento::registerObjCContainersASTChecker(CheckerManager &mgr) {
175bool ento::shouldRegisterObjCContainersASTChecker(
const CheckerManager &mgr) {
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
static StringRef getCalleeName(CallExpr *CE)
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
const Decl * getDecl() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
@ NPC_ValueDependentIsNull
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant.
Represents a function declaration or definition.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
AnalysisDeclContext * getAnalysisDeclContext(const Decl *D)
const SourceManager & getSourceManager()
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerFrontend *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges={}, ArrayRef< FixItHint > Fixits={})
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
Defines the clang::TargetInfo interface.
const char *const CoreFoundationObjectiveC
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
@ Type
The name was classified as a type.
LangAS
Defines the address space values used by the address space qualifier of QualType.