31 using namespace clang;
36 class NonnullGlobalConstantsChecker :
public Checker<check::Location> {
42 NonnullGlobalConstantsChecker() {}
44 void checkLocation(
SVal l,
bool isLoad,
const Stmt *S,
48 void initIdentifierInfo(
ASTContext &Ctx)
const;
50 bool isGlobalConstString(
SVal V)
const;
52 bool isNonnullType(
QualType Ty)
const;
58 void NonnullGlobalConstantsChecker::initIdentifierInfo(
ASTContext &Ctx)
const {
63 CFStringRefII = &Ctx.
Idents.
get(
"CFStringRef");
64 CFBooleanRefII = &Ctx.
Idents.
get(
"CFBooleanRef");
68 void NonnullGlobalConstantsChecker::checkLocation(
SVal location,
bool isLoad,
72 if (!isLoad || !location.
isValid())
78 if (isGlobalConstString(location)) {
92 bool NonnullGlobalConstantsChecker::isGlobalConstString(
SVal V)
const {
96 auto *Region = dyn_cast<
VarRegion>(RegionVal->getAsRegion());
106 if (isNonnullType(Ty) && HasConst)
110 while (
auto *
T = dyn_cast<TypedefType>(Ty)) {
111 Ty =
T->getDecl()->getUnderlyingType();
116 if (isNonnullType(Ty) && HasConst)
123 bool NonnullGlobalConstantsChecker::isNonnullType(
QualType Ty)
const {
128 if (
auto *
T = dyn_cast<ObjCObjectPointerType>(Ty)) {
129 return T->getInterfaceDecl() &&
130 T->getInterfaceDecl()->getIdentifier() == NSStringII;
131 }
else if (
auto *
T = dyn_cast<TypedefType>(Ty)) {
133 return II == CFStringRefII || II == CFBooleanRefII;
138 void ento::registerNonnullGlobalConstantsChecker(
CheckerManager &Mgr) {
A (possibly-)qualified type.
Stmt - This represents one statement.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
ExplodedNode * addTransition(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generates a new transition in the program state graph (ExplodedGraph).
Decl - This represents one declaration (or definition), e.g.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const FunctionProtoType * T
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
bool isConstQualified() const
Determine whether this type is const-qualified.
CHECKER * registerChecker()
Used to register checkers.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Dataflow Directional Tag Classes.
ASTContext & getASTContext()
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
const ProgramStateRef & getState() const
bool isPointerType() const