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);
76 : BR(br),
Checker(checker), AC(ac), ASTC(AC->getASTContext()),
77 PtrWidth(ASTC.getTargetInfo().getPointerWidth(0)) {}
80 void VisitChildren(
Stmt *
S);
81 void VisitStmt(
Stmt *
S) { VisitChildren(S); }
98 void WalkAST::VisitCallExpr(
CallExpr *CE) {
103 const Expr *Arg =
nullptr;
106 if (Name.equals(
"CFArrayCreate") || Name.equals(
"CFSetCreate")) {
111 if (hasPointerToPointerSizedType(Arg))
113 }
else if (Name.equals(
"CFDictionaryCreate")) {
119 if (hasPointerToPointerSizedType(Arg)) {
123 if (hasPointerToPointerSizedType(Arg))
130 assert(ArgNum == 1 || ArgNum == 2);
133 llvm::raw_svector_ostream OsName(BufName);
134 OsName <<
" Invalid use of '" << Name <<
"'" ;
137 llvm::raw_svector_ostream Os(Buf);
140 Os <<
" The "<< ((ArgNum == 1) ?
"second" :
"third") <<
" argument to '"
141 << Name <<
"' must be a C array of pointer-sized values, not '"
146 BR.EmitBasicReport(AC->getDecl(),
Checker, OsName.str(),
148 Arg->getSourceRange());
155 void WalkAST::VisitChildren(
Stmt *
S) {
156 for (
Stmt *Child : S->children())
162 class ObjCContainersASTChecker :
public Checker<check::ASTCodeBody> {
173 void ento::registerObjCContainersASTChecker(
CheckerManager &mgr) {
const char *const CoreFoundationObjectiveC
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
IdentifierInfo * getIdentifier() const
std::string getAsString() const
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Expr * IgnoreParenCasts() LLVM_READONLY
bool isIncompleteType(NamedDecl **Def=nullptr) const
Def If non-NULL, and the type refers to some kind of declaration that can be completed (such as a C s...
AnalysisDeclContext * getAnalysisDeclContext(const Decl *D)
QualType getPointeeType() const
StringRef getName() const
Return the actual identifier string.
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
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
virtual Stmt * getBody() const
const Type * getArrayElementTypeNoTypeQual() const
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
unsigned getNumArgs() const
Defines the clang::TargetInfo interface.
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.