21 using namespace clang;
25 class CastSizeChecker :
public Checker< check::PreStmt<CastExpr> > {
26 mutable std::unique_ptr<BuiltinBug> BT;
59 for (; Iter !=
End; ++Iter)
61 assert(Last &&
"empty structs should already be handled");
68 if (ArrayTy->getSize() == 1 && TypeSize > FlexSize)
70 else if (ArrayTy->getSize() != 0)
85 if (Left % FlexSize == 0)
117 const llvm::APSInt *extentInt = svalBuilder.
getKnownValue(state, extent);
125 if (typeSize.isZero())
128 if (regionSize % typeSize == 0)
136 BT.reset(
new BuiltinBug(
this,
"Cast region with wrong size.",
137 "Cast a region whose size is not a multiple"
138 " of the destination type size."));
139 auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), errorNode);
140 R->addRange(CE->getSourceRange());
bool isNegative() const
isNegative - Test whether the quantity is less than zero.
MemRegion - The root abstract class for all memory regions.
bool hasFlexibleArrayMember() const
field_iterator field_begin() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
RecordDecl * getDecl() const
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...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
field_iterator field_end() const
ExplodedNode * generateSink(ProgramStateRef State=nullptr, ExplodedNode *Pred=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a sink node. Generating a sink stops exploration of the given path.
const ProgramStateRef & getState() const
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
static bool evenFlexibleArraySize(ASTContext &Ctx, CharUnits RegionSize, CharUnits TypeSize, QualType ToPointeeTy)
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
const Type * getTypePtr() const
const ConstantArrayType * getAsConstantArrayType(QualType T) const
const Type * getArrayElementTypeNoTypeQual() const
QualType getPointeeType() const
ASTContext & getASTContext()
bool isZero() const
isZero - Test whether the quantity equals zero.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
SValBuilder & getSValBuilder()
virtual const llvm::APSInt * getKnownValue(ProgramStateRef state, SVal val)=0
const LocationContext * getLocationContext() const