Skip to content

Commit b47d1ba

Browse files
committed
[analyzer][NSOrCFError] Don't emit diagnostics under the name osx.NSOrCFErrorDerefChecker
Differential Revision: https://reviews.llvm.org/D78123
1 parent e665807 commit b47d1ba

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ namespace {
144144

145145
class NSErrorDerefBug : public BugType {
146146
public:
147-
NSErrorDerefBug(const CheckerBase *Checker)
147+
NSErrorDerefBug(const CheckerNameRef Checker)
148148
: BugType(Checker, "NSError** null dereference",
149149
"Coding conventions (Apple)") {}
150150
};
151151

152152
class CFErrorDerefBug : public BugType {
153153
public:
154-
CFErrorDerefBug(const CheckerBase *Checker)
154+
CFErrorDerefBug(const CheckerNameRef Checker)
155155
: BugType(Checker, "CFErrorRef* null dereference",
156156
"Coding conventions (Apple)") {}
157157
};
@@ -166,9 +166,9 @@ class NSOrCFErrorDerefChecker
166166
mutable std::unique_ptr<NSErrorDerefBug> NSBT;
167167
mutable std::unique_ptr<CFErrorDerefBug> CFBT;
168168
public:
169-
bool ShouldCheckNSError, ShouldCheckCFError;
170-
NSOrCFErrorDerefChecker() : NSErrorII(nullptr), CFErrorII(nullptr),
171-
ShouldCheckNSError(0), ShouldCheckCFError(0) { }
169+
DefaultBool ShouldCheckNSError, ShouldCheckCFError;
170+
CheckerNameRef NSErrorName, CFErrorName;
171+
NSOrCFErrorDerefChecker() : NSErrorII(nullptr), CFErrorII(nullptr) {}
172172

173173
void checkLocation(SVal loc, bool isLoad, const Stmt *S,
174174
CheckerContext &C) const;
@@ -276,12 +276,12 @@ void NSOrCFErrorDerefChecker::checkEvent(ImplicitNullDerefEvent event) const {
276276
BugType *bug = nullptr;
277277
if (isNSError) {
278278
if (!NSBT)
279-
NSBT.reset(new NSErrorDerefBug(this));
279+
NSBT.reset(new NSErrorDerefBug(NSErrorName));
280280
bug = NSBT.get();
281281
}
282282
else {
283283
if (!CFBT)
284-
CFBT.reset(new CFErrorDerefBug(this));
284+
CFBT.reset(new CFErrorDerefBug(CFErrorName));
285285
bug = CFBT.get();
286286
}
287287
BR.emitReport(
@@ -331,6 +331,7 @@ void ento::registerNSErrorChecker(CheckerManager &mgr) {
331331
mgr.registerChecker<NSErrorMethodChecker>();
332332
NSOrCFErrorDerefChecker *checker = mgr.getChecker<NSOrCFErrorDerefChecker>();
333333
checker->ShouldCheckNSError = true;
334+
checker->NSErrorName = mgr.getCurrentCheckerName();
334335
}
335336

336337
bool ento::shouldRegisterNSErrorChecker(const CheckerManager &mgr) {
@@ -341,6 +342,7 @@ void ento::registerCFErrorChecker(CheckerManager &mgr) {
341342
mgr.registerChecker<CFErrorFunctionChecker>();
342343
NSOrCFErrorDerefChecker *checker = mgr.getChecker<NSOrCFErrorDerefChecker>();
343344
checker->ShouldCheckCFError = true;
345+
checker->CFErrorName = mgr.getCurrentCheckerName();
344346
}
345347

346348
bool ento::shouldRegisterCFErrorChecker(const CheckerManager &mgr) {

clang/test/Analysis/incorrect-checker-names.mm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,19 @@ + (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictio
106106

107107
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]}}
108108
// FIXME: This shouldn't be tied to a modeling checker.
109-
*error = 0; // expected-warning {{Potential null dereference. According to coding standards documented in CoreFoundation/CFError.h the parameter may be null [osx.NSOrCFErrorDerefChecker]}}
109+
*error = 0; // expected-warning {{Potential null dereference. According to coding standards documented in CoreFoundation/CFError.h the parameter may be null [osx.coreFoundation.CFError]}}
110110
}
111111

112+
@interface A
113+
- (void)myMethodWhichMayFail:(NSError **)error;
114+
@end
115+
116+
@implementation A
117+
- (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]}}
118+
*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]}}
119+
}
120+
@end
121+
112122
bool write_into_out_param_on_success(OS_RETURNS_RETAINED OSObject **obj);
113123

114124
void use_out_param_leak() {

0 commit comments

Comments
 (0)