Explicitly mention yet-unloaded shared libraries in location spec examples
[binutils-gdb.git] / libctf / ctf-decl.c
index 5dcf60ab08bdbac42b3dc459ac89fb48c4fa6905..e56bbb334cd13b8ef035a99ed2e765776d701817 100644 (file)
@@ -1,5 +1,5 @@
 /* C declarator syntax glue.
-   Copyright (C) 2019-2020 Free Software Foundation, Inc.
+   Copyright (C) 2019-2022 Free Software Foundation, Inc.
 
    This file is part of libctf.
 
@@ -68,10 +68,11 @@ ctf_decl_fini (ctf_decl_t *cd)
          free (cdp);
        }
     }
+  free (cd->cd_buf);
 }
 
 void
-ctf_decl_push (ctf_decl_t *cd, ctf_file_t *fp, ctf_id_t type)
+ctf_decl_push (ctf_decl_t *cd, ctf_dict_t *fp, ctf_id_t type)
 {
   ctf_decl_node_t *cdp;
   ctf_decl_prec_t prec;
@@ -116,9 +117,10 @@ ctf_decl_push (ctf_decl_t *cd, ctf_file_t *fp, ctf_id_t type)
       break;
 
     case CTF_K_SLICE:
+      /* Slices themselves have no print representation and should not appear in
+        the decl stack.  */
       ctf_decl_push (cd, fp, ctf_type_reference (fp, type));
-      prec = CTF_PREC_BASE;
-      break;
+      return;
 
     case CTF_K_VOLATILE:
     case CTF_K_CONST:
@@ -151,11 +153,10 @@ ctf_decl_push (ctf_decl_t *cd, ctf_file_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);
@@ -195,5 +196,7 @@ void ctf_decl_sprintf (ctf_decl_t *cd, const char *format, ...)
 
 char *ctf_decl_buf (ctf_decl_t *cd)
 {
-  return cd->cd_buf;
+  char *buf = cd->cd_buf;
+  cd->cd_buf = NULL;
+  return buf;
 }