diff mbox series

value-prof: Fix abs uses in value-prof.c [PR93962]

Message ID 20200311080528.GD2156@tucnak
State New
Headers show
Series value-prof: Fix abs uses in value-prof.c [PR93962] | expand

Commit Message

Li, Pan2 via Gcc-patches March 11, 2020, 8:05 a.m. UTC
Hi!

Jeff has recently fixed dump_histogram_value to use std::abs instead of abs,
because on FreeBSD apparently the ::abs isn't overloaded and only has
int abs (int);
Seems on Solaris /usr/include/iso/stdlib_iso.h abs has:
int abs (int);
long abs (long);
overloads but already not
long long abs (long long);
and there is another abs use in get_nth_most_common_value, also on int64_t.
The long long std::abs (long long); overload is there only in C++11 and we
in GCC10 still support C++98.

Martin has said that a counter should never be INT64_MIN, so IMHO it is
better to use abs_hwi which will assert that.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2020-03-11  Jakub Jelinek  <jakub@redhat.com>

	PR bootstrap/93962
	* value-prof.c (dump_histogram_value): Use abs_hwi instead of
	std::abs.
	(get_nth_most_common_value): Use abs_hwi instead of abs.


	Jakub

Comments

Richard Biener March 11, 2020, 8:20 a.m. UTC | #1
On Wed, 11 Mar 2020, Jakub Jelinek wrote:

> Hi!
> 
> Jeff has recently fixed dump_histogram_value to use std::abs instead of abs,
> because on FreeBSD apparently the ::abs isn't overloaded and only has
> int abs (int);
> Seems on Solaris /usr/include/iso/stdlib_iso.h abs has:
> int abs (int);
> long abs (long);
> overloads but already not
> long long abs (long long);
> and there is another abs use in get_nth_most_common_value, also on int64_t.
> The long long std::abs (long long); overload is there only in C++11 and we
> in GCC10 still support C++98.
> 
> Martin has said that a counter should never be INT64_MIN, so IMHO it is
> better to use abs_hwi which will assert that.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK but using absu_hwi and an unsigned format would have been safer I 
guess.

Thanks,
Richard.

> 2020-03-11  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR bootstrap/93962
> 	* value-prof.c (dump_histogram_value): Use abs_hwi instead of
> 	std::abs.
> 	(get_nth_most_common_value): Use abs_hwi instead of abs.
> 
> --- gcc/value-prof.c.jj	2020-03-05 07:58:02.693135980 +0100
> +++ gcc/value-prof.c	2020-03-10 15:51:14.094854715 +0100
> @@ -266,7 +266,7 @@ dump_histogram_value (FILE *dump_file, h
>  	  if (hist->hvalue.counters)
>  	    {
>  	      fprintf (dump_file, " all: %" PRId64 "%s, values: ",
> -		       std::abs ((int64_t) hist->hvalue.counters[0]),
> +		       (int64_t) abs_hwi (hist->hvalue.counters[0]),
>  		       hist->hvalue.counters[0] < 0
>  		       ? " (values missing)": "");
>  	      for (unsigned i = 0; i < GCOV_TOPN_VALUES; i++)
> @@ -743,7 +743,7 @@ get_nth_most_common_value (gimple *stmt,
>    *count = 0;
>    *value = 0;
>  
> -  gcov_type read_all = abs (hist->hvalue.counters[0]);
> +  gcov_type read_all = abs_hwi (hist->hvalue.counters[0]);
>  
>    gcov_type v = hist->hvalue.counters[2 * n + 1];
>    gcov_type c = hist->hvalue.counters[2 * n + 2];
> 
> 	Jakub
> 
>
diff mbox series

Patch

--- gcc/value-prof.c.jj	2020-03-05 07:58:02.693135980 +0100
+++ gcc/value-prof.c	2020-03-10 15:51:14.094854715 +0100
@@ -266,7 +266,7 @@  dump_histogram_value (FILE *dump_file, h
 	  if (hist->hvalue.counters)
 	    {
 	      fprintf (dump_file, " all: %" PRId64 "%s, values: ",
-		       std::abs ((int64_t) hist->hvalue.counters[0]),
+		       (int64_t) abs_hwi (hist->hvalue.counters[0]),
 		       hist->hvalue.counters[0] < 0
 		       ? " (values missing)": "");
 	      for (unsigned i = 0; i < GCOV_TOPN_VALUES; i++)
@@ -743,7 +743,7 @@  get_nth_most_common_value (gimple *stmt,
   *count = 0;
   *value = 0;
 
-  gcov_type read_all = abs (hist->hvalue.counters[0]);
+  gcov_type read_all = abs_hwi (hist->hvalue.counters[0]);
 
   gcov_type v = hist->hvalue.counters[2 * n + 1];
   gcov_type c = hist->hvalue.counters[2 * n + 2];