21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/Support/raw_ostream.h"
24 using namespace clang;
36 inline bool isPointerSize(
const Type *T) {
41 return (ASTC.getTypeSize(T) == PtrWidth);
45 inline bool hasPointerToPointerSizedType(
const Expr *
E) {
56 if (isPointerSize(TElem))
64 return isPointerSize(TElem);
69 return static_cast<bool>(
75 : BR(br),
Checker(checker), AC(ac), ASTC(AC->getASTContext()),
76 PtrWidth(ASTC.getTargetInfo().getPointerWidth(0)) {}
79 void VisitChildren(
Stmt *
S);
80 void VisitStmt(
Stmt *
S) { VisitChildren(S); }
97 void WalkAST::VisitCallExpr(
CallExpr *CE) {
102 const Expr *Arg =
nullptr;
105 if (Name.equals(
"CFArrayCreate") || Name.equals(
"CFSetCreate")) {
110 if (hasPointerToPointerSizedType(Arg))
112 }
else if (Name.equals(
"CFDictionaryCreate")) {
118 if (hasPointerToPointerSizedType(Arg)) {
122 if (hasPointerToPointerSizedType(Arg))
129 assert(ArgNum == 1 || ArgNum == 2);
132 llvm::raw_svector_ostream OsName(BufName);
133 OsName <<
" Invalid use of '" << Name <<
"'" ;
136 llvm::raw_svector_ostream Os(Buf);
139 Os <<
" The "<< ((ArgNum == 1) ?
"second" :
"third") <<
" argument to '"
140 << Name <<
"' must be a C array of pointer-sized values, not '"
145 BR.EmitBasicReport(AC->getDecl(),
Checker, OsName.str(),
147 Arg->getSourceRange());
154 void WalkAST::VisitChildren(
Stmt *
S) {
155 for (
Stmt *Child : S->children())
161 class ObjCContainersASTChecker :
public Checker<check::ASTCodeBody> {
167 walker.Visit(D->getBody());
172 void ento::registerObjCContainersASTChecker(
CheckerManager &mgr) {
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
const char *const CoreFoundationObjectiveC
A (possibly-)qualified type.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
std::string getAsString() const
The base class of the type hierarchy.
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
One of these records is kept for each identifier that is lexed.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
AnalysisDeclContext contains the context data for the function or method under analysis.
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
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)
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Expr - This represents one expression.
StringRef getName() const
Return the actual identifier string.
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
BugReporter is a utility class for generating PathDiagnostics for analysis.
static StringRef getCalleeName(CallExpr *CE)
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
CHECKER * registerChecker()
Used to register checkers.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
detail::InMemoryDirectory::const_iterator E
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
bool isNull() const
Return true if this QualType doesn't point to a type yet.