1 // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -verify -analyzer-constraints=basic %s
2 // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -verify -analyzer-constraints=range %s
4 // These are used to trigger warnings.
5 typedef typeof(sizeof(int)) size_t;
8 #define NULL ((void*)0)
15 void separateExpressions (int a
) {
19 char* buf
= malloc(1);
21 return; // expected-warning{{never executed}}
25 void oneLongExpression (int a
) {
26 // Expression canonicalization should still allow this to work, even though
27 // the first term is on the left.
28 int b
= 15 + a
+ 15 - 10 - 20;
30 char* buf
= malloc(1);
32 return; // expected-warning{{never executed}}
36 void mixedTypes (int a
) {
37 char* buf
= malloc(1);
39 // Different additive types should not cause crashes when constant-folding.
40 // This is part of PR7406.
42 if (a
!= 0 && (b
-1) == 0) // not crash
43 return; // expected-warning{{never executed}}
46 if (a
!= 0 && (c
-1) == 0) // not crash
47 return; // expected-warning{{never executed}}
56 // Equality and inequality only
57 void eq_ne (unsigned a
) {
63 if (a
-1 != UINT_MAX
-1)
68 void ne_eq (unsigned a
) {
74 if (a
-1 == UINT_MAX
-1)
79 // Mixed typed inequalities (part of PR7406)
80 // These should not crash.
81 void mixed_eq_ne (int a
) {
88 return; // expected-warning{{never executed}}
92 void mixed_ne_eq (int a
) {
99 return; // expected-warning{{never executed}}
104 // Simple order comparisons with no adjustment
105 void baselineGT (unsigned a
) {
110 return; // no-warning
114 void baselineGE (unsigned a
) {
120 return; // no-warning
123 void baselineLT (unsigned a
) {
128 return; // no-warning
132 void baselineLE (unsigned a
) {
138 return; // no-warning
142 // Adjustment gives each of these an extra solution!
143 void adjustedGT (unsigned a
) {
145 if (a
-1 > UINT_MAX
-1)
147 return; // expected-warning{{leak}}
150 void adjustedGE (unsigned a
) {
152 if (a
-1 >= UINT_MAX
-1)
156 return; // expected-warning{{leak}}
159 void adjustedLT (unsigned a
) {
163 return; // expected-warning{{leak}}
166 void adjustedLE (unsigned a
) {
172 return; // expected-warning{{leak}}
177 void tautologyGT (unsigned a
) {
180 return; // no-warning
184 void tautologyGE (unsigned a
) {
186 if (a
>= 0) // expected-warning{{always true}}
188 return; // no-warning
191 void tautologyLT (unsigned a
) {
193 if (a
< 0) // expected-warning{{always false}}
194 return; // expected-warning{{never executed}}
198 void tautologyLE (unsigned a
) {
202 return; // no-warning