Bug 60832 - add pretty-printer code for double-int/wide-int
Summary: add pretty-printer code for double-int/wide-int
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, easyhack
Depends on:
Blocks:
 
Reported: 2014-04-13 15:04 UTC by Manuel López-Ibáñez
Modified: 2018-01-27 19:52 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-04-14 00:00:00


Attachments
WIP patch (1.79 KB, patch)
2014-04-13 15:04 UTC, Manuel López-Ibáñez
Details | Diff
add %Wi %Wu %Wd for pretty-printing wides_int (1.97 KB, patch)
2015-09-21 11:04 UTC, Manuel López-Ibáñez
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel López-Ibáñez 2014-04-13 15:04:55 UTC
Created attachment 32590 [details]
WIP patch

Currently, there is no pretty-printer code to print a double-int (or wide-int) in a warning. This would be useful for cases such as the one in the attached patch. The current method prints '3u' instead of just '3', as it should.
Comment 1 Richard Biener 2014-04-14 08:42:16 UTC
Confirmed.  Btw, the fallback of using hex-style printing for too large double-ints is bad.  Better go via GMP and its sprintf ability.
Comment 2 Manuel López-Ibáñez 2015-09-21 10:11:56 UTC
Author: manu
Date: Mon Sep 21 10:11:24 2015
New Revision: 227964

URL: https://gcc.gnu.org/viewcvs?rev=227964&root=gcc&view=rev
Log:
[PR middle-end/60832] Do not convert widest_int to tree just for printing it.

In do_warn_aggressive_loop_optimizations, we convert to a tree just to print a
widest_int. Apart from overly complicated, this results in printing '3u'
instead of just '3'.

Unfortunately, adding a printf-like conversion specifier would require making
pretty-print.c link with wide-int.cc, which will include a lot of new
dependencies into several other programs (gcov-tool for example). It would be
possible to add the conversion specifier to every FE pretty-printer, but this
still would require updating c-format.c, which is far from trivial. A simpler
approach is to convert to a string rather than to a tree.

In addition, "iteration 3 invokes undefined behavior within this loop" seems to
me clearer than "iteration 3 invokes undefined behavior; containing loop".

gcc/testsuite/ChangeLog:

2015-09-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR middle-end/60832
	* gcc.dg/pr53265.c: Update.

gcc/ChangeLog:

2015-09-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR middle-end/60832
	* tree-ssa-loop-niter.c (do_warn_aggressive_loop_optimizations):
	Print i_bound without converting it to a tree.



Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/pr53265.c
    trunk/gcc/tree-ssa-loop-niter.c
Comment 3 Manuel López-Ibáñez 2015-09-21 11:04:21 UTC
Created attachment 36361 [details]
add %Wi %Wu %Wd for pretty-printing wides_int

This fails bootstrap at:

libcommon.a(pretty-print.o): In function `pp_format(pretty_printer*, text_info*)':
/home/manuel/test1/src/gcc/pretty-print.c:543: undefined reference to `print_dec(generic_wide_int<wide_int_ref_storage<false> > const&, char*, signop)'
/home/manuel/test1/src/gcc/pretty-print.c:573: undefined reference to `print_dec(generic_wide_int<wide_int_ref_storage<false> > const&, char*, signop)'
collect2: error: ld returned 1 exit status
make: *** [gcov] Error 1

pretty-print.c is used all over the place and adding a dependency on wide-int.cc will bring gmp and other stuff that is currently  not used (nor linked with) various helper programs. If wide-int is only printed in the middle-end, perhaps it is sufficient to add it to default_tree_printer. Otherwise, it needs to be added to every FE. This is not difficult just tedious. The difficult part is the c-format.c changes (I wish someone would fix https://gcc.gnu.org/PR47781 so we can use a simpler syntax to define our custom specifiers; in addition to the positive synergies it will bring with other GNU projects that use custom specifiers and wish to use -Wformat).