annotate gcc/testsuite/c-c++-common/ubsan/align-2.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Limit this to known non-strict alignment targets. */
kono
parents:
diff changeset
2 /* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
3 /* { dg-options "-fsanitize=alignment -Wno-address-of-packed-member" } */
111
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 struct S { int a; char b; long long c; short d[10]; };
kono
parents:
diff changeset
6 struct T { char a; long long b; };
kono
parents:
diff changeset
7 struct U { char a; int b; int c; long long d; struct S e; struct T f; } __attribute__((packed));
kono
parents:
diff changeset
8 struct V { long long a; struct S b; struct T c; struct U u; } v;
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 __attribute__((noinline, noclone)) void
kono
parents:
diff changeset
11 f1 (int *p, int *q, char *r, long long *s)
kono
parents:
diff changeset
12 {
kono
parents:
diff changeset
13 *p =
kono
parents:
diff changeset
14 *q
kono
parents:
diff changeset
15 + *r
kono
parents:
diff changeset
16 + *s;
kono
parents:
diff changeset
17 }
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 __attribute__((noinline, noclone)) int
kono
parents:
diff changeset
21 f2 (struct S *p)
kono
parents:
diff changeset
22 {
kono
parents:
diff changeset
23 return p->a;
kono
parents:
diff changeset
24 }
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 __attribute__((noinline, noclone)) long long
kono
parents:
diff changeset
27 f3 (struct S *p, int i)
kono
parents:
diff changeset
28 {
kono
parents:
diff changeset
29 return p->c
kono
parents:
diff changeset
30 + p->d[1]
kono
parents:
diff changeset
31 + p->d[i];
kono
parents:
diff changeset
32 }
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 __attribute__((noinline, noclone)) long long
kono
parents:
diff changeset
35 f4 (long long *p)
kono
parents:
diff changeset
36 {
kono
parents:
diff changeset
37 return *p;
kono
parents:
diff changeset
38 }
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 int
kono
parents:
diff changeset
41 main ()
kono
parents:
diff changeset
42 {
kono
parents:
diff changeset
43 f1 (&v.u.b, &v.u.c, &v.u.a, &v.u.d);
kono
parents:
diff changeset
44 if (f2 (&v.u.e) + f3 (&v.u.e, 4) + f4 (&v.u.f.b) != 0)
kono
parents:
diff changeset
45 __builtin_abort ();
kono
parents:
diff changeset
46 return 0;
kono
parents:
diff changeset
47 }
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 /* { dg-output "\.c:(14|15):\[0-9]*: \[^\n\r]*load of misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" } */
kono
parents:
diff changeset
50 /* { dg-output "\.c:16:\[0-9]*: \[^\n\r]*load of misaligned address 0x\[0-9a-fA-F]* for type 'long long int', which requires \[48] byte alignment.*" } */
kono
parents:
diff changeset
51 /* { dg-output "\.c:(13|16):\[0-9]*: \[^\n\r]*store to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" } */
kono
parents:
diff changeset
52 /* { dg-output "\.c:23:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */
kono
parents:
diff changeset
53 /* { dg-output "\.c:(29|30):\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */
kono
parents:
diff changeset
54 /* { dg-output "\.c:30:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */
kono
parents:
diff changeset
55 /* { dg-output "\.c:31:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */
kono
parents:
diff changeset
56 /* { dg-output "\.c:37:\[0-9]*: \[^\n\r]*load of misaligned address 0x\[0-9a-fA-F]* for type 'long long int', which requires \[48] byte alignment" } */