public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix -Wreturn-type with switches (PR sanitizer/81275)
@ 2017-11-30 23:01 Jakub Jelinek
  2017-12-01  7:06 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-11-30 23:01 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

Now that the C++ FE emits __builtin_unreachable with BUILTINS_LOCATION
for fallthrough into end of function without returning value, we need to
see those in the warn_function_return pass which is right after building
cfg.  While GIMPLE_CONDs conditionally jumping to __builtin_unreachable are
only optimized during evrp and later, GIMPLE_SWITCH cases that branch to
__builtin_unreachable are unfortunately removed already during the cfg
cleanup in the cfg pass and thus the immediately following
warn_function_return pass can't warn.  Fixed by postponing that, e.g.
the evrp pass does unconditional TODO_cleanup_cfg, so those will be
optimized away pretty early (often already during ccp1).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-11-30  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/81275
	* tree-cfg.c (group_case_labels_stmt): Don't optimize away
	C++ FE implicitly added __builtin_unreachable () until -Wreturn-type
	is diagnosed.

	* c-c++-common/tsan/pr81275.c: New test.

--- gcc/tree-cfg.c.jj	2017-11-30 11:40:38.000000000 +0100
+++ gcc/tree-cfg.c	2017-11-30 12:01:39.496311219 +0100
@@ -1750,7 +1750,14 @@ group_case_labels_stmt (gswitch *stmt)
 
       /* Discard cases that have an unreachable destination block.  */
       if (EDGE_COUNT (base_bb->succs) == 0
-	  && gimple_seq_unreachable_p (bb_seq (base_bb)))
+	  && gimple_seq_unreachable_p (bb_seq (base_bb))
+	  /* Don't optimize this if __builtin_unreachable () is the
+	     implicitly added one by the C++ FE too early, before
+	     -Wreturn-type can be diagnosed.  We'll optimize it later
+	     during switchconv pass or any other cfg cleanup.  */
+	  && (gimple_in_ssa_p (cfun)
+	      || (LOCATION_LOCUS (gimple_location (last_stmt (base_bb)))
+		  != BUILTINS_LOCATION)))
 	{
 	  edge base_edge = find_edge (gimple_bb (stmt), base_bb);
 	  if (base_edge != NULL)
--- gcc/testsuite/c-c++-common/tsan/pr81275.c.jj	2017-11-28 22:23:34.000000000 +0100
+++ gcc/testsuite/c-c++-common/tsan/pr81275.c	2017-11-30 11:50:56.185274379 +0100
@@ -1,7 +1,6 @@
 /* PR sanitizer/81275 */
 /* { dg-do compile } */
 /* { dg-options "-Wreturn-type -fsanitize=thread" } */
-/* { dg-skip-if "" { c++ } { "*" } { "-O0" } } */
 
 int
 f1 (int a, int b)

	Jakub

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

* Re: [PATCH] Fix -Wreturn-type with switches (PR sanitizer/81275)
  2017-11-30 23:01 [PATCH] Fix -Wreturn-type with switches (PR sanitizer/81275) Jakub Jelinek
@ 2017-12-01  7:06 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-12-01  7:06 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On November 30, 2017 11:55:42 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>Now that the C++ FE emits __builtin_unreachable with BUILTINS_LOCATION
>for fallthrough into end of function without returning value, we need
>to
>see those in the warn_function_return pass which is right after
>building
>cfg.  While GIMPLE_CONDs conditionally jumping to __builtin_unreachable
>are
>only optimized during evrp and later, GIMPLE_SWITCH cases that branch
>to
>__builtin_unreachable are unfortunately removed already during the cfg
>cleanup in the cfg pass and thus the immediately following
>warn_function_return pass can't warn.  Fixed by postponing that, e.g.
>the evrp pass does unconditional TODO_cleanup_cfg, so those will be
>optimized away pretty early (often already during ccp1).
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK. 

Richard. 

>2017-11-30  Jakub Jelinek  <jakub@redhat.com>
>
>	PR sanitizer/81275
>	* tree-cfg.c (group_case_labels_stmt): Don't optimize away
>	C++ FE implicitly added __builtin_unreachable () until -Wreturn-type
>	is diagnosed.
>
>	* c-c++-common/tsan/pr81275.c: New test.
>
>--- gcc/tree-cfg.c.jj	2017-11-30 11:40:38.000000000 +0100
>+++ gcc/tree-cfg.c	2017-11-30 12:01:39.496311219 +0100
>@@ -1750,7 +1750,14 @@ group_case_labels_stmt (gswitch *stmt)
> 
>       /* Discard cases that have an unreachable destination block.  */
>       if (EDGE_COUNT (base_bb->succs) == 0
>-	  && gimple_seq_unreachable_p (bb_seq (base_bb)))
>+	  && gimple_seq_unreachable_p (bb_seq (base_bb))
>+	  /* Don't optimize this if __builtin_unreachable () is the
>+	     implicitly added one by the C++ FE too early, before
>+	     -Wreturn-type can be diagnosed.  We'll optimize it later
>+	     during switchconv pass or any other cfg cleanup.  */
>+	  && (gimple_in_ssa_p (cfun)
>+	      || (LOCATION_LOCUS (gimple_location (last_stmt (base_bb)))
>+		  != BUILTINS_LOCATION)))
> 	{
> 	  edge base_edge = find_edge (gimple_bb (stmt), base_bb);
> 	  if (base_edge != NULL)
>--- gcc/testsuite/c-c++-common/tsan/pr81275.c.jj	2017-11-28
>22:23:34.000000000 +0100
>+++ gcc/testsuite/c-c++-common/tsan/pr81275.c	2017-11-30
>11:50:56.185274379 +0100
>@@ -1,7 +1,6 @@
> /* PR sanitizer/81275 */
> /* { dg-do compile } */
> /* { dg-options "-Wreturn-type -fsanitize=thread" } */
>-/* { dg-skip-if "" { c++ } { "*" } { "-O0" } } */
> 
> int
> f1 (int a, int b)
>
>	Jakub

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

end of thread, other threads:[~2017-12-01  7:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-30 23:01 [PATCH] Fix -Wreturn-type with switches (PR sanitizer/81275) Jakub Jelinek
2017-12-01  7:06 ` 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).