36class NonnullGlobalConstantsChecker :
public Checker<check::Location> {
43 NonnullGlobalConstantsChecker() {}
45 void checkLocation(
SVal l,
bool isLoad,
const Stmt *S,
49 void initIdentifierInfo(
ASTContext &Ctx)
const;
51 bool isGlobalConstString(
SVal V)
const;
53 bool isNonnullType(
QualType Ty)
const;
59void NonnullGlobalConstantsChecker::initIdentifierInfo(
ASTContext &Ctx)
const {
64 CFStringRefII = &Ctx.
Idents.
get(
"CFStringRef");
65 CFBooleanRefII = &Ctx.
Idents.
get(
"CFBooleanRef");
66 CFNullRefII = &Ctx.
Idents.
get(
"CFNullRef");
70void NonnullGlobalConstantsChecker::checkLocation(
SVal location,
bool isLoad,
73 initIdentifierInfo(
C.getASTContext());
74 if (!isLoad || !location.
isValid())
79 if (isGlobalConstString(location)) {
81 std::optional<DefinedOrUnknownSVal> Constr =
88 C.addTransition(OutputState);
95bool NonnullGlobalConstantsChecker::isGlobalConstString(
SVal V)
const {
99 auto *Region = dyn_cast<VarRegion>(RegionVal->getAsRegion());
104 if (!
Decl->hasGlobalStorage())
109 if (isNonnullType(Ty) && HasConst)
114 if (
const auto *AT = dyn_cast<AttributedType>(
T)) {
115 if (AT->getAttrKind() == attr::TypeNonNull)
117 Ty = AT->getModifiedType();
118 }
else if (
const auto *ET = dyn_cast<ElaboratedType>(
T)) {
119 const auto *TT = dyn_cast<TypedefType>(ET->getNamedType());
122 Ty = TT->getDecl()->getUnderlyingType();
126 if (isNonnullType(Ty) && HasConst)
136bool NonnullGlobalConstantsChecker::isNonnullType(
QualType Ty)
const {
141 if (
auto *
T = dyn_cast<ObjCObjectPointerType>(Ty)) {
142 return T->getInterfaceDecl() &&
143 T->getInterfaceDecl()->getIdentifier() == NSStringII;
146 return II == CFStringRefII || II == CFBooleanRefII || II == CFNullRefII;
151void ento::registerNonnullGlobalConstantsChecker(
CheckerManager &Mgr) {
155bool ento::shouldRegisterNonnullGlobalConstantsChecker(
const CheckerManager &mgr) {
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Decl - This represents one declaration (or definition), e.g.
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
A (possibly-)qualified type.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstQualified() const
Determine whether this type is const-qualified.
Stmt - This represents one statement.
The base class of the type hierarchy.
bool isPointerType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
const T * getAs() const
Member-template getAs<specific type>'.
Represents a variable declaration or definition.
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T