[Bug 837303] [NEW] gcov produce incorrect numbers for while loops and for loops with no increment part
Kasper Dupont
837303 at bugs.launchpad.net
Tue Aug 30 11:04:15 UTC 2011
Public bug reported:
gcov produce correct execution count for a typical for loop such as:
for (i=0;i<10;++i)
However if the increment part is removed from the for statement and put
at the end of the loop instead, the program is equivalent, but gcov in
that case will double count the line with the for statement once per
time the for loop is reached. That is if the loop was not entered at
all, the line where the for loop starts is counted twice.
The same incorrect behaviour is seen with any while loop.
Here is the gcov output from four variations of a program demonstrating
incorrect execution counts in three of the four cases.
-: 1:#include <stdio.h>
-: 2:
1: 3:int main()
-: 4:{
-: 5: int i;
11: 6: for (i=0;i<10;++i) {
10: 7: printf("%d\n",i);
-: 8: }
1: 9: return 0;
-: 10:}
-: 1:#include <stdio.h>
-: 2:
1: 3:int main()
-: 4:{
-: 5: int i;
12: 6: for (i=0;i<10;) {
10: 7: printf("%d\n",i);
10: 8: ++i;
-: 9: }
1: 10: return 0;
-: 11:}
-: 1:#include <stdio.h>
-: 2:
1: 3:int main()
-: 4:{
1: 5: int i=0;
12: 6: while (i<10) {
10: 7: printf("%d\n",i);
10: 8: ++i;
-: 9: }
1: 10: return 0;
-: 11:}
-: 1:#include <stdio.h>
-: 2:
1: 3:int main()
-: 4:{
1: 5: int i=20;
2: 6: while (i<10) {
#####: 7: printf("%d\n",i);
#####: 8: ++i;
-: 9: }
1: 10: return 0;
-: 11:}
ProblemType: Bug
DistroRelease: Ubuntu 10.04
Package: gcc 4:4.4.3-1ubuntu1
ProcVersionSignature: Ubuntu 2.6.32-33.72-generic 2.6.32.41+drm33.18
Uname: Linux 2.6.32-33-generic i686
Architecture: i386
Date: Tue Aug 30 12:47:01 2011
EcryptfsInUse: Yes
InstallationMedia: Ubuntu 10.04.3 LTS "Lucid Lynx" - Release i386 (20110720.1)
ProcEnviron:
PATH=(custom, user)
LANG=en_DK.utf8
SHELL=/bin/bash
SourcePackage: gcc-defaults
** Affects: gcc-defaults (Ubuntu)
Importance: Undecided
Status: New
** Tags: apport-bug i386 lucid
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-defaults in Ubuntu.
https://bugs.launchpad.net/bugs/837303
Title:
gcov produce incorrect numbers for while loops and for loops with no
increment part
Status in “gcc-defaults” package in Ubuntu:
New
Bug description:
gcov produce correct execution count for a typical for loop such as:
for (i=0;i<10;++i)
However if the increment part is removed from the for statement and
put at the end of the loop instead, the program is equivalent, but
gcov in that case will double count the line with the for statement
once per time the for loop is reached. That is if the loop was not
entered at all, the line where the for loop starts is counted twice.
The same incorrect behaviour is seen with any while loop.
Here is the gcov output from four variations of a program
demonstrating incorrect execution counts in three of the four cases.
-: 1:#include <stdio.h>
-: 2:
1: 3:int main()
-: 4:{
-: 5: int i;
11: 6: for (i=0;i<10;++i) {
10: 7: printf("%d\n",i);
-: 8: }
1: 9: return 0;
-: 10:}
-: 1:#include <stdio.h>
-: 2:
1: 3:int main()
-: 4:{
-: 5: int i;
12: 6: for (i=0;i<10;) {
10: 7: printf("%d\n",i);
10: 8: ++i;
-: 9: }
1: 10: return 0;
-: 11:}
-: 1:#include <stdio.h>
-: 2:
1: 3:int main()
-: 4:{
1: 5: int i=0;
12: 6: while (i<10) {
10: 7: printf("%d\n",i);
10: 8: ++i;
-: 9: }
1: 10: return 0;
-: 11:}
-: 1:#include <stdio.h>
-: 2:
1: 3:int main()
-: 4:{
1: 5: int i=20;
2: 6: while (i<10) {
#####: 7: printf("%d\n",i);
#####: 8: ++i;
-: 9: }
1: 10: return 0;
-: 11:}
ProblemType: Bug
DistroRelease: Ubuntu 10.04
Package: gcc 4:4.4.3-1ubuntu1
ProcVersionSignature: Ubuntu 2.6.32-33.72-generic 2.6.32.41+drm33.18
Uname: Linux 2.6.32-33-generic i686
Architecture: i386
Date: Tue Aug 30 12:47:01 2011
EcryptfsInUse: Yes
InstallationMedia: Ubuntu 10.04.3 LTS "Lucid Lynx" - Release i386 (20110720.1)
ProcEnviron:
PATH=(custom, user)
LANG=en_DK.utf8
SHELL=/bin/bash
SourcePackage: gcc-defaults
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/837303/+subscriptions
More information about the foundations-bugs
mailing list