Ted Kremenek | 64699be | 2011-02-16 01:57:07 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify %s |
| 2 | |
| 3 | int foo() { |
Ted Kremenek | 108b2d5 | 2011-02-16 04:01:44 +0000 | [diff] [blame] | 4 | int x[2]; // expected-note 4 {{Array 'x' declared here}} |
| 5 | int y[2]; // expected-note 2 {{Array 'y' declared here}} |
Ted Kremenek | 64699be | 2011-02-16 01:57:07 +0000 | [diff] [blame] | 6 | int *p = &y[2]; // no-warning |
| 7 | (void) sizeof(x[2]); // no-warning |
Ted Kremenek | 108b2d5 | 2011-02-16 04:01:44 +0000 | [diff] [blame] | 8 | y[2] = 2; // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}} |
| 9 | return x[2] + // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}} |
| 10 | y[-1] + // expected-warning{{array index of '-1' indexes before the beginning of the array}} |
| 11 | x[sizeof(x)] + // expected-warning{{array index of '8' indexes past the end of an array (that contains 2 elements)}} |
| 12 | x[sizeof(x) / sizeof(x[0])] + // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}} |
Ted Kremenek | 64699be | 2011-02-16 01:57:07 +0000 | [diff] [blame] | 13 | x[sizeof(x) / sizeof(x[0]) - 1] + // no-warning |
Ted Kremenek | 108b2d5 | 2011-02-16 04:01:44 +0000 | [diff] [blame] | 14 | x[sizeof(x[2])]; // expected-warning{{array index of '4' indexes past the end of an array (that contains 2 elements)}} |
Ted Kremenek | 64699be | 2011-02-16 01:57:07 +0000 | [diff] [blame] | 15 | } |
| 16 | |