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 return Left % FlexSize == 0;
114 const llvm::APSInt *extentInt = svalBuilder.
getKnownValue(state, extent);
122 if (typeSize.isZero())
125 if (regionSize % typeSize == 0)
133 BT.reset(
new BuiltinBug(
this,
"Cast region with wrong size.",
134 "Cast a region whose size is not a multiple"
135 " of the destination type size."));
136 auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), errorNode);
137 R->addRange(CE->getSourceRange());
bool isNegative() const
isNegative - Test whether the quantity is less than zero.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
MemRegion - The root abstract class for all memory regions.
ExplodedNode * generateErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a transition to a node that will be used to report an error.
bool hasFlexibleArrayMember() const
The base class of the type hierarchy.
field_iterator field_begin() const
RecordDecl - Represents a struct/union/class.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
CharUnits - This is an opaque type for sizes expressed in character units.
RecordDecl * getDecl() const
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
field_iterator field_end() const
SymbolicRegion - A special, "non-concrete" region.
Expr - This represents one expression.
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)
Check if we are casting to a struct with a flexible array at the end.
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
Retrieves a pointer to the underlying (unqualified) type.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
ASTContext & getASTContext()
bool isZero() const
isZero - Test whether the quantity equals zero.
detail::InMemoryDirectory::const_iterator E
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
const T * getAs() const
Member-template getAs<specific type>'.
SValBuilder & getSValBuilder()
virtual const llvm::APSInt * getKnownValue(ProgramStateRef state, SVal val)=0
Evaluates a given SVal.
Represents the canonical version of C arrays with a specified constant size.
const LocationContext * getLocationContext() const