* [PATCH] gcov: Fix wrong usage of NAN in statistics (PR gcov-profile/86536).
@ 2018-07-24 7:24 Martin Liška
0 siblings, 0 replies; only message in thread
From: Martin Liška @ 2018-07-24 7:24 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 932 bytes --]
Hi.
We have situations where a branch can return more often than called (fork).
Thus I decided to rapidly simplify format_gcov and print ratios that are
provided. No extra values are handled now.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
If no objections, I'll install the patch in couple of days.
Martin
gcc/ChangeLog:
2018-07-20 Martin Liska <mliska@suse.cz>
PR gcov-profile/86536
* gcov.c (format_gcov): Use printf format %.*f directly
and do not handle special values.
gcc/testsuite/ChangeLog:
2018-07-20 Martin Liska <mliska@suse.cz>
PR gcov-profile/86536
* gcc.misc-tests/gcov-pr86536.c: New test.
---
gcc/gcov.c | 46 +++++----------------
gcc/testsuite/gcc.misc-tests/gcov-pr86536.c | 25 +++++++++++
2 files changed, 35 insertions(+), 36 deletions(-)
create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-pr86536.c
[-- Attachment #2: 0001-gcov-Fix-wrong-usage-of-NAN-in-statistics-PR-gcov-pr.patch --]
[-- Type: text/x-patch, Size: 2776 bytes --]
diff --git a/gcc/gcov.c b/gcc/gcov.c
index ad2de4d5b22..78a3e0e19e9 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -2203,50 +2203,24 @@ format_count (gcov_type count)
}
/* Format a GCOV_TYPE integer as either a percent ratio, or absolute
- count. If dp >= 0, format TOP/BOTTOM * 100 to DP decimal places.
- If DP is zero, no decimal point is printed. Only print 100% when
- TOP==BOTTOM and only print 0% when TOP=0. If dp < 0, then simply
+ count. If DECIMAL_PLACES >= 0, format TOP/BOTTOM * 100 to DECIMAL_PLACES.
+ If DECIMAL_PLACES is zero, no decimal point is printed. Only print 100% when
+ TOP==BOTTOM and only print 0% when TOP=0. If DECIMAL_PLACES < 0, then simply
format TOP. Return pointer to a static string. */
static char const *
-format_gcov (gcov_type top, gcov_type bottom, int dp)
+format_gcov (gcov_type top, gcov_type bottom, int decimal_places)
{
static char buffer[20];
- /* Handle invalid values that would result in a misleading value. */
- if (bottom != 0 && top > bottom && dp >= 0)
+ if (decimal_places >= 0)
{
- sprintf (buffer, "NAN %%");
- return buffer;
- }
+ float ratio = bottom ? 100.0f * top / bottom: 0;
- if (dp >= 0)
- {
- float ratio = bottom ? (float)top / bottom : 0;
- int ix;
- unsigned limit = 100;
- unsigned percent;
-
- for (ix = dp; ix--; )
- limit *= 10;
-
- percent = (unsigned) (ratio * limit + (float)0.5);
- if (percent <= 0 && top)
- percent = 1;
- else if (percent >= limit && top != bottom)
- percent = limit - 1;
- ix = sprintf (buffer, "%.*u%%", dp + 1, percent);
- if (dp)
- {
- dp++;
- do
- {
- buffer[ix+1] = buffer[ix];
- ix--;
- }
- while (dp--);
- buffer[ix + 1] = '.';
- }
+ /* Round up to 1% if there's a small non-zero value. */
+ if (ratio > 0.0f && ratio < 0.5f && decimal_places == 0)
+ ratio = 1.0f;
+ sprintf (buffer, "%.*f%%", decimal_places, ratio);
}
else
return format_count (top);
diff --git a/gcc/testsuite/gcc.misc-tests/gcov-pr86536.c b/gcc/testsuite/gcc.misc-tests/gcov-pr86536.c
new file mode 100644
index 00000000000..48177735999
--- /dev/null
+++ b/gcc/testsuite/gcc.misc-tests/gcov-pr86536.c
@@ -0,0 +1,25 @@
+// PR gcov-profile/86536
+// { dg-options "-fprofile-arcs -ftest-coverage" }
+// { dg-do run { target native } }
+// { dg-require-fork "" }
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int
+main (void)
+{
+
+ int j = 22; /* count(1) */
+
+ /* returns(200) */
+ fork (); /* count(1) */
+ /* returns(end) */
+
+ int i = 7; /* count(2) */
+ return 0; /* count(2) */
+}
+
+// { dg-final { run-gcov branches calls { -b gcov-pr86536.c } } }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-07-24 7:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-24 7:24 [PATCH] gcov: Fix wrong usage of NAN in statistics (PR gcov-profile/86536) Martin Liška
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).