[clang] 500479d - [analyzer][DirectIvarAssignment] Turn DirectIvarAssignmentForAnnotatedFunctions into a checker option
Kirstóf Umann via cfe-commits
cfe-commits at lists.llvm.org
Tue May 19 06:41:59 PDT 2020
Author: Kirstóf Umann
Date: 2020-05-19T15:41:43+02:00
New Revision: 500479dba33ae03644313e34d10c013371b5215b
URL: https://github.com/llvm/llvm-project/commit/500479dba33ae03644313e34d10c013371b5215b
DIFF: https://github.com/llvm/llvm-project/commit/500479dba33ae03644313e34d10c013371b5215b.diff
LOG: [analyzer][DirectIvarAssignment] Turn DirectIvarAssignmentForAnnotatedFunctions into a checker option
Since this is an alpha checker, I don't worry about backward compatibility :)
Differential Revision: https://reviews.llvm.org/D78121
Added:
Modified:
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m
Removed:
################################################################################
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 5cf32ac03436..cc6952b55810 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1118,13 +1118,15 @@ def MissingInvalidationMethod : Checker<"MissingInvalidationMethod">,
def DirectIvarAssignment : Checker<"DirectIvarAssignment">,
HelpText<"Check for direct assignments to instance variables">,
- Documentation<HasAlphaDocumentation>;
-
-def DirectIvarAssignmentForAnnotatedFunctions :
- Checker<"DirectIvarAssignmentForAnnotatedFunctions">,
- HelpText<"Check for direct assignments to instance variables in the methods "
- "annotated with objc_no_direct_instance_variable_assignment">,
- Dependencies<[DirectIvarAssignment]>,
+ CheckerOptions<[
+ CmdLineOption<Boolean,
+ "AnnotatedFunctions",
+ "Check for direct assignments to instance variables in the "
+ "methods annotated with "
+ "objc_no_direct_instance_variable_assignment",
+ "false",
+ InAlpha>
+ ]>,
Documentation<HasAlphaDocumentation>;
} // end "alpha.osx.cocoa"
diff --git a/clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp b/clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
index d09f0da3faac..df88b71ff063 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
@@ -219,19 +219,12 @@ static bool AttrFilter(const ObjCMethodDecl *M) {
// Register the checker that checks for direct accesses in all functions,
// except for the initialization and copy routines.
void ento::registerDirectIvarAssignment(CheckerManager &mgr) {
- mgr.registerChecker<DirectIvarAssignment>();
+ auto Chk = mgr.registerChecker<DirectIvarAssignment>();
+ if (mgr.getAnalyzerOptions().getCheckerBooleanOption(Chk,
+ "AnnotatedFunctions"))
+ Chk->ShouldSkipMethod = &AttrFilter;
}
bool ento::shouldRegisterDirectIvarAssignment(const CheckerManager &mgr) {
return true;
}
-
-void ento::registerDirectIvarAssignmentForAnnotatedFunctions(
- CheckerManager &mgr) {
- mgr.getChecker<DirectIvarAssignment>()->ShouldSkipMethod = &AttrFilter;
-}
-
-bool ento::shouldRegisterDirectIvarAssignmentForAnnotatedFunctions(
- const CheckerManager &mgr) {
- return true;
-}
diff --git a/clang/test/Analysis/analyzer-config.c b/clang/test/Analysis/analyzer-config.c
index b94f618d7492..3a6b4d20b1b1 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -8,6 +8,7 @@
// CHECK-NEXT: alpha.clone.CloneChecker:MinimumCloneComplexity = 50
// CHECK-NEXT: alpha.clone.CloneChecker:ReportNormalClones = true
// CHECK-NEXT: alpha.cplusplus.STLAlgorithmModeling:AggressiveStdFindModeling = false
+// CHECK-NEXT: alpha.osx.cocoa.DirectIvarAssignment:AnnotatedFunctions = false
// CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtExec = 0x04
// CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtRead = 0x01
// CHECK-NEXT: alpha.security.taint.TaintPropagation:Config = ""
diff --git a/clang/test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m b/clang/test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m
index 782fcecd43f9..4d3ee072ca29 100644
--- a/clang/test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m
+++ b/clang/test/Analysis/objc/direct-ivar-assignment-in-annotated-functions.m
@@ -1,4 +1,8 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.osx.cocoa.DirectIvarAssignmentForAnnotatedFunctions -verify -fblocks %s
+// RUN: %clang_analyze_cc1 -verify -fblocks %s \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=alpha.osx.cocoa.DirectIvarAssignment \
+// RUN: -analyzer-config \
+// RUN: alpha.osx.cocoa.DirectIvarAssignment:AnnotatedFunctions=true
typedef signed char BOOL;
@protocol NSObject - (BOOL)isEqual:(id)object; @end
@@ -60,4 +64,4 @@ - (void) someMethodNotAnnaotated: (MyClass*)In {
_nonSynth = 0; // no-warning
}
- at end
\ No newline at end of file
+ @end
More information about the cfe-commits
mailing list