summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/align-7.c
blob: ec4e87f56d518de370d74f7bea424c09e92ffad6 (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
/* Limit this to known non-strict alignment targets.  */
/* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
/* { dg-options "-O -fsanitize=alignment -fno-sanitize-recover=alignment -fdump-tree-sanopt-details" } */
/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */
/* { dg-shouldfail "ubsan" } */

struct S { int a; char b; long long c; short d[10]; };
struct T { char a; long long b; };
struct U { char a; int b; int c; long long d; struct S e; struct T f; } __attribute__((packed));
struct V { long long a; struct S b; struct T c; struct U u; } v;

__attribute__((noinline, noclone)) int
foo (struct S *p)
{
  volatile int i;
  i = p->a;
  i = p->a;
  i = p->a;
  i = p->a;
  return p->a;
}

int
main ()
{
  if (foo (&v.u.e))
    __builtin_abort ();
  return 0;
}

/* { dg-output "\.c:16:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment" } */
/* { dg-final { scan-tree-dump-times "Optimizing" 4 "sanopt"} } */