summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/pr63477.c
blob: 8fb2f266fd8362b3c1ddc086ee7ca4ad5a0d3a9e (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
/* PR middle-end/63477 - Bogus warning with -O3 -Warray-bounds: array
   subscript is above array bounds
   { dg-do compile }
   { dg-options "-O3 -Warray-bounds" }  */

#define MAX_VAL 16

typedef struct
{
  int itemList[MAX_VAL + 1];
  unsigned int numItems;
} ItemList;

void FrobList (ItemList *l)
{
  unsigned int i;

  for (i = 0; i < l->numItems - 1; i++)
    {
      int minVal = l->itemList[i];

      unsigned int minIdx = i;
      unsigned int idx;

      for (idx = i + 1; idx < l->numItems; ++idx) {

	if (l->itemList[idx] < minVal)  /* { dg-bogus "\\\[-Warray-bounds]" } */
	  {
	    minVal = l->itemList[idx];
	    minIdx = idx;
	  }
      }

      l->itemList[i] = l->itemList[minIdx];
    }
}