aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2017-12-02 08:57:04 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2017-12-02 08:57:04 +0100
commit38651b523d2df78a62489911e1c0036847c116bd (patch)
treea6a292ec23bf2fe057bf4eb6a51b0cffc2b86ed9 /gcc
parente034c5c895722e0092d2239cd8c2991db77d6d39 (diff)
downloadgcc-38651b523d2df78a62489911e1c0036847c116bd.zip
gcc-38651b523d2df78a62489911e1c0036847c116bd.tar.gz
gcc-38651b523d2df78a62489911e1c0036847c116bd.tar.bz2
re PR sanitizer/81212 (-Wreturn-type is disabled when used together with -fsanitize=return)
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: Likewise. * g++.dg/ubsan/return-7.C: Likewise. From-SVN: r255354
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/ubsan/pr81212.C16
-rw-r--r--gcc/testsuite/g++.dg/ubsan/return-1.C2
-rw-r--r--gcc/testsuite/g++.dg/ubsan/return-2.C2
-rw-r--r--gcc/testsuite/g++.dg/ubsan/return-7.C2
-rw-r--r--gcc/tree-cfg.c9
7 files changed, 36 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9536a88..f1ce291 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,10 @@
2017-12-02 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.
+
PR target/78643
PR target/80583
* expr.c (get_inner_reference): If DECL_MODE of a non-bitfield
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 49f0409..eedf1a8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2017-12-02 Jakub Jelinek <jakub@redhat.com>
+ PR c++/81212
+ * 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: Likewise.
+ * g++.dg/ubsan/return-7.C: Likewise.
+
PR target/78643
PR target/80583
* gcc.target/i386/pr80583.c: New test.
diff --git a/gcc/testsuite/g++.dg/ubsan/pr81212.C b/gcc/testsuite/g++.dg/ubsan/pr81212.C
new file mode 100644
index 0000000..ce92a07
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/pr81212.C
@@ -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" }
diff --git a/gcc/testsuite/g++.dg/ubsan/return-1.C b/gcc/testsuite/g++.dg/ubsan/return-1.C
index 43791b9..4e24db0 100644
--- a/gcc/testsuite/g++.dg/ubsan/return-1.C
+++ b/gcc/testsuite/g++.dg/ubsan/return-1.C
@@ -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 (); };
diff --git a/gcc/testsuite/g++.dg/ubsan/return-2.C b/gcc/testsuite/g++.dg/ubsan/return-2.C
index 90c48b5..068210d 100644
--- a/gcc/testsuite/g++.dg/ubsan/return-2.C
+++ b/gcc/testsuite/g++.dg/ubsan/return-2.C
@@ -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 (); };
diff --git a/gcc/testsuite/g++.dg/ubsan/return-7.C b/gcc/testsuite/g++.dg/ubsan/return-7.C
index 316cb4b..7f23c9f 100644
--- a/gcc/testsuite/g++.dg/ubsan/return-7.C
+++ b/gcc/testsuite/g++.dg/ubsan/return-7.C
@@ -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 (); };
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 4fb4a83..2501a9c 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -9151,10 +9151,13 @@ pass_warn_function_return::execute (function *fun)
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);