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

/* Test structures with -fsanitize=object-size.  */

#define N 20

struct S { char *p; int i; };
struct T { struct S *s; };

__attribute__((noinline, noclone)) void
f1 (int i)
{
  volatile int j;
  struct S s;
  s.p = (char *) __builtin_calloc (N, 1);
  j = s.p[i];
  j = *(s.p + i);
  __builtin_free (s.p);
}

/* { dg-output "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)" } */
/* { 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)" } */

int
main ()
{
  f1 (N);
  f1 (N - 1);
  return 0;
}