public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix -Wreturn-type with switches (PR sanitizer/81275)
Date: Thu, 30 Nov 2017 23:01:00 -0000	[thread overview]
Message-ID: <20171130225542.GP2353@tucnak> (raw)

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

             reply	other threads:[~2017-11-30 22:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-30 23:01 Jakub Jelinek [this message]
2017-12-01  7:06 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171130225542.GP2353@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).