public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/101193] New: [GCOV] Bit operation leads to wrong coverage information
@ 2021-06-24 13:04 njuwy at smail dot nju.edu.cn
2021-07-02 7:22 ` [Bug gcov-profile/101193] " marxin at gcc dot gnu.org
2021-07-02 22:54 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: njuwy at smail dot nju.edu.cn @ 2021-06-24 13:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101193
Bug ID: 101193
Summary: [GCOV] Bit operation leads to wrong coverage
information
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: njuwy at smail dot nju.edu.cn
CC: marxin at gcc dot gnu.org
Target Milestone: ---
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure -enable-checking=release -enable-languages=c,c++
-disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)
$ cat test.c
#ifdef __UINT32_TYPE__
typedef __UINT32_TYPE__ uint32_t;
#else
typedef __UINT32_TYPE__ unsigned;
#endif
struct bitfield {
unsigned char f0 : 7;
unsigned char : 1;
unsigned char f1 : 7;
unsigned char : 1;
unsigned char f2 : 7;
unsigned char : 1;
unsigned char f3 : 7;
};
struct ok {
unsigned char f0;
unsigned char f1;
unsigned char f2;
unsigned char f3;
};
union bf_or_uint32 {
struct ok inval;
struct bitfield bfval;
};
__attribute__((noinline, noclone)) uint32_t
partial_read_le32(union bf_or_uint32 in) {
return in.bfval.f0 | (in.bfval.f1 << 8) | (in.bfval.f2 << 16) |
(in.bfval.f3 << 24);
}
int main() {
union bf_or_uint32 bfin;
uint32_t out;
char cin[] = {0x83, 0x85, 0x87, 0x89};
bfin.inval = (struct ok){0x83, 0x85, 0x87, 0x89};
out = partial_read_le32(bfin);
return 0;
}
$ gcc -O0 --coverage test.c;./a.out;gcov test;cat test.c.gcov
File 'test.c'
Lines executed:100.00% of 8
Creating 'test.c.gcov'
-: 0:Source:test.c
-: 0:Graph:test.gcno
-: 0:Data:test.gcda
-: 0:Runs:1
-: 1:#ifdef __UINT32_TYPE__
-: 2:typedef __UINT32_TYPE__ uint32_t;
-: 3:#else
-: 4:typedef __UINT32_TYPE__ unsigned;
-: 5:#endif
-: 6:
-: 7:struct bitfield {
-: 8: unsigned char f0 : 7;
-: 9: unsigned char : 1;
-: 10: unsigned char f1 : 7;
-: 11: unsigned char : 1;
-: 12: unsigned char f2 : 7;
-: 13: unsigned char : 1;
-: 14: unsigned char f3 : 7;
-: 15:};
-: 16:
-: 17:struct ok {
-: 18: unsigned char f0;
-: 19: unsigned char f1;
-: 20: unsigned char f2;
-: 21: unsigned char f3;
-: 22:};
-: 23:
-: 24:union bf_or_uint32 {
-: 25: struct ok inval;
-: 26: struct bitfield bfval;
-: 27:};
-: 28:
-: 29:
-: 30:__attribute__((noinline, noclone)) uint32_t
1: 31:partial_read_le32(union bf_or_uint32 in) {
2: 32: return in.bfval.f0 | (in.bfval.f1 << 8) | (in.bfval.f2 << 16)
|
1: 33: (in.bfval.f3 << 24);
-: 34:}
-: 35:
-: 36:
1: 37:int main() {
-: 38: union bf_or_uint32 bfin;
-: 39: uint32_t out;
1: 40: char cin[] = {0x83, 0x85, 0x87, 0x89};
1: 41: bfin.inval = (struct ok){0x83, 0x85, 0x87, 0x89};
1: 42: out = partial_read_le32(bfin);
-: 43:
-: 44:
1: 45: return 0;
-: 46:}
-: 47:
-: 48:
Line 32 should be executed only once.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug gcov-profile/101193] [GCOV] Bit operation leads to wrong coverage information
2021-06-24 13:04 [Bug gcov-profile/101193] New: [GCOV] Bit operation leads to wrong coverage information njuwy at smail dot nju.edu.cn
@ 2021-07-02 7:22 ` marxin at gcc dot gnu.org
2021-07-02 22:54 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-07-02 7:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101193
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2021-07-02
Status|UNCONFIRMED |NEW
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed, we have quite some similar issues. It's not related to bitfields but
to fact that the following expression is split among multiple lines:
return in.bfval.f0 | (in.bfval.f1 << 8) | (in.bfval.f2 << 16) | (in.bfval.f3 <<
24);
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug gcov-profile/101193] [GCOV] Bit operation leads to wrong coverage information
2021-06-24 13:04 [Bug gcov-profile/101193] New: [GCOV] Bit operation leads to wrong coverage information njuwy at smail dot nju.edu.cn
2021-07-02 7:22 ` [Bug gcov-profile/101193] " marxin at gcc dot gnu.org
@ 2021-07-02 22:54 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-02 22:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101193
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu.org
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #1)
> Confirmed, we have quite some similar issues. It's not related to bitfields
> but to fact that the following expression is split among multiple lines:
>
> return in.bfval.f0 | (in.bfval.f1 << 8) | (in.bfval.f2 << 16) | (in.bfval.f3
> << 24);
Actually I suspect it is more related to bitfields and spread across multiple
lines. There is an optimization done early (before GCOV) in fold-const which
combines the above to use and afterwards.
I have a few set of patches which allows to get rid of most of the optimization
in fold-const dealing with this but not all; This is something which I am going
to work towards for GCC 12 but after the current phiopt work.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-02 22:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24 13:04 [Bug gcov-profile/101193] New: [GCOV] Bit operation leads to wrong coverage information njuwy at smail dot nju.edu.cn
2021-07-02 7:22 ` [Bug gcov-profile/101193] " marxin at gcc dot gnu.org
2021-07-02 22:54 ` pinskia 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).