From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix -Wreturn-type with -fsanitize=return (PR c++/81212)
Date: Sat, 02 Dec 2017 00:14:00 -0000 [thread overview]
Message-ID: <20171202001410.GE2353@tucnak> (raw)
Hi!
With -fsanitize=return, we add __builtin_ubsan_handle_missing_return
instead of __builtin_unreachable with BUILTINS_LOCATION locus,
the following patch teaches warn function return pass to handle that too.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2017-12-01 Jakub Jelinek <jakub@redhat.com>
PR c++/81212
* tree-cfg.c (pass_warn_function_return::execute): Handle
__builtin_ubsan_handle_missing_return like __builtin_unreachable
with BUILTINS_LOCATION.
* g++.dg/ubsan/pr81212.C: New test.
* g++.dg/ubsan/return-1.C: Add -Wno-return-type to dg-options.
* g++.dg/ubsan/return-2.C: Add -Wno-return-type to dg-options.
* g++.dg/ubsan/return-7.C: Add -Wno-return-type to dg-options.
--- gcc/tree-cfg.c.jj 2017-12-01 09:10:12.000000000 +0100
+++ gcc/tree-cfg.c 2017-12-01 19:38:21.933049446 +0100
@@ -9151,10 +9151,13 @@ pass_warn_function_return::execute (func
if (EDGE_COUNT (bb->succs) == 0)
{
gimple *last = last_stmt (bb);
+ const enum built_in_function ubsan_missing_ret
+ = BUILT_IN_UBSAN_HANDLE_MISSING_RETURN;
if (last
- && (LOCATION_LOCUS (gimple_location (last))
- == BUILTINS_LOCATION)
- && gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE))
+ && ((LOCATION_LOCUS (gimple_location (last))
+ == BUILTINS_LOCATION
+ && gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE))
+ || gimple_call_builtin_p (last, ubsan_missing_ret)))
{
gimple_stmt_iterator gsi = gsi_for_stmt (last);
gsi_prev_nondebug (&gsi);
--- gcc/testsuite/g++.dg/ubsan/pr81212.C.jj 2017-12-01 19:30:43.251747933 +0100
+++ gcc/testsuite/g++.dg/ubsan/pr81212.C 2017-12-01 19:30:25.000000000 +0100
@@ -0,0 +1,16 @@
+// PR c++/81212
+// { dg-do compile }
+// { dg-options "-Wreturn-type -fsanitize=return" }
+
+struct S
+{
+ S (void *);
+ void *s;
+};
+
+S
+foo (bool x, void *y)
+{
+ if (x)
+ return S (y);
+} // { dg-warning "control reaches end of non-void function" }
--- gcc/testsuite/g++.dg/ubsan/return-1.C.jj 2013-11-22 21:05:59.000000000 +0100
+++ gcc/testsuite/g++.dg/ubsan/return-1.C 2017-12-01 22:23:17.053866660 +0100
@@ -1,5 +1,5 @@
// { dg-do run }
-// { dg-options "-fsanitize=return" }
+// { dg-options "-fsanitize=return -Wno-return-type" }
// { dg-shouldfail "ubsan" }
struct S { S (); ~S (); };
--- gcc/testsuite/g++.dg/ubsan/return-2.C.jj 2014-10-22 15:52:16.000000000 +0200
+++ gcc/testsuite/g++.dg/ubsan/return-2.C 2017-12-01 22:23:32.059679081 +0100
@@ -1,5 +1,5 @@
// { dg-do run }
-// { dg-options "-fsanitize=return -fno-sanitize-recover=return" }
+// { dg-options "-fsanitize=return -fno-sanitize-recover=return -Wno-return-type" }
struct S { S (); ~S (); };
--- gcc/testsuite/g++.dg/ubsan/return-7.C.jj 2016-11-23 20:50:51.000000000 +0100
+++ gcc/testsuite/g++.dg/ubsan/return-7.C 2017-12-01 22:24:03.894281135 +0100
@@ -1,5 +1,5 @@
// { dg-do run }
-// { dg-options "-fsanitize=undefined" }
+// { dg-options "-fsanitize=undefined -Wno-return-type" }
// { dg-shouldfail "ubsan" }
struct S { S (); ~S (); };
Jakub
next reply other threads:[~2017-12-02 0:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-02 0:14 Jakub Jelinek [this message]
2017-12-02 7:54 ` 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=20171202001410.GE2353@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).