20 using namespace clang;
26 const CheckerBase *Checker;
31 : BR(br), Checker(checker), AC(ac) {}
33 void VisitStmt(
Stmt *S) { VisitChildren(S); }
34 void VisitChildren(
Stmt *S);
38 void WalkAST::VisitChildren(
Stmt *S) {
64 PathDiagnosticLocation ELoc =
66 BR.EmitBasicReport(AC->getDecl(), Checker,
67 "Potential unintended use of sizeof() on pointer type",
69 "The code calls sizeof() on a pointer type. " 70 "This can produce an unexpected result.",
80 class SizeofPointerChecker :
public Checker<check::ASTCodeBody> {
82 void checkASTCodeBody(
const Decl *D, AnalysisManager& mgr,
83 BugReporter &BR)
const {
84 WalkAST walker(BR,
this, mgr.getAnalysisDeclContext(D));
90 void ento::registerSizeofPointerChecker(CheckerManager &mgr) {
91 mgr.registerChecker<SizeofPointerChecker>();
94 bool ento::shouldRegisterSizeofPointerChecker(
const LangOptions &LO) {
A (possibly-)qualified type.
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Stmt - This represents one statement.
Decl - This represents one declaration (or definition), e.g.
AnalysisDeclContext contains the context data for the function or method under analysis.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const char *const LogicError
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand...
This represents one expression.
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
UnaryExprOrTypeTrait getKind() const
bool isArgumentType() const
Dataflow Directional Tag Classes.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
bool isPointerType() const
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...