if (TREE_CODE (node) == FIELD_DECL)
{
const tree container = DECL_CONTEXT (node);
- const char * name = IDENTIFIER_POINTER (DECL_NAME (node));
/* Lookup the CTF type info for the containing type. */
dw_die_ref die = lookup_type_die (container);
if (kind != CTF_K_STRUCT && kind != CTF_K_UNION)
return -1;
+ tree field = TYPE_FIELDS (container);
int i = 0;
ctf_dmdef_t * dmd;
for (dmd = dtd->dtd_u.dtu_members;
dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd))
{
- if (get_btf_id (dmd->dmd_type) > BTF_MAX_TYPE)
- continue;
- if (strcmp (dmd->dmd_name, name) == 0)
- return i;
- i++;
+ bool field_has_btf = get_btf_id (dmd->dmd_type) <= BTF_MAX_TYPE;
+
+ if (field == node)
+ return field_has_btf ? i : -1;
+
+ if (field_has_btf)
+ i++;
+
+ field = DECL_CHAIN (field);
}
}
return -1;
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O0 -gbtf -dA -mco-re" } */
+
+struct weird
+{
+ struct
+ {
+ int b;
+ };
+
+ char x;
+
+ union
+ {
+ int a;
+ int c;
+ };
+};
+
+
+int test (struct weird *arg) {
+ int *x = __builtin_preserve_access_index (&arg->b);
+ int *y = __builtin_preserve_access_index (&arg->c);
+
+ return *x + *y;
+}
+
+
+/* { dg-final { scan-assembler-times "ascii \"0:0:0.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2:1.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */