1 // RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s 2 3 // Zero-sized VLAs. check_zero_sized_VLA(int x)4void 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 check_uninit_sized_VLA()11void 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. vla_allocate_signed(int x)17static void vla_allocate_signed(int x) { 18 int vla[x]; // expected-warning{{Declared variable-length array (VLA) has negative size}} 19 } 20 vla_allocate_unsigned(unsigned int x)21static void vla_allocate_unsigned(unsigned int x) { 22 int vla[x]; // no-warning 23 } 24 check_negative_sized_VLA_1()25void check_negative_sized_VLA_1() { 26 vla_allocate_signed(-1); 27 } 28 check_negative_sized_VLA_2()29void check_negative_sized_VLA_2() { 30 vla_allocate_unsigned(-1); 31 } 32 check_negative_sized_VLA_3()33void 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 check_negative_sized_VLA_4()38void check_negative_sized_VLA_4() { 39 unsigned int x = -1; 40 int vla[x]; // no-warning 41 } 42 check_negative_sized_VLA_5()43void 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 check_negative_sized_VLA_6()48void check_negative_sized_VLA_6() { 49 unsigned char x = -1; 50 int vla[x]; // no-warning 51 } 52 check_negative_sized_VLA_7()53void check_negative_sized_VLA_7() { 54 signed char x = -1; 55 int vla[x + 2]; // no-warning 56 } 57 check_negative_sized_VLA_8()58void 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 check_negative_sized_VLA_9()63void check_negative_sized_VLA_9() { 64 int x = 1; 65 int vla[x]; // no-warning 66 } 67 check_negative_sized_VLA_10_sub(int x)68static 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 check_negative_sized_VLA_10(int x)73void check_negative_sized_VLA_10(int x) { 74 if (x < 0) 75 check_negative_sized_VLA_10_sub(x); 76 } 77 check_negative_sized_VLA_11_sub(int x)78static void check_negative_sized_VLA_11_sub(int x) 79 { 80 int vla[x]; // no-warning 81 } 82 check_negative_sized_VLA_11(int x)83void check_negative_sized_VLA_11(int x) { 84 if (x > 0) 85 check_negative_sized_VLA_11_sub(x); 86 } 87