diff options
author | Cupertino Miranda <cupertino.miranda@oracle.com> | 2024-03-08 13:33:42 +0000 |
---|---|---|
committer | Cupertino Miranda <cupertino.miranda@oracle.com> | 2024-03-20 20:27:16 +0000 |
commit | f10c18df9c02dc518360426c021971838e0012d2 (patch) | |
tree | 22bda6703d1f7f26ac42dd12e04fa8d52440ea9f | |
parent | 624d025f62fdbc969cca08fdb1ac77246b8535a5 (diff) | |
download | gcc-f10c18df9c02dc518360426c021971838e0012d2.zip gcc-f10c18df9c02dc518360426c021971838e0012d2.tar.gz gcc-f10c18df9c02dc518360426c021971838e0012d2.tar.bz2 |
bpf: Corrected index computation when present with unnamed struct fields
Any unnamed non-struct-or-union field is not a member of the
BTF_KIND_STRUCT.
For that reason, CO-RE access strings indexes should take that in
consideration. This patch adds a condition to the incrementer that
computes the index for the field access.
gcc/ChangeLog:
* config/bpf/core-builtins.cc (bpf_core_get_index): Check if
field contains a DECL_NAME.
gcc/testsuite/ChangeLog:
* gcc.target/bpf/core-builtin-fieldinfo-offset-1.c: Add
testcase for unnamed fields.
-rw-r--r-- | gcc/config/bpf/core-builtins.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c | 10 |
2 files changed, 13 insertions, 3 deletions
diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc index 70b14e4..8333ad8 100644 --- a/gcc/config/bpf/core-builtins.cc +++ b/gcc/config/bpf/core-builtins.cc @@ -553,7 +553,11 @@ bpf_core_get_index (const tree node, bool *valid) { if (l == node) return i; - i++; + /* Skip unnamed padding, not represented by BTF. */ + if (DECL_NAME(l) != NULL_TREE + || TREE_CODE (TREE_TYPE (l)) == UNION_TYPE + || TREE_CODE (TREE_TYPE (l)) == RECORD_TYPE) + i++; } } else if (code == ARRAY_REF || code == ARRAY_RANGE_REF || code == MEM_REF) diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c b/gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c index 2765420..8b1d8b0 100644 --- a/gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c +++ b/gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c @@ -14,6 +14,9 @@ struct T { struct S s[2]; char c; char d; + int a: 1; + int:31; + int f; }; enum { @@ -38,7 +41,9 @@ unsigned int foo (struct T *t) unsigned e1 = __builtin_preserve_field_info (bar()->d, FIELD_BYTE_OFFSET); unsigned e2 = __builtin_preserve_field_info (bar()->s[1].a4, FIELD_BYTE_OFFSET); - return s0a1 + s0a4 + s0x + s1a1 + s1a4 + s1x + c + d + e1 + e2; + unsigned f1 = __builtin_preserve_field_info (t->f, FIELD_BYTE_OFFSET); + + return s0a1 + s0a4 + s0x + s1a1 + s1a4 + s1x + c + d + e1 + e2 + f1; } /* { dg-final { scan-assembler-times "\[\t \]mov\[\t \]%r\[0-9\],4" 2 } } */ @@ -65,5 +70,6 @@ unsigned int foo (struct T *t) /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:1:1:4\"\\)" 1 } } */ /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:2\"\\)" 1 } } */ /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:3\"\\)" 2 } } */ +/* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:5\"\\)" 1 } } */ -/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bpfcr_kind" 10 } } */ +/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bpfcr_kind" 11 } } */ |