This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: gcov: new option to merge results
On Jun 8, 2007, at 6:34 PM, Olivier Hainque wrote:
Do you have concrete examples of problems that prompted this change ?
Sure. Here is a simple case:
f1.c:
#include <stdio.h>
#include "comm.h"
int arr1[] = { 1, 2, 3, 4, 5};
int main (void)
{
int r1, r2;
r2 = f2 ();
r1 = sum_arr (5, arr1);
printf ("r1=%d r2=%d\n", r1, r2);
return 0;
}
f2.c:
#include "comm.h"
int arr2[]={5, 4, 3, 2, 1};
int f2 (void)
{
return sum_arr(5, arr2);
}
comm.h:
extern inline int sum_arr (int num, int *arr)
{
int i;
int res = 0;
for (i = 0; i < num; i++)
res += arr[i];
return res;
}
If you run 'gcov f1.o f2.o', the comm.h.gcov output is:
-: 1:extern inline int sum_arr (int num, int *arr)
-: 2:{
-: 3: int i;
1: 4: int res = 0;
-: 5:
6: 6: for (i = 0; i < num; i++)
5: 7: res += arr[i];
-: 8:
1: 9: return res;
-: 10:}
This is rather unexpected because the inner block of the loop was run
10 times (and not 5).
Looks like this could even be the default behavior IMO.
Indeed. I didn't want to break backward compatibility but because
the handling of multiple source files was not advertised the previous
behavior is kept if there is only one file.
Thank you for your comment.