https://gcc.gnu.org/g:01c37f9a4f1d272183ea90bab4f5d527089fc3dc

commit r15-6920-g01c37f9a4f1d272183ea90bab4f5d527089fc3dc
Author: Cupertino Miranda <cupertino.mira...@oracle.com>
Date:   Wed Jan 15 14:38:32 2025 +0000

    bpf: set index entry for a VAR_DECL in CO-RE relocs
    
    CO-RE accesses with non pointer struct variables will also generate a
    "0" string access within the CO-RE relocation.
    The first index within the access string, has sort of a different
    meaning then the remaining of the indexes.
    For i0:i1:...:in being an access index for "struct A a" declaration, its
    semantics are represented by:
      (&a + (sizeof(struct A) * i0) + offsetof(i1:...:in)
    
    gcc/ChangeLog:
            * config/bpf/core-builtins.cc (compute_field_expr): Change
            VAR_DECL outcome in switch case.
    
    gcc/testsuite/ChangeLog:
            * gcc.target/bpf/core-builtin-1.c: Correct test.
            * gcc.target/bpf/core-builtin-2.c: Correct test.
            * gcc.target/bpf/core-builtin-exprlist-1.c: Correct test.

Diff:
---
 gcc/config/bpf/core-builtins.cc                        |  5 ++++-
 gcc/testsuite/gcc.target/bpf/core-builtin-1.c          | 16 ++++++++--------
 gcc/testsuite/gcc.target/bpf/core-builtin-2.c          |  3 ++-
 gcc/testsuite/gcc.target/bpf/core-builtin-exprlist-1.c | 16 ++++++++--------
 4 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc
index d4aca38d9381..152da94a9761 100644
--- a/gcc/config/bpf/core-builtins.cc
+++ b/gcc/config/bpf/core-builtins.cc
@@ -698,10 +698,13 @@ compute_field_expr (tree node, unsigned int *accessors,
                              access_node, false, callback);
       return n;
 
+    case VAR_DECL:
+      accessors[0] = 0;
+      return 1;
+
     case ADDR_EXPR:
     case CALL_EXPR:
     case SSA_NAME:
-    case VAR_DECL:
     case PARM_DECL:
       return 0;
     default:
diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-1.c 
b/gcc/testsuite/gcc.target/bpf/core-builtin-1.c
index b4f9998afb8f..0706005f0e5e 100644
--- a/gcc/testsuite/gcc.target/bpf/core-builtin-1.c
+++ b/gcc/testsuite/gcc.target/bpf/core-builtin-1.c
@@ -24,16 +24,16 @@ unsigned long ula[8];
 unsigned long
 func (void)
 {
-  /* 1 */
+  /* 0:1 */
   int b = _(my_s.b);
 
-  /* 2 */
+  /* 0:2 */
   char c = _(my_s.c);
 
-  /* 2:3 */
+  /* 0:2:3 */
   unsigned char uc = _(my_u.uc[3]);
 
-  /* 6 */
+  /* 0:6 */
   unsigned long ul = _(ula[6]);
 
   return b + c + uc + ul;
@@ -55,10 +55,10 @@ u_ptr (union U *pu)
   return x;
 }
 
-/* { dg-final { scan-assembler-times "ascii \"1.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"2:3.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"6.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:1.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2:3.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:6.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "ascii \"0:2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "ascii \"0:2:3.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 
diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-2.c 
b/gcc/testsuite/gcc.target/bpf/core-builtin-2.c
index b72e2566b710..04b3f6b2652a 100644
--- a/gcc/testsuite/gcc.target/bpf/core-builtin-2.c
+++ b/gcc/testsuite/gcc.target/bpf/core-builtin-2.c
@@ -16,11 +16,12 @@ struct S foo;
 
 void func (void)
 {
+  /* 0:1:3:2 */
   char *x = __builtin_preserve_access_index (&foo.u[3].c);
 
   *x = 's';
 }
 
 /* { dg-final { scan-assembler-times "\[\t \]0x4000002\[\t 
\]+\[^\n\]*btt_info" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"1:3:2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:1:3:2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "bpfcr_type" 1 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-exprlist-1.c 
b/gcc/testsuite/gcc.target/bpf/core-builtin-exprlist-1.c
index 8ce4a6e70de7..c53daf81c5fc 100644
--- a/gcc/testsuite/gcc.target/bpf/core-builtin-exprlist-1.c
+++ b/gcc/testsuite/gcc.target/bpf/core-builtin-exprlist-1.c
@@ -31,16 +31,16 @@ func (void)
   int ic;
 
   __builtin_preserve_access_index (({
-    /* 1 */
+    /* 0:1 */
     b = my_s.b;
 
-    /* 2 */
+    /* 0:2 */
     ic = my_s.c;
 
-    /* 2:3 */
+    /* 0:2:3 */
     uc = my_u.uc[3];
 
-    /* 6 */
+    /* 0:6 */
     ul = ula[6];
   }));
 
@@ -65,10 +65,10 @@ u_ptr (union U *pu)
   return x;
 }
 
-/* { dg-final { scan-assembler-times "ascii \"1.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"2:3.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
-/* { dg-final { scan-assembler-times "ascii \"6.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:1.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2:3.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:6.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "ascii \"0:2.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "ascii \"0:2:3.0\"\[\t 
\]+\[^\n\]*btf_aux_string" 1 } } */

Reply via email to