1 // Temporarily disabling the test, it failes the "system is over-constrained" (part of expensive checks)
2 // assertion in *non* optimized builds.
3 // REQUIRES: rdar44992170
4 // RUN: %clang_analyze_cc1 -fblocks -analyze -analyzer-checker=core,nullability,apiModeling,debug.ExprInspection -verify %s
6 #include "Inputs/system-header-simulator-for-nullability.h"
8 void clang_analyzer_warnIfReached(void);
10 NSString* _Nonnull trust_nonnull_framework_annotation(void) {
11 NSString* out = [NSString generateString];
13 return out; // no-warning
16 NSString* _Nonnull trust_instancemsg_annotation(NSString* _Nonnull param) {
17 NSString* out = [param stringByAppendingString:@"string"];
19 return out; // no-warning
22 NSString* _Nonnull distrust_instancemsg_noannotation(NSString* param) {
24 NSString* out = [param stringByAppendingString:@"string"];
26 return out; // expected-warning{{}}
29 NSString* _Nonnull trust_analyzer_knowledge(NSString* param) {
32 NSString* out = [param stringByAppendingString:@"string"];
34 return out; // no-warning
37 NSString* _Nonnull trust_assume_nonnull_macro(void) {
38 NSString* out = [NSString generateImplicitlyNonnullString];
40 return out; // no-warning
43 NSString* _Nonnull distrust_without_annotation(void) {
44 NSString* out = [NSString generatePossiblyNullString];
46 return out; // expected-warning{{}}
49 NSString* _Nonnull nonnull_please_trust_me(void);
51 NSString* _Nonnull distrust_local_nonnull_annotation(void) {
52 NSString* out = nonnull_please_trust_me();
54 return out; // expected-warning{{}}
57 NSString* _Nonnull trust_c_function(void) {
58 NSString* out = getString();
60 return out; // no-warning
63 NSString* _Nonnull distrust_unannoted_function(void) {
64 NSString* out = getPossiblyNullString();
66 return out; // expected-warning{{}}
69 NSString * _Nonnull distrustProtocol(id<MyProtocol> o) {
70 NSString* out = [o getString];
72 return out; // expected-warning{{}}
75 // If the return value is non-nil, the index is non-nil.
76 NSString *_Nonnull retImpliesIndex(NSString *s,
81 return s; // no-warning
85 NSString *_Nonnull retImpliesIndexOtherMethod(NSString *s,
87 id obj = [dic objectForKey:s];
90 return s; // no-warning
94 NSString *_Nonnull retImpliesIndexOnRHS(NSString *s,
99 return s; // no-warning
103 NSString *_Nonnull retImpliesIndexReverseCheck(NSString *s,
109 return s; // no-warning
112 NSString *_Nonnull retImpliesIndexReverseCheckOnRHS(NSString *s,
118 return s; // no-warning
121 NSString *_Nonnull retImpliesIndexWrongBranch(NSString *s,
126 return s; // expected-warning{{}}
130 NSString *_Nonnull retImpliesIndexWrongBranchOnRHS(NSString *s,
135 return s; // expected-warning{{}}
139 // The return value could still be nil for a non-nil index.
140 NSDictionary *_Nonnull indexDoesNotImplyRet(NSString *s,
145 return obj; // expected-warning{{}}
146 return [[NSDictionary alloc] init];
149 // The return value could still be nil for a non-nil index.
150 NSDictionary *_Nonnull notIndexImpliesNotRet(NSString *s,
155 clang_analyzer_warnIfReached(); // no-warning
158 return [[NSDictionary alloc] init];
161 NSString *_Nonnull checkAssumeOnMutableDictionary(NSMutableDictionary *d,
166 return k; // no-warning
169 NSString *_Nonnull checkAssumeOnMutableDictionaryOtherMethod(NSMutableDictionary *d,
172 [d setObject:val forKey:k];
174 return k; // no-warning
177 // Check that we don't crash when the added assumption is enough
178 // to make the state unfeasible.
180 @interface DictionarySubclass : NSDictionary {
182 DictionarySubclass *d;
185 @implementation DictionarySubclass
186 - (id) objectForKey:(id)e {
192 id f = [self objectForKey:e];