Debian Codegraph @

gcc/testsuite/gcc.target/bpf/core-attr-5.c

raw
1 /* Test for BPF CO-RE __attribute__((preserve_access_index)) with accesses on
2 LHS and both LHS and RHS of assignment. */
3
4 /* { dg-do compile } */
5 /* { dg-options "-O2 -dA -gbtf -mco-re -masm=normal" } */
6
7 struct U {
8 int c;
9 struct V {
10 int d;
11 int e[4];
12 int f;
13 int *g;
14 } v;
15 } __attribute__((preserve_access_index));
16
17 struct T {
18 int a;
19 int b;
20 struct U u;
21 struct U *ptr_u;
22 struct U *array_u;
23 } __attribute__((preserve_access_index));
24
25
26 extern void mset(void *);
27 void
28 func (struct T *t, int i)
29 {
30 /* This next expression is silently generating incomplete CO-RE relocations
31 * because of a front-end optimization to the array access with i. It is
32 * converting the access to pointer arithmetics, which completely removes the
33 * reference to the type of array_u. With current folding it is not possible
34 * to generate correct/complete CO-RE relocations for such cases. The XFAIL
35 * is exactly for this reason. Once we do XPASS this test there is a slight
36 * chance we are doing the proper code generation. */
37
38 /* 0:4 sizeof(struct U) 0:1:1:3 */
39 t->array_u[i].v.e[3] = 0xc1;
40
41 /* This was commented since in this case it is detectable as not a field
42 * expression. */
43 /* 0:4 sizeof(struct U) 0:1:1:2 */
44 //__builtin_preserve_access_index (t->array_u[i].v.e[2]) = 0xa1;
45
46 /* 0:3 0:1:1:1 */
47 t->ptr_u->v.e[1] = 0xb1;
48
49 /* 0:3 0:1:2 */
50 mset (&(t->ptr_u->v.f));
51
52 mset (&t->a);
53 }
54
55 /* { dg-final { scan-assembler-times "ascii \"0:4.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
56 /* { dg-final { scan-assembler-times "ascii \"0:1:1:3.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
57 /* { dg-final { scan-assembler-times "ascii \"0:1:1:1.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
58 /* { dg-final { scan-assembler-times "ascii \"0:3.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
59 /* { dg-final { scan-assembler-times "ascii \"0:0.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
60 /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:1:1:3\"\\)" 1 } } */
61 /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:4\"\\)" 1 } } */
62 /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:3\"\\)" 2 } } */
63 /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:1:2\"\\)" 1 } } */
64 /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:1:1:1\"\\)" 1 } } */
65 /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:0\"\\)" 1 } } */
66 /* { dg-final { scan-assembler-times "bpfcr_type \\(struct T\\)" 4 } } */
67 /* { dg-final { scan-assembler-times "bpfcr_type \\(struct U\\)" 4 { xfail *-*-* } } } */