On Thu, Nov 15, 2018 at 2:31 PM Michael Matz <[email protected]> wrote:
>
> Hi,
>
> On Thu, 15 Nov 2018, Richard Biener wrote:
>
> > > Okay, probably. Then consider the same patch with sprinkling casts to
> > > long for all these arguments (the actual numbers will fit that type in
> > > reality). I could of course also use PRIu64 but that makes my eyes
> > > bleed.
> >
> > Hmm. Can you use PRIu64 please and cast to uint64_t? OK with that
> > change.
>
> Instead I'd like to check in this. It adds a new macro expanding to
> "%" #n PRIu64 "%c"
> (with n being the width) corresponding to one SIZE_AMOUNT macro "argument"
> (which are actually two arguments), and hides the cast in the latter macro
> itself. At least the number of format string args and actual args
> corresponds again then and my eyes bleed a little less. Still okay?
Works for me.
Richard.
>
> Ciao,
> Michael.
>
> * system.h (PRsa): New macro.
> (SIZE_AMOUNT): Cast number to uint64_t.
> * alloc-pool.h (pool_usage::dump): Don't use %zu but PRsa.
> (pool_usage::dump_footer): Likewise and also use PRIu64.
> * bitmap.h (bitmap_usage::dump): Likewise.
> * ggc-common.c (ggc_usage::dump): Likewise.
> * ggc-page.c (ggc_print_statistics): Likewise.
> * mem-stats.h (mem_usage::dump): Likewise.
> (mem_usage::dump_footer): Likewise.
> * rtl.c (dump_rtx_statistics): Likewise.
> * vec.c (vec_usage::dump): Likewise.
> (vec_usage::dump_footer): Likewise.
>
> diff --git a/gcc/alloc-pool.h b/gcc/alloc-pool.h
> index d17a05ca4fb1..81cb69e227ab 100644
> --- a/gcc/alloc-pool.h
> +++ b/gcc/alloc-pool.h
> @@ -63,8 +63,8 @@ struct pool_usage: public mem_usage
> {
> char *location_string = loc->to_string ();
>
> - fprintf (stderr, "%-32s%-48s %5zu%c%9zu%c:%5.1f%%%9zu"
> - "%c%9zu%c:%5.1f%%%12zu\n",
> + fprintf (stderr, "%-32s%-48s " PRsa(5) PRsa(9) ":%5.1f%%"
> + PRsa(9) PRsa(9) ":%5.1f%%%12" PRIu64 "\n",
> m_pool_name, location_string,
> SIZE_AMOUNT (m_instances),
> SIZE_AMOUNT (m_allocated),
> @@ -72,7 +72,7 @@ struct pool_usage: public mem_usage
> SIZE_AMOUNT (m_peak),
> SIZE_AMOUNT (m_times),
> get_percent (m_times, total.m_times),
> - m_element_size);
> + (uint64_t)m_element_size);
>
> free (location_string);
> }
> @@ -91,7 +91,7 @@ struct pool_usage: public mem_usage
> dump_footer ()
> {
> print_dash_line ();
> - fprintf (stderr, "%s%82zu%c%10zu%c\n", "Total",
> + fprintf (stderr, "%s" PRsa(82) PRsa(10) "\n", "Total",
> SIZE_AMOUNT (m_instances), SIZE_AMOUNT (m_allocated));
> print_dash_line ();
> }
> diff --git a/gcc/bitmap.h b/gcc/bitmap.h
> index 973ea846baf1..9a180daa7454 100644
> --- a/gcc/bitmap.h
> +++ b/gcc/bitmap.h
> @@ -239,9 +239,9 @@ struct bitmap_usage: public mem_usage
> {
> char *location_string = loc->to_string ();
>
> - fprintf (stderr, "%-48s %9zu%c:%5.1f%%"
> - "%9zu%c%9zu%c:%5.1f%%"
> - "%11" PRIu64 "%c%11" PRIu64 "%c%10s\n",
> + fprintf (stderr, "%-48s " PRsa (9) ":%5.1f%%"
> + PRsa (9) PRsa (9) ":%5.1f%%"
> + PRsa (11) PRsa (11) "%10s\n",
> location_string, SIZE_AMOUNT (m_allocated),
> get_percent (m_allocated, total.m_allocated),
> SIZE_AMOUNT (m_peak), SIZE_AMOUNT (m_times),
> diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c
> index 9fdba23ce4c2..c989fb01e669 100644
> --- a/gcc/ggc-common.c
> +++ b/gcc/ggc-common.c
> @@ -884,8 +884,8 @@ struct ggc_usage: public mem_usage
> {
> size_t balance = get_balance ();
> fprintf (stderr,
> - "%-48s %9zu%c:%5.1f%%%9zu%c:%5.1f%%"
> - "%9zu%c:%5.1f%%%9zu%c:%5.1f%%%9zu%c\n",
> + "%-48s " PRsa (9) ":%5.1f%%" PRsa (9) ":%5.1f%%"
> + PRsa (9) ":%5.1f%%" PRsa (9) ":%5.1f%%" PRsa (9) "\n",
> prefix, SIZE_AMOUNT (m_collected),
> get_percent (m_collected, total.m_collected),
> SIZE_AMOUNT (m_freed), get_percent (m_freed, total.m_freed),
> diff --git a/gcc/ggc-page.c b/gcc/ggc-page.c
> index 00c2864711f0..f04b22ca8cca 100644
> --- a/gcc/ggc-page.c
> +++ b/gcc/ggc-page.c
> @@ -2288,14 +2288,15 @@ ggc_print_statistics (void)
> overhead += (sizeof (page_entry) - sizeof (long)
> + BITMAP_SIZE (OBJECTS_IN_PAGE (p) + 1));
> }
> - fprintf (stderr, "%-8zu %10zu%c %10zu%c %10zu%c\n",
> - OBJECT_SIZE (i),
> + fprintf (stderr, "%-8" PRIu64 " " PRsa (10) " " PRsa (10) " "
> + PRsa (10) "\n",
> + (uint64_t)OBJECT_SIZE (i),
> SIZE_AMOUNT (allocated),
> SIZE_AMOUNT (in_use),
> SIZE_AMOUNT (overhead));
> total_overhead += overhead;
> }
> - fprintf (stderr, "%-8s %10zu%c %10zu%c %10zu%c\n",
> + fprintf (stderr, "%-8s " PRsa (10) " " PRsa (10) " " PRsa (10) "\n",
> "Total",
> SIZE_AMOUNT (G.bytes_mapped),
> SIZE_AMOUNT (G.allocated),
> @@ -2306,42 +2307,42 @@ ggc_print_statistics (void)
> fprintf (stderr, "\nTotal allocations and overheads during "
> "the compilation process\n");
>
> - fprintf (stderr, "Total Overhead: %9"
> - HOST_LONG_LONG_FORMAT "d%c\n",
> + fprintf (stderr, "Total Overhead: "
> + PRsa (9) "\n",
> SIZE_AMOUNT (G.stats.total_overhead));
> - fprintf (stderr, "Total Allocated: %9"
> - HOST_LONG_LONG_FORMAT "d%c\n",
> + fprintf (stderr, "Total Allocated: "
> + PRsa (9) "\n",
> SIZE_AMOUNT (G.stats.total_allocated));
>
> - fprintf (stderr, "Total Overhead under 32B: %9"
> - HOST_LONG_LONG_FORMAT "d%c\n",
> + fprintf (stderr, "Total Overhead under 32B: "
> + PRsa (9) "\n",
> SIZE_AMOUNT (G.stats.total_overhead_under32));
> - fprintf (stderr, "Total Allocated under 32B: %9"
> - HOST_LONG_LONG_FORMAT "d%c\n",
> + fprintf (stderr, "Total Allocated under 32B: "
> + PRsa (9) "\n",
> SIZE_AMOUNT (G.stats.total_allocated_under32));
> - fprintf (stderr, "Total Overhead under 64B: %9"
> - HOST_LONG_LONG_FORMAT "d%c\n",
> + fprintf (stderr, "Total Overhead under 64B: "
> + PRsa (9) "\n",
> SIZE_AMOUNT (G.stats.total_overhead_under64));
> - fprintf (stderr, "Total Allocated under 64B: %9"
> - HOST_LONG_LONG_FORMAT "d%c\n",
> + fprintf (stderr, "Total Allocated under 64B: "
> + PRsa (9) "\n",
> SIZE_AMOUNT (G.stats.total_allocated_under64));
> - fprintf (stderr, "Total Overhead under 128B: %9"
> - HOST_LONG_LONG_FORMAT "d%c\n",
> + fprintf (stderr, "Total Overhead under 128B: "
> + PRsa (9) "\n",
> SIZE_AMOUNT (G.stats.total_overhead_under128));
> - fprintf (stderr, "Total Allocated under 128B: %9"
> - HOST_LONG_LONG_FORMAT "d%c\n",
> + fprintf (stderr, "Total Allocated under 128B: "
> + PRsa (9) "\n",
> SIZE_AMOUNT (G.stats.total_allocated_under128));
>
> for (i = 0; i < NUM_ORDERS; i++)
> if (G.stats.total_allocated_per_order[i])
> {
> - fprintf (stderr, "Total Overhead page size %9zu: %9"
> - HOST_LONG_LONG_FORMAT "d%c\n",
> - OBJECT_SIZE (i),
> + fprintf (stderr, "Total Overhead page size %9" PRIu64 ": "
> + PRsa (9) "\n",
> + (uint64_t)OBJECT_SIZE (i),
> SIZE_AMOUNT (G.stats.total_overhead_per_order[i]));
> - fprintf (stderr, "Total Allocated page size %9zu: %9"
> - HOST_LONG_LONG_FORMAT "d%c\n",
> - OBJECT_SIZE (i),
> + fprintf (stderr, "Total Allocated page size %9" PRIu64 ": "
> + PRsa (9) "\n",
> + (uint64_t)OBJECT_SIZE (i),
> SIZE_AMOUNT (G.stats.total_allocated_per_order[i]));
> }
> }
> diff --git a/gcc/mem-stats.h b/gcc/mem-stats.h
> index 6ab92211cf47..219959faa992 100644
> --- a/gcc/mem-stats.h
> +++ b/gcc/mem-stats.h
> @@ -205,8 +205,8 @@ struct mem_usage
> {
> char *location_string = loc->to_string ();
>
> - fprintf (stderr, "%-48s %9zu%c:%5.1f%%"
> - "%9zu%c%9zu%c:%5.1f%%%10s\n",
> + fprintf (stderr, "%-48s " PRsa (9) ":%5.1f%%"
> + PRsa (9) PRsa (9) ":%5.1f%%%10s\n",
> location_string, SIZE_AMOUNT (m_allocated),
> get_percent (m_allocated, total.m_allocated),
> SIZE_AMOUNT (m_peak), SIZE_AMOUNT (m_times),
> @@ -220,7 +220,7 @@ struct mem_usage
> dump_footer () const
> {
> print_dash_line ();
> - fprintf (stderr, "%s%53zu%c%26zu%c\n", "Total",
> + fprintf (stderr, "%s" PRsa (53) PRsa (26) "\n", "Total",
> SIZE_AMOUNT (m_allocated), SIZE_AMOUNT (m_times));
> print_dash_line ();
> }
> diff --git a/gcc/rtl.c b/gcc/rtl.c
> index bf897bf75b4e..2ab349981d9b 100644
> --- a/gcc/rtl.c
> +++ b/gcc/rtl.c
> @@ -821,7 +821,7 @@ dump_rtx_statistics (void)
> unsigned j = indices[i];
> if (rtx_alloc_counts[j])
> {
> - fprintf (stderr, "%-24s %6zu%c %9zu%c\n",
> + fprintf (stderr, "%-24s " PRsa (6) " " PRsa (9) "\n",
> GET_RTX_NAME (j),
> SIZE_AMOUNT (rtx_alloc_counts[j]),
> SIZE_AMOUNT (rtx_alloc_sizes[j]));
> @@ -832,14 +832,14 @@ dump_rtx_statistics (void)
>
> if (rtvec_alloc_counts)
> {
> - fprintf (stderr, "%-24s %6zu%c %9zu%c\n", "rtvec",
> + fprintf (stderr, "%-24s " PRsa (6) " " PRsa (9) "\n", "rtvec",
> SIZE_AMOUNT (rtvec_alloc_counts),
> SIZE_AMOUNT (rtvec_alloc_sizes));
> total_counts += rtvec_alloc_counts;
> total_sizes += rtvec_alloc_sizes;
> }
> fprintf (stderr, "-----------------------------------------------\n");
> - fprintf (stderr, "%-24s %6d%c %9d%c\n",
> + fprintf (stderr, "%-24s " PRsa (6) " " PRsa (9) "\n",
> "Total", SIZE_AMOUNT (total_counts),
> SIZE_AMOUNT (total_sizes));
> fprintf (stderr, "-----------------------------------------------\n");
> diff --git a/gcc/system.h b/gcc/system.h
> index ba328213a693..d23300f5e5db 100644
> --- a/gcc/system.h
> +++ b/gcc/system.h
> @@ -1231,6 +1231,10 @@ void gcc_stablesort (void *, size_t, size_t,
> /* Display an integer amount as multiple of 1K or 1M (in base 2).
> Display the correct unit (either k, M, or ' ') after the amount, as
> well. */
> -#define SIZE_AMOUNT(size) SIZE_SCALE (size), SIZE_LABEL (size)
> +#define SIZE_AMOUNT(size) (uint64_t)SIZE_SCALE (size), SIZE_LABEL (size)
> +
> +/* Format string particle for printing a SIZE_AMOUNT with N being the width
> + of the number. */
> +#define PRsa(n) "%" #n PRIu64 "%c"
>
> #endif /* ! GCC_SYSTEM_H */
> diff --git a/gcc/vec.c b/gcc/vec.c
> index bd49d0358c5c..c08ef0445af6 100644
> --- a/gcc/vec.c
> +++ b/gcc/vec.c
> @@ -83,13 +83,13 @@ struct vec_usage: public mem_usage
> s[48] = '\0';
>
> fprintf (stderr,
> - "%-48s %10zu%10zu%c:%4.1f%%%9zu%c%10zu"
> - ":%4.1f%%%10zu%c%10zu%c\n",
> + "%-48s %10" PRIu64 PRsa (10) ":%4.1f%%" PRsa (9) "%10" PRIu64
> + ":%4.1f%%" PRsa (10) PRsa (10) "\n",
> s,
> - m_element_size,
> + (uint64_t)m_element_size,
> SIZE_AMOUNT (m_allocated),
> m_allocated * 100.0 / total.m_allocated,
> - SIZE_AMOUNT (m_peak), m_times,
> + SIZE_AMOUNT (m_peak), (uint64_t)m_times,
> m_times * 100.0 / total.m_times,
> SIZE_AMOUNT (m_items), SIZE_AMOUNT (m_items_peak));
> }
> @@ -99,7 +99,7 @@ struct vec_usage: public mem_usage
> dump_footer ()
> {
> print_dash_line ();
> - fprintf (stderr, "%s%64zu%c%25zu%c%16zu%c\n",
> + fprintf (stderr, "%s" PRsa (64) PRsa (25) PRsa (16) "\n",
> "Total", SIZE_AMOUNT (m_allocated),
> SIZE_AMOUNT (m_times), SIZE_AMOUNT (m_items));
> print_dash_line ();