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

struct S { int a; int b; };

static inline __attribute__((always_inline)) int
foo (struct S *p)
{
  volatile int a;
  a = p->a; /* OK */
  return p->b;
}

int
bar (void)
{
  struct S *p = (struct S *) __builtin_calloc (sizeof (int) + sizeof (int) / 2, 1);
  return foo (p);
}

int
main (void)
{
  bar ();
  return 0;
}

/* { dg-output "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]*\\^" } */