aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wstringop-overflow-53.c
blob: cd8fa3202eb686722b1fb6c718bd9ebdb6ae64e1 (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
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
/* PR middle-end/96384 - bogus -Wstringop-overflow= storing into
   multidimensional array with index in range
   { dg-do compile }
   { dg-options "-O2 -Wall" } */

#define SHRT_MAX   __SHRT_MAX__
#define SHRT_MIN   (-SHRT_MAX - 1)
#define INT_MAX    __INT_MAX__
#define INT_MIN    (-INT_MAX - 1)
#define LONG_MAX   __LONG_MAX__
#define LONG_MIN   (-LONG_MAX - 1)

#define USHRT_MAX  (SHRT_MAX * 2 + 1)
#define UINT_MAX   ~0U
#define ULONG_MAX  ~0LU

char ca3_5_7[3][5][7];

void nowarn_ca_3_5_ssi (short i)
{
  if (i > SHRT_MAX - 1)
    i = SHRT_MAX - 1;

  ca3_5_7[i][0][0] = __LINE__;
  ca3_5_7[i][0][1] = __LINE__;
  ca3_5_7[i][0][2] = __LINE__;
  ca3_5_7[i][0][3] = __LINE__;
  ca3_5_7[i][0][4] = __LINE__;
  ca3_5_7[i][0][5] = __LINE__;
  ca3_5_7[i][0][6] = __LINE__;

  ca3_5_7[i][1][0] = __LINE__;
  ca3_5_7[i][1][1] = __LINE__;
  ca3_5_7[i][1][2] = __LINE__;
  ca3_5_7[i][1][3] = __LINE__;
  ca3_5_7[i][1][4] = __LINE__;
  ca3_5_7[i][1][5] = __LINE__;
  ca3_5_7[i][1][6] = __LINE__;

  ca3_5_7[i][2][0] = __LINE__;
  ca3_5_7[i][2][1] = __LINE__;
  ca3_5_7[i][2][2] = __LINE__;
  ca3_5_7[i][2][3] = __LINE__;
  ca3_5_7[i][2][4] = __LINE__;
  ca3_5_7[i][2][5] = __LINE__;
  ca3_5_7[i][2][6] = __LINE__;

  ca3_5_7[i][3][0] = __LINE__;
  ca3_5_7[i][3][1] = __LINE__;
  ca3_5_7[i][3][2] = __LINE__;
  ca3_5_7[i][3][3] = __LINE__;
  ca3_5_7[i][3][4] = __LINE__;
  ca3_5_7[i][3][5] = __LINE__;
  ca3_5_7[i][3][6] = __LINE__;

  ca3_5_7[i][4][0] = __LINE__;
  ca3_5_7[i][4][1] = __LINE__;
  ca3_5_7[i][4][2] = __LINE__;
  ca3_5_7[i][4][3] = __LINE__;
  ca3_5_7[i][4][4] = __LINE__;
  ca3_5_7[i][4][5] = __LINE__;
  ca3_5_7[i][4][6] = __LINE__;

  ca3_5_7[1][i][5] = __LINE__;
  ca3_5_7[2][3][i] = __LINE__;
}

void nowarn_ca_3_5_usi (unsigned short i)
{
  if (i > USHRT_MAX - 1)
    i = USHRT_MAX - 1;

  ca3_5_7[i][3][5] = __LINE__;
  ca3_5_7[1][i][5] = __LINE__;
  ca3_5_7[2][3][i] = __LINE__;
}

void nowarn_ca_3_5_si (int i)
{
  if (i > INT_MAX - 1)
    i = INT_MAX - 1;

  ca3_5_7[i][3][5] = __LINE__;
  ca3_5_7[1][i][5] = __LINE__;
  ca3_5_7[2][3][i] = __LINE__;
}

void nowarn_ca_3_5_ui (unsigned i)
{
  if (i > UINT_MAX - 1)
    i = UINT_MAX - 1;

  ca3_5_7[i][3][5] = __LINE__;
  ca3_5_7[1][i][5] = __LINE__;
  ca3_5_7[2][3][i] = __LINE__;
}

void nowarn_ca_3_5_li (long i)
{
  if (i > LONG_MAX - 1)
    i = LONG_MAX - 1;

  ca3_5_7[i][3][5] = __LINE__;
  ca3_5_7[1][i][5] = __LINE__;
  ca3_5_7[2][3][i] = __LINE__;
}

void nowarn_ca_3_5_uli (unsigned long i)
{
  if (i > ULONG_MAX - 1)
    i = ULONG_MAX - 1;

  ca3_5_7[i][3][5] = __LINE__;
  ca3_5_7[1][i][5] = __LINE__;
  ca3_5_7[2][3][i] = __LINE__;
}