From: Jakub Jelinek Date: Tue, 5 Dec 2017 09:17:32 +0000 (+0100) Subject: cp-gimplify.c (cp_maybe_instrument_return): Don't add __builtin_unreachable if -O0... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=81e4859a97804dfe76eb090f8b4d6a68361ce658;p=gcc.git cp-gimplify.c (cp_maybe_instrument_return): Don't add __builtin_unreachable if -O0 or if -fsanitize=unreachable. * cp-gimplify.c (cp_maybe_instrument_return): Don't add __builtin_unreachable if -O0 or if -fsanitize=unreachable. * g++.dg/missing-return.C: Add -O to dg-options. From-SVN: r255403 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8760a701677..5f7a574e7a5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-12-05 Jakub Jelinek + + * cp-gimplify.c (cp_maybe_instrument_return): Don't add + __builtin_unreachable if -O0 or if -fsanitize=unreachable. + 2017-12-04 Jason Merrill PR c++/83273 - constexpr if allows non-constant condition diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 68a253a02db..934f6742a53 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1554,6 +1554,18 @@ cp_maybe_instrument_return (tree fndecl) || !targetm.warn_func_return (fndecl)) return; + if (!sanitize_flags_p (SANITIZE_RETURN, fndecl) + /* Don't add __builtin_unreachable () if not optimizing, it will not + improve any optimizations in that case, just break UB code. + Don't add it if -fsanitize=unreachable -fno-sanitize=return either, + UBSan covers this with ubsan_instrument_return above where sufficient + information is provided, while the __builtin_unreachable () below + if return sanitization is disabled will just result in hard to + understand runtime error without location. */ + && (!optimize + || sanitize_flags_p (SANITIZE_UNREACHABLE, fndecl))) + return; + tree t = DECL_SAVED_TREE (fndecl); while (t) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 16eee3d024d..aeacec422cc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-12-05 Jakub Jelinek + + * g++.dg/missing-return.C: Add -O to dg-options. + 2017-12-04 Jeff Law PR tree-optimization/78496 diff --git a/gcc/testsuite/g++.dg/missing-return.C b/gcc/testsuite/g++.dg/missing-return.C index f7fcfebb2b4..5f8e2ccb100 100644 --- a/gcc/testsuite/g++.dg/missing-return.C +++ b/gcc/testsuite/g++.dg/missing-return.C @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Wreturn-type -fdump-tree-optimized" } */ +/* { dg-options "-Wreturn-type -fdump-tree-optimized -O" } */ int foo(int a) {