Assembly return instruction incorrectly annotated
Closed this issue · 2 comments
Reeeemi commented
I think I found a bug in the assembly coverage annotation. In the example below, the retq
instruction is annotated with a "-", indicating it was not executed, while I'm pretty sure it should always be executed. I think it's caused by the jmp
instruction to the retq
statement.
GNATCoverage output:
Coverage level: branch
f !: 0000000000400530-0000000000400550
0000000000400530 +: 85 ff test %edi,%edi
0000000000400532 v: 7e 1a jle 0x40054e <f+0x1e>
0000000000400534 +: 31 c9 xor %ecx,%ecx
0000000000400536 +: 31 c0 xor %eax,%eax
0000000000400538 +: 0f 1f 84 00 00 00 00 00 nopl 0x0(%rax,%rax,1)
0000000000400540 +: 89 ca mov %ecx,%edx
0000000000400542 +: 21 fa and %edi,%edx
0000000000400544 +: 01 d0 add %edx,%eax
0000000000400546 +: ff c1 inc %ecx
0000000000400548 +: 39 cf cmp %ecx,%edi
000000000040054a v: 75 f4 jne 0x400540 <f+0x10>
000000000040054c +: eb 02 jmp 0x400550 <f+0x20>
000000000040054e -: 31 c0 xor %eax,%eax
0000000000400550 -: c3 retq
This happens when compiling the example below with clang
at optimization level -O1
(X86-64).
f.c
:
int f(int n) {
int total = 0;
for (int i = 0 ; i < n ; i++) {
total += i & n;
}
return total;
}
main.c
:
#include<stdio.h>
int f(int n);
int main() {
printf("%i\n", f(1));
return 0;
}
Compiling:
clang -c main.c
clang -O1 -c f.c
clang main.o f.o -o main
GNATCoverage:
gnatcov run ./main
gnatcov coverage --level=branch --annotate=asm main.trace --routines=f
I hope I provided all information needed to investigate this.
Regards,
Remi
pmderodat commented
Hello Remi,
Thank you for reporting this issue! We could reproduce on our side and are investigating this.
pmderodat commented
This bug should now be fixed. Thank you again for reporting it!