public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/53915] New: gcov -f rounding problem
@ 2012-07-10 13:32 vincent-gcc at vinc17 dot net
  2012-07-10 14:27 ` [Bug gcov-profile/53915] " vincent-gcc at vinc17 dot net
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2012-07-10 13:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53915

             Bug #: 53915
           Summary: gcov -f rounding problem
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: gcov-profile
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vincent-gcc@vinc17.net


I have the following problem with gcov 4.7.1 under Debian:

ypig:/tmp/ompfr-gcov/src> gcov -f round_prec.c
Function 'mpfr_can_round_raw'
Lines executed:100.00% of 44

Function 'mpfr_can_round'
Lines executed:100.00% of 4

Function 'mpfr_prec_round'
Lines executed:100.00% of 31

Function 'mpfr_round_raw_4'
Lines executed:95.00% of 60

Function 'mpfr_round_raw_2'
Lines executed:99.99% of 9

Function 'mpfr_round_raw'
Lines executed:100.00% of 7

File 'round_prec.c'
Lines executed:100.00% of 79
Creating 'round_prec.c.gcov'

File 'round_raw_generic.c'
Lines executed:97.37% of 76
Creating 'round_raw_generic.c.gcov'

File '/usr/include/gmp-x86_64.h'
No executable lines
Removing 'gmp-x86_64.h.gcov'

See the result for Function 'mpfr_round_raw_2': 99.99% of 9. This is not
possible! Either all the lines are executed, in which case one should get 100%,
or at most 8 lines of 9 are executed, in which case one should get 88.89% at
most.

This is reproducible on a Debian/unstable amd64 machine with MPFR trunk r8346
by running the tools/coverage script.

I've also reported with bug on the Debian BTS:

  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=681076


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gcov-profile/53915] gcov -f rounding problem
  2012-07-10 13:32 [Bug gcov-profile/53915] New: gcov -f rounding problem vincent-gcc at vinc17 dot net
@ 2012-07-10 14:27 ` vincent-gcc at vinc17 dot net
  2012-07-10 14:46 ` vincent-gcc at vinc17 dot net
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2012-07-10 14:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53915

--- Comment #1 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> 2012-07-10 14:27:28 UTC ---
The problem is probably in gcc/gcov.c, function format_gcov, which has:

      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);

Using double instead of float would be a first improvement (2 occurrences in
the first line, cast to be removed in the last line). Also, multiplying top by
limit (after a cast to double) before dividing by bottom should be better, as
the first operation (the multiplication) would be done exactly in practice.
Something like that:

  percent = (unsigned) ((double) top * limit / bottom + 0.5);

or even:

  percent = (unsigned) (((double) top * limit + (double) bottom / 2) / bottom);


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gcov-profile/53915] gcov -f rounding problem
  2012-07-10 13:32 [Bug gcov-profile/53915] New: gcov -f rounding problem vincent-gcc at vinc17 dot net
  2012-07-10 14:27 ` [Bug gcov-profile/53915] " vincent-gcc at vinc17 dot net
@ 2012-07-10 14:46 ` vincent-gcc at vinc17 dot net
  2012-07-10 15:19 ` [Bug gcov-profile/53915] gcov can call format_gcov with top > bottom, which is unexpected vincent-gcc at vinc17 dot net
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2012-07-10 14:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53915

--- Comment #2 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> 2012-07-10 14:46:28 UTC ---
Actually this should not be the problem, because if top = bottom = 9, then the
division is done exactly anyway; moreover "percent = limit - 1;" won't be
executed in this case due to the condition top != bottom. Now, I can't explain
the result.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gcov-profile/53915] gcov can call format_gcov with top > bottom, which is unexpected
  2012-07-10 13:32 [Bug gcov-profile/53915] New: gcov -f rounding problem vincent-gcc at vinc17 dot net
  2012-07-10 14:27 ` [Bug gcov-profile/53915] " vincent-gcc at vinc17 dot net
  2012-07-10 14:46 ` vincent-gcc at vinc17 dot net
@ 2012-07-10 15:19 ` vincent-gcc at vinc17 dot net
  2012-07-11  7:44 ` [Bug gcov-profile/53915] gcov can call format_gcov with top > bottom, which is unexpected and gives 99.99% rguenth at gcc dot gnu.org
  2012-07-22  0:15 ` steven at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2012-07-10 15:19 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53915

Vincent Lefèvre <vincent-gcc at vinc17 dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|gcov -f rounding problem    |gcov can call format_gcov
                   |                            |with top > bottom, which is
                   |                            |unexpected
           Severity|minor                       |normal

--- Comment #3 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> 2012-07-10 15:19:20 UTC ---
After recompiling gcov with the -g option and testing with gdb:

Function 'mpfr_round_raw_2'

Breakpoint 1, format_gcov (top=10, bottom=9, dp=2) at ../../src/gcc/gcov.c:1651

and obviously the format_gcov function doesn't handle this case.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gcov-profile/53915] gcov can call format_gcov with top > bottom, which is unexpected and gives 99.99%
  2012-07-10 13:32 [Bug gcov-profile/53915] New: gcov -f rounding problem vincent-gcc at vinc17 dot net
                   ` (2 preceding siblings ...)
  2012-07-10 15:19 ` [Bug gcov-profile/53915] gcov can call format_gcov with top > bottom, which is unexpected vincent-gcc at vinc17 dot net
@ 2012-07-11  7:44 ` rguenth at gcc dot gnu.org
  2012-07-22  0:15 ` steven at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-11  7:44 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53915

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-07-11
                 CC|                            |nathan at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-11 07:44:31 UTC ---
Confirmed.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug gcov-profile/53915] gcov can call format_gcov with top > bottom, which is unexpected and gives 99.99%
  2012-07-10 13:32 [Bug gcov-profile/53915] New: gcov -f rounding problem vincent-gcc at vinc17 dot net
                   ` (3 preceding siblings ...)
  2012-07-11  7:44 ` [Bug gcov-profile/53915] gcov can call format_gcov with top > bottom, which is unexpected and gives 99.99% rguenth at gcc dot gnu.org
@ 2012-07-22  0:15 ` steven at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: steven at gcc dot gnu.org @ 2012-07-22  0:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53915

Steven Bosscher <steven at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |steven at gcc dot gnu.org

--- Comment #5 from Steven Bosscher <steven at gcc dot gnu.org> 2012-07-22 00:15:21 UTC ---
Is there a small test case for this problem?


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-07-22  0:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-10 13:32 [Bug gcov-profile/53915] New: gcov -f rounding problem vincent-gcc at vinc17 dot net
2012-07-10 14:27 ` [Bug gcov-profile/53915] " vincent-gcc at vinc17 dot net
2012-07-10 14:46 ` vincent-gcc at vinc17 dot net
2012-07-10 15:19 ` [Bug gcov-profile/53915] gcov can call format_gcov with top > bottom, which is unexpected vincent-gcc at vinc17 dot net
2012-07-11  7:44 ` [Bug gcov-profile/53915] gcov can call format_gcov with top > bottom, which is unexpected and gives 99.99% rguenth at gcc dot gnu.org
2012-07-22  0:15 ` steven at gcc dot gnu.org

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).