clang 10.0.0git

Functions
CastSizeChecker.cpp File Reference
`#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"`
`#include "clang/AST/CharUnits.h"`
`#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"`
`#include "clang/StaticAnalyzer/Core/Checker.h"`
`#include "clang/StaticAnalyzer/Core/CheckerManager.h"`
`#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"`
Include dependency graph for CastSizeChecker.cpp:

Go to the source code of this file.

## Functions
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. More...

## Function Documentation

## ◆ evenFlexibleArraySize()

static bool evenFlexibleArraySize | ( | ASTContext & | Ctx,
|  | CharUnits | RegionSize,
|  | CharUnits | TypeSize,
|  | QualType | ToPointeeTy
| ) |  |
| static

Check if we are casting to a struct with a flexible array at the end.

struct foo {
size_t len;
struct bar data[];
};

or

struct foo {
size_t len;
struct bar data[0];
}

In these cases it is also valid to allocate size of struct foo + a multiple of struct bar.

Definition at line 48 of file CastSizeChecker.cpp.

References End, clang::RecordDecl::field_begin(), clang::RecordDecl::field_end(), clang::CharUnits::fromQuantity(), clang::Type::getArrayElementTypeNoTypeQual(), clang::Type::getAs(), clang::ASTContext::getAsConstantArrayType(), clang::ASTContext::getCanonicalType(), clang::RecordType::getDecl(), clang::PointerType::getPointeeType(), clang::Stmt::getSourceRange(), clang::CastExpr::getSubExpr(), clang::Expr::getType(), clang::QualType::getTypePtr(), clang::ASTContext::getTypeSizeInChars(), clang::RecordDecl::hasFlexibleArrayMember(), clang::Type::isIncompleteType(), clang::CharUnits::isNegative(), clang::CharUnits::isZero(), clang::Last, and clang::CodeGen::state.