OSDN Git Service

[analyzer][NSOrCFError] Don't emit diagnostics under the name osx.NSOrCFErrorDerefChecker
authorKirstóf Umann <dkszelethus@gmail.com>
Tue, 14 Apr 2020 15:44:44 +0000 (17:44 +0200)
committerKirstóf Umann <dkszelethus@gmail.com>
Tue, 19 May 2020 22:05:49 +0000 (00:05 +0200)
Differential Revision: https://reviews.llvm.org/D78123

clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
clang/test/Analysis/incorrect-checker-names.mm

index 5f68788..90c5583 100644 (file)
@@ -144,14 +144,14 @@ namespace {
 
 class NSErrorDerefBug : public BugType {
 public:
-  NSErrorDerefBug(const CheckerBase *Checker)
+  NSErrorDerefBug(const CheckerNameRef Checker)
       : BugType(Checker, "NSError** null dereference",
                 "Coding conventions (Apple)") {}
 };
 
 class CFErrorDerefBug : public BugType {
 public:
-  CFErrorDerefBug(const CheckerBase *Checker)
+  CFErrorDerefBug(const CheckerNameRef Checker)
       : BugType(Checker, "CFErrorRef* null dereference",
                 "Coding conventions (Apple)") {}
 };
@@ -166,9 +166,9 @@ class NSOrCFErrorDerefChecker
   mutable std::unique_ptr<NSErrorDerefBug> NSBT;
   mutable std::unique_ptr<CFErrorDerefBug> CFBT;
 public:
-  bool ShouldCheckNSError, ShouldCheckCFError;
-  NSOrCFErrorDerefChecker() : NSErrorII(nullptr), CFErrorII(nullptr),
-                              ShouldCheckNSError(0), ShouldCheckCFError(0) { }
+  DefaultBool ShouldCheckNSError, ShouldCheckCFError;
+  CheckerNameRef NSErrorName, CFErrorName;
+  NSOrCFErrorDerefChecker() : NSErrorII(nullptr), CFErrorII(nullptr) {}
 
   void checkLocation(SVal loc, bool isLoad, const Stmt *S,
                      CheckerContext &C) const;
@@ -276,12 +276,12 @@ void NSOrCFErrorDerefChecker::checkEvent(ImplicitNullDerefEvent event) const {
   BugType *bug = nullptr;
   if (isNSError) {
     if (!NSBT)
-      NSBT.reset(new NSErrorDerefBug(this));
+      NSBT.reset(new NSErrorDerefBug(NSErrorName));
     bug = NSBT.get();
   }
   else {
     if (!CFBT)
-      CFBT.reset(new CFErrorDerefBug(this));
+      CFBT.reset(new CFErrorDerefBug(CFErrorName));
     bug = CFBT.get();
   }
   BR.emitReport(
@@ -331,6 +331,7 @@ void ento::registerNSErrorChecker(CheckerManager &mgr) {
   mgr.registerChecker<NSErrorMethodChecker>();
   NSOrCFErrorDerefChecker *checker = mgr.getChecker<NSOrCFErrorDerefChecker>();
   checker->ShouldCheckNSError = true;
+  checker->NSErrorName = mgr.getCurrentCheckerName();
 }
 
 bool ento::shouldRegisterNSErrorChecker(const CheckerManager &mgr) {
@@ -341,6 +342,7 @@ void ento::registerCFErrorChecker(CheckerManager &mgr) {
   mgr.registerChecker<CFErrorFunctionChecker>();
   NSOrCFErrorDerefChecker *checker = mgr.getChecker<NSOrCFErrorDerefChecker>();
   checker->ShouldCheckCFError = true;
+  checker->CFErrorName = mgr.getCurrentCheckerName();
 }
 
 bool ento::shouldRegisterCFErrorChecker(const CheckerManager &mgr) {
index f14eea9..11b6a21 100644 (file)
@@ -106,9 +106,19 @@ typedef struct __CFError* CFErrorRef;
 
 void foo(CFErrorRef* error) { // expected-warning{{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred [osx.coreFoundation.CFError]}}
   // FIXME: This shouldn't be tied to a modeling checker.
-  *error = 0;  // expected-warning {{Potential null dereference.  According to coding standards documented in CoreFoundation/CFError.h the parameter may be null [osx.NSOrCFErrorDerefChecker]}}
+  *error = 0; // expected-warning {{Potential null dereference.  According to coding standards documented in CoreFoundation/CFError.h the parameter may be null [osx.coreFoundation.CFError]}}
 }
 
+@interface A
+- (void)myMethodWhichMayFail:(NSError **)error;
+@end
+
+@implementation A
+- (void)myMethodWhichMayFail:(NSError **)error {                  // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occurred [osx.cocoa.NSError]}}
+  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference.  According to coding standards in 'Creating and Returning NSError Objects' the parameter may be null [osx.cocoa.NSError]}}
+}
+@end
+
 bool write_into_out_param_on_success(OS_RETURNS_RETAINED OSObject **obj);
 
 void use_out_param_leak() {