aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/bounds-13.c
blob: 25b0467ec67be51d2b66bcc2bafee3831f793c86 (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
/* PR sanitizer/71498 */
/* { dg-do run } */
/* { dg-options "-fsanitize=bounds -Wno-array-bounds" } */

struct S { int a[100]; int b, c; } s;

__attribute__((noinline, noclone)) int
foo (int x)
{
  return s.a[x];
}

__attribute__((noinline, noclone)) int
bar (int x)
{
  static int *d = &s.a[99];
  asm volatile ("" : : "r" (&d));
  return s.a[x];
}

int
main ()
{
  volatile int a = 0;
  a += foo (100);
  a += bar (100);
  return 0;
}

/* { dg-output "index 100 out of bounds for type 'int \\\[100\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 100 out of bounds for type 'int \\\[100\\\]'\[^\n\r]*(\n|\r\n|\r)" } */