forked from OSchip/llvm-project
DirectIvarAssignment: Replace vtable'd objects with simple functions.
Avoids unnecessary static constructors. llvm-svn: 188083
This commit is contained in:
parent
f103c2f946
commit
27bc504285
|
@ -40,21 +40,15 @@ namespace {
|
||||||
///
|
///
|
||||||
/// Checks for the init, dealloc, and any other functions that might be allowed
|
/// Checks for the init, dealloc, and any other functions that might be allowed
|
||||||
/// to perform direct instance variable assignment based on their name.
|
/// to perform direct instance variable assignment based on their name.
|
||||||
struct MethodFilter {
|
static bool DefaultMethodFilter(const ObjCMethodDecl *M) {
|
||||||
virtual ~MethodFilter() {}
|
if (M->getMethodFamily() == OMF_init || M->getMethodFamily() == OMF_dealloc ||
|
||||||
virtual bool operator()(ObjCMethodDecl *M) {
|
M->getMethodFamily() == OMF_copy ||
|
||||||
if (M->getMethodFamily() == OMF_init ||
|
M->getMethodFamily() == OMF_mutableCopy ||
|
||||||
M->getMethodFamily() == OMF_dealloc ||
|
M->getSelector().getNameForSlot(0).find("init") != StringRef::npos ||
|
||||||
M->getMethodFamily() == OMF_copy ||
|
M->getSelector().getNameForSlot(0).find("Init") != StringRef::npos)
|
||||||
M->getMethodFamily() == OMF_mutableCopy ||
|
return true;
|
||||||
M->getSelector().getNameForSlot(0).find("init") != StringRef::npos ||
|
return false;
|
||||||
M->getSelector().getNameForSlot(0).find("Init") != StringRef::npos)
|
}
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static MethodFilter DefaultMethodFilter;
|
|
||||||
|
|
||||||
class DirectIvarAssignment :
|
class DirectIvarAssignment :
|
||||||
public Checker<check::ASTDecl<ObjCImplementationDecl> > {
|
public Checker<check::ASTDecl<ObjCImplementationDecl> > {
|
||||||
|
@ -89,7 +83,7 @@ class DirectIvarAssignment :
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MethodFilter *ShouldSkipMethod;
|
bool (*ShouldSkipMethod)(const ObjCMethodDecl *);
|
||||||
|
|
||||||
DirectIvarAssignment() : ShouldSkipMethod(&DefaultMethodFilter) {}
|
DirectIvarAssignment() : ShouldSkipMethod(&DefaultMethodFilter) {}
|
||||||
|
|
||||||
|
@ -230,22 +224,16 @@ void ento::registerDirectIvarAssignment(CheckerManager &mgr) {
|
||||||
|
|
||||||
// Register the checker that checks for direct accesses in functions annotated
|
// Register the checker that checks for direct accesses in functions annotated
|
||||||
// with __attribute__((annotate("objc_no_direct_instance_variable_assignment"))).
|
// with __attribute__((annotate("objc_no_direct_instance_variable_assignment"))).
|
||||||
namespace {
|
static bool AttrFilter(const ObjCMethodDecl *M) {
|
||||||
struct InvalidatorMethodFilter : MethodFilter {
|
for (specific_attr_iterator<AnnotateAttr>
|
||||||
virtual ~InvalidatorMethodFilter() {}
|
AI = M->specific_attr_begin<AnnotateAttr>(),
|
||||||
virtual bool operator()(ObjCMethodDecl *M) {
|
AE = M->specific_attr_end<AnnotateAttr>();
|
||||||
for (specific_attr_iterator<AnnotateAttr>
|
AI != AE; ++AI) {
|
||||||
AI = M->specific_attr_begin<AnnotateAttr>(),
|
const AnnotateAttr *Ann = *AI;
|
||||||
AE = M->specific_attr_end<AnnotateAttr>(); AI != AE; ++AI) {
|
if (Ann->getAnnotation() == "objc_no_direct_instance_variable_assignment")
|
||||||
const AnnotateAttr *Ann = *AI;
|
return false;
|
||||||
if (Ann->getAnnotation() == "objc_no_direct_instance_variable_assignment")
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
};
|
return true;
|
||||||
|
|
||||||
InvalidatorMethodFilter AttrFilter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ento::registerDirectIvarAssignmentForAnnotatedFunctions(
|
void ento::registerDirectIvarAssignmentForAnnotatedFunctions(
|
||||||
|
|
Loading…
Reference in New Issue