File: Warray-bounds-62.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (130 lines) | stat: -rw-r--r-- 4,915 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* PR tree-optimization/84079 - missing -Warray-bounds taking the address
   of past-the-end element of a multidimensional array
   { dg-do compile }
   { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */

void sink (int, ...);

#define T(type, dims, inxs)			\
  do {						\
    type a dims;				\
    sink (__LINE__, &a inxs);			\
  } while (0)


void test_char_1_1 (int i0, int i1, int i2)
{
#undef DIMS
#define DIMS [1][1]

  T (char, DIMS, [0]);
  T (char, DIMS, [1]);
  T (char, DIMS, [2]);            // { dg-warning "subscript 2 is above array bounds of 'char\\\[1]\\\[1]'" }

  T (char, DIMS, [0][0]);
  T (char, DIMS, [0][1]);
  T (char, DIMS, [0][2]);         // { dg-warning "subscript 2 is above array bounds of 'char\\\[1]'" }

  T (char, DIMS, [1][0]);         // { dg-warning "subscript 1 is above array bounds of 'char\\\[1]\\\[1]'" }
  T (char, DIMS, [1][1]);         // { dg-warning "subscript 1 is above array bounds of 'char\\\[1]\\\[1]'" }
  T (char, DIMS, [1][2]);         // { dg-warning "subscript 2 is above array bounds of 'char\\\[1]'" }

  // Exercise ranges.
  if (i0 < 0) i0 = 0;
  if (i1 < 1) i1 = 1;
  if (i2 < 2) i2 = 2;

  T (char, DIMS, [i0]);
  T (char, DIMS, [i1]);
  T (char, DIMS, [i2]);           // { dg-warning "subscript 2 is above array bounds of 'char\\\[1]\\\[1]" }

  T (char, DIMS, [i0][i0]);
  T (char, DIMS, [i0][i1]);
  T (char, DIMS, [i1][i0]);       // { dg-warning "subscript 1 is above array bounds of 'char\\\[1]\\\[1]'" }
  T (char, DIMS, [i1][i1]);       // { dg-warning "subscript 1 is above array bounds of 'char\\\[1]\\\[1]'" }
  T (char, DIMS, [i1][i2]);       // { dg-warning "subscript 2 is above array bounds of 'char\\\[1]'" }
}


void test_int_3_5 (int i0, int i1, int i2, int i3, int i4, int i5, int i6)
{
#undef DIMS
#define DIMS [3][5]

  T (int, DIMS, [0]);
  T (int, DIMS, [3]);
  T (int, DIMS, [4]);             // { dg-warning "subscript 4 is above array bounds of 'int\\\[3]\\\[5]'" }

  T (int, DIMS, [0][0]);
  T (int, DIMS, [0][5]);
  T (int, DIMS, [0][6]);          // { dg-warning "subscript 6 is above array bounds of 'int\\\[5]'" }

  T (int, DIMS, [1][0]);
  T (int, DIMS, [1][5]);
  T (int, DIMS, [1][6]);          // { dg-warning "subscript 6 is above array bounds of 'int\\\[5]'" }

  T (int, DIMS, [3][0]);          // { dg-warning "subscript 3 is above array bounds of 'int\\\[3]\\\[5]'" }
  T (int, DIMS, [3][5]);          // { dg-warning "subscript 3 is above array bounds of 'int\\\[3]\\\[5]'" }
  T (int, DIMS, [3][6]);          // { dg-warning "subscript 6 is above array bounds of 'int\\\[5]'" }

  // Exercise ranges.
  if (i0 < 0) i0 = 0;
  if (i1 < 1) i1 = 1;
  if (i2 < 2) i2 = 2;
  if (i3 < 3) i3 = 3;
  if (i4 < 4) i4 = 4;
  if (i5 < 5) i5 = 5;
  if (i6 < 6) i6 = 6;

  T (int, DIMS, [i0]);
  T (int, DIMS, [i3]);
  T (int, DIMS, [i4]);            // { dg-warning "subscript 4 is above array bounds of 'int\\\[3]\\\[5]" }

  T (int, DIMS, [i0][i0]);
  T (int, DIMS, [i0][i5]);
  T (int, DIMS, [i0][i6]);        // { dg-warning "subscript 6 is above array bounds of 'int\\\[5]'" }

  T (int, DIMS, [i1][i0]);
  T (int, DIMS, [i1][i5]);
  T (int, DIMS, [i1][i6]);        // { dg-warning "subscript 6 is above array bounds of 'int\\\[5]'" }

  T (int, DIMS, [i3][i0]);        // { dg-warning "subscript 3 is above array bounds of 'int\\\[3]\\\[5]'" }
  T (int, DIMS, [i3][i5]);        // { dg-warning "subscript 3 is above array bounds of 'int\\\[3]\\\[5]'" }
  T (int, DIMS, [i3][i6]);        // { dg-warning "subscript 6 is above array bounds of 'int\\\[5]'" }
}


void test_int_2_3_4_5 (void)
{
#undef DIMS
#define DIMS [2][3][4][5]

  T (int, DIMS, [0]);
  T (int, DIMS, [2]);
  T (int, DIMS, [3]);             // { dg-warning "subscript 3 is above array bounds of 'int\\\[2]\\\[3]\\\[4]\\\[5]'" }

  T (int, DIMS, [0][0]);
  T (int, DIMS, [0][3]);
  T (int, DIMS, [0][4]);          // { dg-warning "subscript 4 is above array bounds of 'int\\\[3]\\\[4]\\\[5]'" }
  T (int, DIMS, [0][9]);          // { dg-warning "subscript 9 is above array bounds of 'int\\\[3]\\\[4]\\\[5]'" }

  T (int, DIMS, [0][0][0]);
  T (int, DIMS, [0][0][4]);
  T (int, DIMS, [0][0][5]);       // { dg-warning "subscript 5 is above array bounds of 'int\\\[4]\\\[5]'" }

  T (int, DIMS, [0][0][0][0]);
  T (int, DIMS, [0][0][0][5]);
  T (int, DIMS, [0][0][0][6]);    // { dg-warning "subscript 6 is above array bounds of 'int\\\[5]'" }

  T (int, DIMS, [0][0][1][0]);
  T (int, DIMS, [0][0][1][5]);
  T (int, DIMS, [0][0][1][6]);    // { dg-warning "subscript 6 is above array bounds of 'int\\\[5]'" }

  T (int, DIMS, [0][0][3][0]);
  T (int, DIMS, [0][0][3][5]);
  T (int, DIMS, [0][0][3][6]);    // { dg-warning "subscript 6 is above array bounds of 'int\\\[5]'" }

  T (int, DIMS, [0][0][1][0]);
  T (int, DIMS, [0][0][1][5]);
  T (int, DIMS, [0][0][1][6]);    // { dg-warning "subscript 6 is above array bounds of 'int\\\[5]'" }
}