summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Warray-bounds-51.c
blob: 6028b11637ca0448392d6862036a5ded8df3a705 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* PR middle-end/92333 - missing variable name referencing VLA in warnings
   PR middle-end/82608 - missing -Warray-bounds on an out-of-bounds VLA index
   { dg-do compile }
   { dg-options "-O2 -Wall" } */

void sink (void*);

void test_char_vla_location (void)
{
  unsigned nelts = 7;

  char vla[nelts];    // { dg-message "declared here|while referencing" }

  vla[0] = __LINE__;
  vla[nelts] = 0;     // { dg-warning "\\\[-Warray-bounds" }

  sink (vla);
}

void test_int_vla_location (void)
{
  unsigned nelts = 7;

  int vla[nelts];     // { dg-message "declared here|while referencing" }

  vla[0] = __LINE__;
  vla[nelts] = 1;     // { dg-warning "\\\[-Warray-bounds" }

  sink (vla);
}

void test_struct_char_vla_location (void)
{
  unsigned nelts = 7;

  struct {
    char cvla[nelts]; // { dg-message "declared here|while referencing" }
  } s;

  s.cvla[0] = __LINE__;
  s.cvla[nelts - 1] = 0;
  s.cvla[nelts] = 0;  // { dg-warning "\\\[-Warray-bounds" }

  sink (&s);
}


void test_struct_int_vla_location (void)
{
  unsigned nelts = 7;

  struct {
    int ivla[nelts];  // { dg-message "declared here|while referencing" }
  } s;

  s.ivla[0] = __LINE__;
  s.ivla[nelts - 1] = 0;
  s.ivla[nelts] = 0;  // { dg-warning "\\\[-Warray-bounds" }

  sink (&s);
}