1 // RUN: %clang_analyze_cc1 -fobjc-arc -analyzer-checker=core,debug.ExprInspection -verify %s
3 void clang_analyzer_eval(int);
4 void clang_analyzer_warnIfReached(void);
6 extern void __assert_fail (__const char *__assertion, __const char *__file,
7 unsigned int __line, __const char *__function)
8 __attribute__ ((__noreturn__));
10 #define assert(expr) \
11 ((expr) ? (void)(0) : __assert_fail (#expr, __FILE__, __LINE__, __func__))
15 + (nonnull instancetype)alloc;
16 - (nonnull instancetype)init;
18 @interface NSObject <NSObject> {}
21 @interface NSError : NSObject {
28 @interface SomeClass : NSObject
29 + (int)doSomethingWithError:(NSError *__autoreleasing *)error;
32 @implementation SomeClass
33 + (int)doSomethingWithError:(NSError *__autoreleasing *)error {
35 NSError *e = [[NSError alloc] init];
39 clang_analyzer_eval(*error != 0); // expected-warning{{TRUE}}
45 void testStrongOutParam(void) {
47 clang_analyzer_eval(error != 0); // expected-warning{{FALSE}}
48 int ok = [SomeClass doSomethingWithError:&error];
49 clang_analyzer_eval(ok); // expected-warning{{FALSE}}
50 clang_analyzer_eval(error != 0); // expected-warning{{TRUE}}
51 clang_analyzer_eval(error->x == 5); // expected-warning{{TRUE}}
54 void testAutoreleasingOutParam(void) {
55 NSError *__autoreleasing error;
56 clang_analyzer_eval(error != 0); // expected-warning{{FALSE}}
57 int ok = [SomeClass doSomethingWithError:&error];
58 clang_analyzer_eval(ok); // expected-warning{{FALSE}}
59 clang_analyzer_eval(error != 0); // expected-warning{{TRUE}}
60 clang_analyzer_eval(error->x == 5); // expected-warning{{TRUE}}
63 void testNilOutParam(void) {
64 int ok = [SomeClass doSomethingWithError:(void *)0];
65 clang_analyzer_eval(ok); // expected-warning{{FALSE}}