public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/114715] New: Gcov allocates branches to wrong row for nested switches
@ 2024-04-15 6:38 a_aili at hotmail dot com
2024-04-15 8:51 ` [Bug gcov-profile/114715] " rguenth at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: a_aili at hotmail dot com @ 2024-04-15 6:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114715
Bug ID: 114715
Summary: Gcov allocates branches to wrong row for nested
switches
Product: gcc
Version: 11.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: a_aili at hotmail dot com
Target Milestone: ---
While using the following GCC version
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
11.4.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-11
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-gcn/usr
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)
gcov allocates branches to the wrong row when using nested switches.
Given the following test program:
#include <stdio.h>
int main()
{
int a = 1;
int b = 2;
int c = -3;
switch(a)
{
case 1:
c = 3;
switch(b) {
case 1:
c = 4;
break;
case 2:
c = 5;
break;
}
break;
case 2:
c = 6;
break;
default:
break;
}
printf("%i, %i, %i\n", a, b, c);
}
compiled with 'gcc test.c -o0 --coverage -o test'.
Gcov invoked with 'gcov --branch-count --branch-probabilities test.c' gives
-: 0:Source:test.c
-: 0:Graph:test.gcno
-: 0:Data:test.gcda
-: 0:Runs:1
-: 1:#include <stdio.h>
-: 2:
function main called 1 returned 100% blocks executed 70%
1: 3:int main()
-: 4:{
1: 5: int a = 1;
1: 6: int b = 2;
1: 7: int c = -3;
1: 8: switch(a)
branch 0 taken 1
branch 1 taken 0
branch 2 taken 0
-: 9: {
1: 10: case 1:
1: 11: c = 3;
branch 0 taken 0
branch 1 taken 1
branch 2 taken 0
-: 12: switch(b) {
#####: 13: case 1:
#####: 14: c = 4;
#####: 15: break;
1: 16: case 2:
1: 17: c = 5;
1: 18: break;
-: 19: }
1: 20: break;
#####: 21: case 2:
#####: 22: c = 6;
#####: 23: break;
#####: 24: default:
#####: 25: break;
-: 26: }
-: 27:
1: 28: printf("%i, %i, %i\n", a, b, c);
call 0 returned 1
-: 29:}
As you can see the branches for the nested switch is allocated to row 11 and
row 12 is marked as not executed. If gcov should have been consistent on how it
allocates coverage the branches on row 11 should have been allocated correctly
to the switch as on row 8. The second switch on row 12 should also be marked as
executed.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug gcov-profile/114715] Gcov allocates branches to wrong row for nested switches
2024-04-15 6:38 [Bug gcov-profile/114715] New: Gcov allocates branches to wrong row for nested switches a_aili at hotmail dot com
@ 2024-04-15 8:51 ` rguenth at gcc dot gnu.org
2024-04-15 8:53 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-15 8:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114715
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-04-15
Known to fail| |13.2.0
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
CC| |jakub at gcc dot gnu.org,
| |rguenth at gcc dot gnu.org
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. The branches emitted by pass_lower_switch_O0 lack location info,
so does the switch itself, already since at least gimplification.
The GENERIC SWITCH_EXPR has
{file = 0x4926cc0 "/tmp/t.c", line = 12, column = 9, data = 0x0,
sysp = false}
we set a location on the BIND we wrap the switch with though. The outer
switch is not wrapped in a BIND. That one gets the location from
annotate_all_with_location_after but this function doesn't recurse into
structured gimple.
It's easy to manually set the switch stmt location, annotating random
nested GIMPLE with a location might be odd. Maybe instead of
gimple_set_location (bind, EXPR_LOCATION (switch_expr));
we should also set all of the BIND_BODY locations as well?
Jakub, any preference?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug gcov-profile/114715] Gcov allocates branches to wrong row for nested switches
2024-04-15 6:38 [Bug gcov-profile/114715] New: Gcov allocates branches to wrong row for nested switches a_aili at hotmail dot com
2024-04-15 8:51 ` [Bug gcov-profile/114715] " rguenth at gcc dot gnu.org
@ 2024-04-15 8:53 ` rguenth at gcc dot gnu.org
2024-04-15 9:05 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-15 8:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114715
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Besides OMP the switch gimplification code is the only one building a new BIND.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug gcov-profile/114715] Gcov allocates branches to wrong row for nested switches
2024-04-15 6:38 [Bug gcov-profile/114715] New: Gcov allocates branches to wrong row for nested switches a_aili at hotmail dot com
2024-04-15 8:51 ` [Bug gcov-profile/114715] " rguenth at gcc dot gnu.org
2024-04-15 8:53 ` rguenth at gcc dot gnu.org
@ 2024-04-15 9:05 ` rguenth at gcc dot gnu.org
2024-04-15 9:11 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-15 9:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114715
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 3df58b962f3..26e96ada4c7 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -3017,6 +3017,7 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p)
switch_stmt = gimple_build_switch (SWITCH_COND (switch_expr),
default_case, labels);
+ gimple_set_location (switch_stmt, EXPR_LOCATION (switch_expr));
/* For the benefit of -Wimplicit-fallthrough, if switch_body_seq
ends with a GIMPLE_LABEL holding SWITCH_BREAK_LABEL_P LABEL_DECL,
wrap the GIMPLE_SWITCH up to that GIMPLE_LABEL into a GIMPLE_BIND,
fixes the testcase
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug gcov-profile/114715] Gcov allocates branches to wrong row for nested switches
2024-04-15 6:38 [Bug gcov-profile/114715] New: Gcov allocates branches to wrong row for nested switches a_aili at hotmail dot com
` (2 preceding siblings ...)
2024-04-15 9:05 ` rguenth at gcc dot gnu.org
@ 2024-04-15 9:11 ` rguenth at gcc dot gnu.org
2024-04-15 11:45 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-15 9:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114715
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug gcov-profile/114715] Gcov allocates branches to wrong row for nested switches
2024-04-15 6:38 [Bug gcov-profile/114715] New: Gcov allocates branches to wrong row for nested switches a_aili at hotmail dot com
` (3 preceding siblings ...)
2024-04-15 9:11 ` rguenth at gcc dot gnu.org
@ 2024-04-15 11:45 ` rguenth at gcc dot gnu.org
2024-05-03 13:55 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-15 11:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114715
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |14.0
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
commit 9d573f71e80e9f6f4aac912fc8fc128aa2697e3a (origin/master, origin/HEAD)
Author: Richard Biener <rguenther@suse.de>
Date: Mon Apr 15 11:09:17 2024 +0200
gcov-profile/114715 - missing coverage for switch
The following avoids missing coverage for the line of a switch statement
which happens when gimplification emits a BIND_EXPR wrapping the switch
as that prevents us from setting locations on the containing statements
via annotate_all_with_location. Instead set the location of the GIMPLE
switch directly.
PR gcov-profile/114715
* gimplify.cc (gimplify_switch_expr): Set the location of the
GIMPLE switch.
* gcc.misc-tests/gcov-24.c: New testcase.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug gcov-profile/114715] Gcov allocates branches to wrong row for nested switches
2024-04-15 6:38 [Bug gcov-profile/114715] New: Gcov allocates branches to wrong row for nested switches a_aili at hotmail dot com
` (4 preceding siblings ...)
2024-04-15 11:45 ` rguenth at gcc dot gnu.org
@ 2024-05-03 13:55 ` cvs-commit at gcc dot gnu.org
2024-05-03 14:00 ` rguenth at gcc dot gnu.org
2024-05-16 9:56 ` cvs-commit at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-03 13:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114715
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:5a3cc62dbb45185dd1ca32caec80d57a320ec5a0
commit r13-8682-g5a3cc62dbb45185dd1ca32caec80d57a320ec5a0
Author: Richard Biener <rguenther@suse.de>
Date: Mon Apr 15 11:09:17 2024 +0200
gcov-profile/114715 - missing coverage for switch
The following avoids missing coverage for the line of a switch statement
which happens when gimplification emits a BIND_EXPR wrapping the switch
as that prevents us from setting locations on the containing statements
via annotate_all_with_location. Instead set the location of the GIMPLE
switch directly.
PR gcov-profile/114715
* gimplify.cc (gimplify_switch_expr): Set the location of the
GIMPLE switch.
* gcc.misc-tests/gcov-24.c: New testcase.
(cherry picked from commit 9d573f71e80e9f6f4aac912fc8fc128aa2697e3a)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug gcov-profile/114715] Gcov allocates branches to wrong row for nested switches
2024-04-15 6:38 [Bug gcov-profile/114715] New: Gcov allocates branches to wrong row for nested switches a_aili at hotmail dot com
` (5 preceding siblings ...)
2024-05-03 13:55 ` cvs-commit at gcc dot gnu.org
@ 2024-05-03 14:00 ` rguenth at gcc dot gnu.org
2024-05-16 9:56 ` cvs-commit at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-03 14:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114715
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |13.2.1
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed for GCC 13+ sofar. Probably never worked correctly?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug gcov-profile/114715] Gcov allocates branches to wrong row for nested switches
2024-04-15 6:38 [Bug gcov-profile/114715] New: Gcov allocates branches to wrong row for nested switches a_aili at hotmail dot com
` (6 preceding siblings ...)
2024-05-03 14:00 ` rguenth at gcc dot gnu.org
@ 2024-05-16 9:56 ` cvs-commit at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-16 9:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114715
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:56415e39029012aa3675d3b4b71fb248cf43049e
commit r12-10445-g56415e39029012aa3675d3b4b71fb248cf43049e
Author: Richard Biener <rguenther@suse.de>
Date: Mon Apr 15 11:09:17 2024 +0200
gcov-profile/114715 - missing coverage for switch
The following avoids missing coverage for the line of a switch statement
which happens when gimplification emits a BIND_EXPR wrapping the switch
as that prevents us from setting locations on the containing statements
via annotate_all_with_location. Instead set the location of the GIMPLE
switch directly.
PR gcov-profile/114715
* gimplify.cc (gimplify_switch_expr): Set the location of the
GIMPLE switch.
* gcc.misc-tests/gcov-24.c: New testcase.
(cherry picked from commit 5a3cc62dbb45185dd1ca32caec80d57a320ec5a0)
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-05-16 9:56 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15 6:38 [Bug gcov-profile/114715] New: Gcov allocates branches to wrong row for nested switches a_aili at hotmail dot com
2024-04-15 8:51 ` [Bug gcov-profile/114715] " rguenth at gcc dot gnu.org
2024-04-15 8:53 ` rguenth at gcc dot gnu.org
2024-04-15 9:05 ` rguenth at gcc dot gnu.org
2024-04-15 9:11 ` rguenth at gcc dot gnu.org
2024-04-15 11:45 ` rguenth at gcc dot gnu.org
2024-05-03 13:55 ` cvs-commit at gcc dot gnu.org
2024-05-03 14:00 ` rguenth at gcc dot gnu.org
2024-05-16 9:56 ` cvs-commit 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).