Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s |
| 2 | |
| 3 | // Zero-sized VLAs. |
| 4 | void check_zero_sized_VLA(int x) { |
| 5 | if (x) |
| 6 | return; |
| 7 | |
| 8 | int vla[x]; // expected-warning{{Declared variable-length array (VLA) has zero size}} |
| 9 | } |
| 10 | |
| 11 | void check_uninit_sized_VLA() { |
| 12 | int x; |
| 13 | int vla[x]; // expected-warning{{Declared variable-length array (VLA) uses a garbage value as its size}} |
| 14 | } |
| 15 | |
| 16 | // Negative VLAs. |
| 17 | static void vla_allocate_signed(int x) { |
| 18 | int vla[x]; // expected-warning{{Declared variable-length array (VLA) has negative size}} |
| 19 | } |
| 20 | |
| 21 | static void vla_allocate_unsigned(unsigned int x) { |
| 22 | int vla[x]; // no-warning |
| 23 | } |
| 24 | |
| 25 | void check_negative_sized_VLA_1() { |
| 26 | vla_allocate_signed(-1); |
| 27 | } |
| 28 | |
| 29 | void check_negative_sized_VLA_2() { |
| 30 | vla_allocate_unsigned(-1); |
| 31 | } |
| 32 | |
| 33 | void check_negative_sized_VLA_3() { |
| 34 | int x = -1; |
| 35 | int vla[x]; // expected-warning{{Declared variable-length array (VLA) has negative size}} |
| 36 | } |
| 37 | |
| 38 | void check_negative_sized_VLA_4() { |
| 39 | unsigned int x = -1; |
| 40 | int vla[x]; // no-warning |
| 41 | } |
| 42 | |
| 43 | void check_negative_sized_VLA_5() { |
| 44 | signed char x = -1; |
| 45 | int vla[x]; // expected-warning{{Declared variable-length array (VLA) has negative size}} |
| 46 | } |
| 47 | |
| 48 | void check_negative_sized_VLA_6() { |
| 49 | unsigned char x = -1; |
| 50 | int vla[x]; // no-warning |
| 51 | } |
| 52 | |
| 53 | void check_negative_sized_VLA_7() { |
| 54 | signed char x = -1; |
| 55 | int vla[x + 2]; // no-warning |
| 56 | } |
| 57 | |
| 58 | void check_negative_sized_VLA_8() { |
| 59 | signed char x = 1; |
| 60 | int vla[x - 2]; // expected-warning{{Declared variable-length array (VLA) has negative size}} |
| 61 | } |
| 62 | |
| 63 | void check_negative_sized_VLA_9() { |
| 64 | int x = 1; |
| 65 | int vla[x]; // no-warning |
| 66 | } |
| 67 | |
| 68 | static void check_negative_sized_VLA_10_sub(int x) |
| 69 | { |
| 70 | int vla[x]; // expected-warning{{Declared variable-length array (VLA) has negative size}} |
| 71 | } |
| 72 | |
| 73 | void check_negative_sized_VLA_10(int x) { |
| 74 | if (x < 0) |
| 75 | check_negative_sized_VLA_10_sub(x); |
| 76 | } |
| 77 | |
| 78 | static void check_negative_sized_VLA_11_sub(int x) |
| 79 | { |
| 80 | int vla[x]; // no-warning |
| 81 | } |
| 82 | |
| 83 | void check_negative_sized_VLA_11(int x) { |
| 84 | if (x > 0) |
| 85 | check_negative_sized_VLA_11_sub(x); |
| 86 | } |