From fa4fe2753730f412c00a8a2bab36550c063dfe95 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Mon, 24 Feb 2025 18:11:25 +0000 Subject: libctf: fix cv-qualified unnamed struct/union field lookup GCC permits not only unnamed structs and unions, but cv-qualified ones. Our earlier fix in 6c3a38777b38a2ad87e2b2bcec4567578d1c83ec supported unnamed structs and unions, but only unqualified ones. Resolving away cvr-quals of nameless fields (and, irrelevantly, typedefs) is easy and fixes this problem. Tests adjusted accordingly. libctf/ PR libctf/32746 * ctf-types.c (ctf_member_next): Resolve away cv-quals. (ctf_member_info): Likewise. * testsuite/libctf-lookup/struct-iteration-ctf.c: Add a cv-qualified type or two: make sure to keep a non-qualified one. * testsuite/libctf-lookup/struct-iteration.c: Verify consistency of ctf_member_next and ctf_member_info. * testsuite/libctf-lookup/struct-iteration.lk: Adjust. Tested-by: Stephen Brennan --- libctf/testsuite/libctf-lookup/struct-iteration.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libctf/testsuite/libctf-lookup/struct-iteration.c') diff --git a/libctf/testsuite/libctf-lookup/struct-iteration.c b/libctf/testsuite/libctf-lookup/struct-iteration.c index b240864..fd89ca7 100644 --- a/libctf/testsuite/libctf-lookup/struct-iteration.c +++ b/libctf/testsuite/libctf-lookup/struct-iteration.c @@ -51,11 +51,29 @@ main (int argc, char *argv[]) while ((offset = ctf_member_next (fp, type, &i, &name, &membtype, CTF_MN_RECURSE)) >= 0) { + ctf_membinfo_t memb; char *type_name = ctf_type_aname (fp, membtype); printf ("next test: %s, offset %zx, has type %lx/%s\n", name, offset, membtype, type_name); free (type_name); + + /* Check that we can get the same member via ctf_member_info too. */ + if (name[0] != '\0') + { + if (ctf_member_info (fp, type, name, &memb) != 0) + { + fprintf (stderr, "Cannot get member info for %s: %s\n", + name, ctf_errmsg (ctf_errno (fp))); + exit (1); + } + if (memb.ctm_offset != offset || memb.ctm_type != membtype) + { + fprintf (stderr, "ctf_member_info versus iteration comparison " + "failure: types %lx/%lx, offsets %zx/%lx\n", + membtype, memb.ctm_type, offset, memb.ctm_offset); + } + } } if (ctf_errno (fp) != ECTF_NEXT_END) goto nerr; -- cgit v1.1