public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] gcov-profile/114715 - missing coverage for switch
       [not found] <66942.124041507280100377@us-mta-299.us.mimecast.lan>
@ 2024-04-15 11:29 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2024-04-15 11:29 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Mon, Apr 15, 2024 at 01:28:00PM +0200, Richard Biener wrote:
> 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.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, OK for trunk?
> 
> Thanks,
> Richard.
> 
> 	PR gcov-profile/114715
> 	* gimplify.cc (gimplify_switch_expr): Set the location of the
> 	GIMPLE switch.
> 
> 	* gcc.misc-tests/gcov-24.c: New testcase.

LGTM, thanks.

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] gcov-profile/114715 - missing coverage for switch
@ 2024-04-15 11:28 Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-04-15 11:28 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, OK for trunk?

Thanks,
Richard.

	PR gcov-profile/114715
	* gimplify.cc (gimplify_switch_expr): Set the location of the
	GIMPLE switch.

	* gcc.misc-tests/gcov-24.c: New testcase.
---
 gcc/gimplify.cc                        |  1 +
 gcc/testsuite/gcc.misc-tests/gcov-24.c | 30 ++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-24.c

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,
diff --git a/gcc/testsuite/gcc.misc-tests/gcov-24.c b/gcc/testsuite/gcc.misc-tests/gcov-24.c
new file mode 100644
index 00000000000..395099bd7ae
--- /dev/null
+++ b/gcc/testsuite/gcc.misc-tests/gcov-24.c
@@ -0,0 +1,30 @@
+/* { dg-options "-fprofile-arcs -ftest-coverage" } */
+/* { dg-do run { target native } } */
+
+int main()
+{
+  int a = 1;
+  int b = 2;
+  int c = -3;
+  switch(a) /* count(1) */
+    {
+    case 1: /* count(1) */
+    c = 3;
+    switch(b) { /* count(1) */
+      case 1: /* count(#####) */
+      c = 4;
+      break;
+      case 2: /* count(1) */
+      c = 5;
+      break;
+    }
+    break;
+    case 2: /* count(#####) */
+    c = 6;
+    break;
+    default: /* count(#####) */
+    break;
+    }
+}
+
+/* { dg-final { run-gcov gcov-24.c } } */
-- 
2.35.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-15 11:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <66942.124041507280100377@us-mta-299.us.mimecast.lan>
2024-04-15 11:29 ` [PATCH] gcov-profile/114715 - missing coverage for switch Jakub Jelinek
2024-04-15 11:28 Richard Biener

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).