David Faust writes:
> On 3/13/24 07:24, Cupertino Miranda wrote: >> Any unnamed structure field if not a member of the BTF_KIND_STRUCT. > typo: if -> is > > I'd suggest to clarify that "any unnamed structure field" is really > any unnamed non-struct-or-union field, since anonymous inner structs > and unions certainly are present in BTF (and you handle them here). > >> 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. > > Otherwise, OK. > Thanks. Corrected and Pushed. Thanks > >> >> 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. >> --- >> gcc/config/bpf/core-builtins.cc | 6 +++++- >> .../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 70b14e48e6e5..8333ad81d0e0 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 27654205287d..8b1d8b012a2a 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 } } */