[Bug other/100695] Format decoder, quoting in 'dump_printf' etc.

2022-07-01 Thread burnus at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100695

--- Comment #2 from Tobias Burnus  ---
Created attachment 53233
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53233=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, ,
 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

[Bug other/100695] Format decoder, quoting in 'dump_printf' etc.

2021-06-09 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100695

Jakub Jelinek  changed:

   What|Removed |Added

 CC||burnus at gcc dot gnu.org,
   ||jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek  ---
As an example, can be reproduced e.g. on
./cc1 -quiet -fopt-info-omp-note --param=openacc-privatization=noisy -fopenacc
-O2 .../gcc/testsuite/c-c++-common/goacc/privatization-1-routine_gang-loop.c
when that omp-low.c %<%T%> is changed to %qT.

>From what I see, the quotes for %< are emitted using:
case '<':
  {
obstack_grow (>chunk_obstack,
  open_quote, strlen (open_quote));
const char *colorstr
  = colorize_start (pp_show_color (pp), "quote");
obstack_grow (>chunk_obstack, colorstr, strlen (colorstr));
but for %qX using:
  if (quote)
pp_begin_quote (pp, pp_show_color (pp));
and similarly for the closing quote.
In the case of dump_print_*, the characters go into chunk_obstack, while e.g.
what '%T' provides goes to the stashed items or where.