https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100695

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Created attachment 53233
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53233&action=edit
Patch which does not work (segfault during self test) – but maybe it gives an
idea how to solve the issue

I think there are multiple issues:

(a) '%T' does not accept %qT but there is still an error for using %<%T%>

(b) Using %qT should be accepted. This implies both the addition of "q" to
      c-family/c-format.cc's gcc_dump_printf_char_table
    to permit it.

(c) Using %qT kind of works - but does not actually print the quotes.
    (cf. comment 1)

That's because of how it is processed. In pretty-print.cc pp_format:

      if (quote)
        pp_begin_quote (pp, pp_show_color (pp));
...
            ok = pp_format_decoder (pp) (pp, text, p,
                                         precision, wide, plus, hash, &quote,
                                         formatters[argno]);
...
      if (quote)
        pp_end_quote (pp, pp_show_color (pp));

This works well, if the item - is processed directly.
For instance, tree-diagnostic.cc's default_tree_printer just does:

    case 'E':
...
          pp_identifier (pp, IDENTIFIER_POINTER (t));
          return true;

However, in dumpfile.cc's dump_pretty_printer::decode_format there is no direct
output but the %qT processing is deferred (spec = 'T', buffer_ptr = "qT"):

dump_pretty_printer::decode_format (text_info *text, const char *spec,
                                       const char **buffer_ptr)
{
  /* Various format codes that imply making an optinfo_item and stashed it
     for later use (to capture metadata, rather than plain text).  */
...

    case 'T':
      {
        tree t = va_arg (*text->args_ptr, tree);

        /* Make an item for the tree, and stash it.  */
        optinfo_item *item = make_item_for_dump_generic_expr (t, TDF_SLIM);
        stash_item (buffer_ptr, item);
        return true;

And the 'stash_item' effectively undoes the quote. For %<...%>, those are
processed separately, such that 'decode_format' only processes '%T' and the
quotes are retained.

Thus, one way would be to 'obstack_grow' - or something like that to "split"
'q' ... 'T' in %qT. Or to handle somehow the
  pp_buffer(pp)
in dump_pretty_printer::decode_format

Reply via email to