22 using namespace clang;
26 class CastToStructChecker :
public Checker< check::PreStmt<CastExpr> > {
27 mutable std::unique_ptr<BuiltinBug> BT;
34 void CastToStructChecker::checkPreStmt(
const CastExpr *CE,
44 if (!ToPTy || !OrigPTy)
62 new BuiltinBug(
this,
"Cast from non-struct type to struct type",
63 "Casting a non-structure type to a structure type "
64 "and accessing a field can lead to memory access "
65 "errors or data corruption."));
66 auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N);
67 R->addRange(CE->getSourceRange());
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isRecordType() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool isStructureOrClassType() const
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Expr - This represents one expression.
ExplodedNode * generateNonFatalErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a transition to a node that will be used to report an error.
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
QualType getPointeeType() const
ASTContext & getASTContext()
detail::InMemoryDirectory::const_iterator E
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...