| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s |
| 2 |
|
| 3 |
typedef int __attribute__((ext_vector_type(2))) V; |
| 4 |
|
| 5 |
void clang_analyzer_warnIfReached(void); |
| 6 |
void clang_analyzer_numTimesReached(void); |
| 7 |
void clang_analyzer_eval(int); |
| 8 |
|
| 9 |
int flag; |
| 10 |
|
| 11 |
V pass_through_and_set_flag(V v) { |
| 12 |
flag = 1; |
| 13 |
return v; |
| 14 |
} |
| 15 |
|
| 16 |
V dont_crash_and_dont_split_state(V x, V y) { |
| 17 |
flag = 0; |
| 18 |
V z = x && pass_through_and_set_flag(y); |
| 19 |
clang_analyzer_eval(flag); // expected-warning{{TRUE}} |
| 20 |
// FIXME: For now we treat vector operator && as short-circuit, |
| 21 |
// but in fact it is not. It should always evaluate |
| 22 |
// pass_through_and_set_flag(). It should not split state. |
| 23 |
// Now we also get FALSE on the other path. |
| 24 |
// expected-warning@-5{{FALSE}} |
| 25 |
|
| 26 |
// FIXME: Should be 1 since we should not split state. |
| 27 |
clang_analyzer_numTimesReached(); // expected-warning{{2}} |
| 28 |
return z; |
| 29 |
} |
| 30 |
|
| 31 |
void test_read(void) { |
| 32 |
V x; |
| 33 |
x[0] = 0; |
| 34 |
x[1] = 1; |
| 35 |
|
| 36 |
clang_analyzer_eval(x[0] == 0); // expected-warning{{TRUE}} |
| 37 |
} |
| 38 |
|
| 39 |
V return_vector(void) { |
| 40 |
V z; |
| 41 |
z[0] = 0; |
| 42 |
z[1] = 0; |
| 43 |
return z; |
| 44 |
} |
| 45 |
|
| 46 |
int test_vector_access(void) { |
| 47 |
return return_vector()[0]; // no-crash no-warning |
| 48 |
} |
| 49 |
|
| 50 |
@interface I |
| 51 |
@property V v; |
| 52 |
@end |
| 53 |
|
| 54 |
// Do not crash on subscript operations into ObjC properties. |
| 55 |
int myfunc(I *i2) { |
| 56 |
int out = i2.v[0]; // no-crash no-warning |
| 57 |
|
| 58 |
// Check that the analysis continues. |
| 59 |
clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 60 |
return out; |
| 61 |
} |