From: Jakub Jelinek Date: Sat, 2 Dec 2017 07:57:04 +0000 (+0100) Subject: re PR sanitizer/81212 (-Wreturn-type is disabled when used together with -fsanitize... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=38651b523d2df78a62489911e1c0036847c116bd;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9536a88b8a9..f1ce29112e0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2017-12-02 Jakub Jelinek + 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 49f0409a24a..eedf1a87960 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2017-12-02 Jakub Jelinek + 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 00000000000..ce92a07dceb --- /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 43791b9e33f..4e24db0c2a7 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 90c48b5b1d5..068210d884c 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 316cb4bc516..7f23c9f97d7 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 4fb4a834b20..2501a9cb8bb 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);