summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/object-size-10.c
blob: 53e719de0cd9336849938fcc7346767a931849a3 (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
/* { dg-do run } */
/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
/* { dg-options "-fsanitize=undefined" } */

static char a[128] __attribute__ ((aligned(4096)));
static int b[128] __attribute__ ((aligned(4096)));

__attribute__ ((noinline, noclone)) int
fn1 (int i)
{
  asm ("");
  return a[i & 127];
}

__attribute__ ((noinline, noclone)) int
fn2 (int i)
{
  asm ("");
  return a[i & 128];
}

/* { dg-output "index 128 out of bounds for type 'char \\\[128\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*load of address \[^\n\r]* with insufficient space for an object of type 'char'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" } */

__attribute__ ((noinline, noclone)) int
fn3 (int i)
{
  asm ("");
  return b[i & 127];
}

__attribute__ ((noinline, noclone)) int
fn4 (int i)
{
  asm ("");
  return b[i & 128];
}

/* { dg-output "\[^\n\r]*index 128 out of bounds for type 'int \\\[128\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*load of address \[^\n\r]* with insufficient space for an object of type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" } */

__attribute__ ((noinline, noclone)) int
fn5 (int i, int j)
{
  asm ("");
  return b[i & j];
}

/* { dg-output "\[^\n\r]*index 128 out of bounds for type 'int \\\[128\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*load of address \[^\n\r]* with insufficient space for an object of type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*\\^" } */

__attribute__ ((noinline, noclone)) int
fn6 (int i)
{
  asm ("");
  return b[i & 0];
}

int
main (void)
{
  fn1 (128);
  fn2 (128);
  fn3 (128);
  fn4 (128);
  fn5 (128, 127);
  fn5 (128, 128);
  fn6 (128);
  return 0;
}