2020-04-08 23:58:40 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -verify -Wno-objc-root-class %s \
|
|
|
|
// RUN: -analyzer-checker=core \
|
|
|
|
// RUN: -analyzer-checker=nullability \
|
|
|
|
// RUN: -analyzer-checker=osx.cocoa.NSError \
|
|
|
|
// RUN: -analyzer-checker=osx.coreFoundation.CFError
|
2008-09-19 12:56:32 +08:00
|
|
|
|
|
|
|
typedef signed char BOOL;
|
|
|
|
typedef int NSInteger;
|
|
|
|
typedef struct _NSZone NSZone;
|
|
|
|
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
|
|
|
|
@protocol NSObject - (BOOL)isEqual:(id)object; @end
|
|
|
|
@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
|
|
|
|
@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
|
|
|
|
@interface NSObject <NSObject> {} @end
|
|
|
|
@class NSDictionary;
|
|
|
|
@interface NSError : NSObject <NSCopying, NSCoding> {}
|
|
|
|
+ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict;
|
|
|
|
@end
|
|
|
|
extern NSString * const NSXMLParserErrorDomain ;
|
|
|
|
|
|
|
|
@interface A
|
|
|
|
- (void)myMethodWhichMayFail:(NSError **)error;
|
|
|
|
- (BOOL)myMethodWhichMayFail2:(NSError **)error;
|
2020-04-08 23:58:40 +08:00
|
|
|
- (BOOL)myMethodWhichMayFail3:(NSError **_Nonnull)error;
|
2020-04-20 16:08:57 +08:00
|
|
|
- (BOOL)myMethodWhichMayFail4:(NSError **)error __attribute__((nonnull));
|
2008-09-19 12:56:32 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation A
|
2009-08-06 14:26:40 +08:00
|
|
|
- (void)myMethodWhichMayFail:(NSError **)error { // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occurred}}
|
Allow multiple PathDiagnosticConsumers to be used with a BugReporter at the same time.
This fixes several issues:
- removes egregious hack where PlistDiagnosticConsumer would forward to HTMLDiagnosticConsumer,
but diagnostics wouldn't be generated consistently in the same way if PlistDiagnosticConsumer
was used by itself.
- emitting diagnostics to the terminal (using clang's diagnostic machinery) is no longer a special
case, just another PathDiagnosticConsumer. This also magically resolved some duplicate warnings,
as we now use PathDiagnosticConsumer's diagnostic pruning, which has scope for the entire translation
unit, not just the scope of a BugReporter (which is limited to a particular ExprEngine).
As an interesting side-effect, diagnostics emitted to the terminal also have their trailing "." stripped,
just like with diagnostics emitted to plists and HTML. This required some tests to be updated, but now
the tests have higher fidelity with what users will see.
There are some inefficiencies in this patch. We currently generate the report graph (from the ExplodedGraph)
once per PathDiagnosticConsumer, which is a bit wasteful, but that could be pulled up higher in the
logic stack. There is some intended duplication, however, as we now generate different PathDiagnostics (for the same issue)
for different PathDiagnosticConsumers. This is necessary to produce the diagnostics that a particular
consumer expects.
llvm-svn: 162028
2012-08-17 01:45:23 +08:00
|
|
|
*error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference}}
|
2008-09-19 12:56:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)myMethodWhichMayFail2:(NSError **)error { // no-warning
|
|
|
|
if (error) *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-08 23:58:40 +08:00
|
|
|
|
|
|
|
- (BOOL)myMethodWhichMayFail3:(NSError **_Nonnull)error { // no-warning
|
|
|
|
*error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-20 16:08:57 +08:00
|
|
|
|
|
|
|
- (BOOL)myMethodWhichMayFail4:(NSError **)error { // no-warning
|
|
|
|
*error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning
|
|
|
|
return 0;
|
|
|
|
}
|
2008-09-19 12:56:32 +08:00
|
|
|
@end
|
2008-10-02 07:24:09 +08:00
|
|
|
|
|
|
|
struct __CFError {};
|
|
|
|
typedef struct __CFError* CFErrorRef;
|
|
|
|
|
2009-08-06 14:26:40 +08:00
|
|
|
void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred}}
|
Allow multiple PathDiagnosticConsumers to be used with a BugReporter at the same time.
This fixes several issues:
- removes egregious hack where PlistDiagnosticConsumer would forward to HTMLDiagnosticConsumer,
but diagnostics wouldn't be generated consistently in the same way if PlistDiagnosticConsumer
was used by itself.
- emitting diagnostics to the terminal (using clang's diagnostic machinery) is no longer a special
case, just another PathDiagnosticConsumer. This also magically resolved some duplicate warnings,
as we now use PathDiagnosticConsumer's diagnostic pruning, which has scope for the entire translation
unit, not just the scope of a BugReporter (which is limited to a particular ExprEngine).
As an interesting side-effect, diagnostics emitted to the terminal also have their trailing "." stripped,
just like with diagnostics emitted to plists and HTML. This required some tests to be updated, but now
the tests have higher fidelity with what users will see.
There are some inefficiencies in this patch. We currently generate the report graph (from the ExplodedGraph)
once per PathDiagnosticConsumer, which is a bit wasteful, but that could be pulled up higher in the
logic stack. There is some intended duplication, however, as we now generate different PathDiagnostics (for the same issue)
for different PathDiagnosticConsumers. This is necessary to produce the diagnostics that a particular
consumer expects.
llvm-svn: 162028
2012-08-17 01:45:23 +08:00
|
|
|
*error = 0; // expected-warning {{Potential null dereference}}
|
2008-10-02 07:24:09 +08:00
|
|
|
}
|
|
|
|
|
2009-03-29 03:59:33 +08:00
|
|
|
int f1(CFErrorRef* error) {
|
|
|
|
if (error) *error = 0; // no-warning
|
2008-10-02 07:24:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-03-29 03:59:33 +08:00
|
|
|
|
|
|
|
int f2(CFErrorRef* error) {
|
|
|
|
if (0 != error) *error = 0; // no-warning
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int f3(CFErrorRef* error) {
|
|
|
|
if (error != 0) *error = 0; // no-warning
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-20 16:08:57 +08:00
|
|
|
int __attribute__((nonnull)) f4(CFErrorRef *error) {
|
|
|
|
*error = 0; // no-warning
|
|
|
|
return 0;
|
|
|
|
}
|
2009-03-29 03:59:33 +08:00
|
|
|
|
2020-04-20 16:08:57 +08:00
|
|
|
int __attribute__((nonnull(1))) f5(int *x, CFErrorRef *error) {
|
|
|
|
*error = 0; // expected-warning {{Potential null dereference}}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __attribute__((nonnull(2))) f6(int *x, CFErrorRef *error) {
|
|
|
|
*error = 0; // no-warning
|
|
|
|
return 0;
|
|
|
|
}
|