[binutils-gdb] libctf: do not print array declarators backwards

Nick Alcock nix@sourceware.org
Tue Jan 5 15:02:01 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b09ad6eae985c6cf3138775de8e712bc116b4166

commit b09ad6eae985c6cf3138775de8e712bc116b4166
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jan 5 13:25:56 2021 +0000

    libctf: do not print array declarators backwards
    
    The CTF declarator stack code (used by ctf_type_aname() and thus
    ultimately by ctf-dump.c and objdump --ctf etc) contains careful
    code to prepend array declarators to the stack it's building up
    on the grounds that array declarators are ordered inside out: only
    they're not, they're ordered outside in.
    
    This has led to our (non-upstreamed) compiler emitting array declarators
    backwards for years, because it looks backwards in the dumper unless
    it's actually emitted backwards into the CTF so the dumper can wrongly
    reverse it again: but
    
      int[5][6]
    
    should be an array of 6 int[5]s, not an array of 5 int[6]'s, so even if
    the dumper gets it right, actual users calling ctf_array_info are going
    to see a completely wrong type graph with the wrong bounds in it.
    
    Fix trivial.
    
    libctf/ChangeLog
    2021-01-05  Nick Alcock  <nick.alcock@oracle.com>
    
            * ctf-decl.c (ctf_decl_push): Don't print array decls backwards.

Diff:
---
 libctf/ChangeLog  | 4 ++++
 libctf/ctf-decl.c | 5 ++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index fec02cea156..cc8e34a3a22 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,7 @@
+2021-01-05  Nick Alcock  <nick.alcock@oracle.com>
+
+	* ctf-decl.c (ctf_decl_push): Don't print array decls backwards.
+
 2021-01-04  Nicolas Boulenguez  <nicolas@debian.org>
 
 	PR 27117
diff --git a/libctf/ctf-decl.c b/libctf/ctf-decl.c
index f18ca964c93..232ff5d71c0 100644
--- a/libctf/ctf-decl.c
+++ b/libctf/ctf-decl.c
@@ -152,11 +152,10 @@ ctf_decl_push (ctf_decl_t *cd, ctf_dict_t *fp, ctf_id_t type)
   if (prec > cd->cd_qualp && prec < CTF_PREC_ARRAY)
     cd->cd_qualp = prec;
 
-  /* C array declarators are ordered inside out so prepend them.  Also by
-     convention qualifiers of base types precede the type specifier (e.g.
+  /* By convention qualifiers of base types precede the type specifier (e.g.
      const int vs. int const) even though the two forms are equivalent.  */
 
-  if (kind == CTF_K_ARRAY || (is_qual && prec == CTF_PREC_BASE))
+  if (is_qual && prec == CTF_PREC_BASE)
     ctf_list_prepend (&cd->cd_nodes[prec], cdp);
   else
     ctf_list_append (&cd->cd_nodes[prec], cdp);


More information about the Binutils-cvs mailing list