cp-gimplify.c (cp_maybe_instrument_return): Don't add __builtin_unreachable if -O0...
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 Dec 2017 09:17:32 +0000 (10:17 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 5 Dec 2017 09:17:32 +0000 (10:17 +0100)
* 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

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/missing-return.C

index 8760a701677790e199de57d74834d026a6012abf..5f7a574e7a59d5e585e745c3abee7756c675022a 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-05  Jakub Jelinek  <jakub@redhat.com>
+
+       * cp-gimplify.c (cp_maybe_instrument_return): Don't add
+       __builtin_unreachable if -O0 or if -fsanitize=unreachable.
+
 2017-12-04  Jason Merrill  <jason@redhat.com>
 
        PR c++/83273 - constexpr if allows non-constant condition
index 68a253a02db73f06ea98fac43c6c6d3aa2f43b08..934f6742a53b408d85d79fc0b5716d72bb74494a 100644 (file)
@@ -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)
     {
index 16eee3d024da9975e256917d5768b7d065fb3cd3..aeacec422cc5041d938298701663ad17ba41d37b 100644 (file)
@@ -1,3 +1,7 @@
+2017-12-05  Jakub Jelinek  <jakub@redhat.com>
+
+       * g++.dg/missing-return.C: Add -O to dg-options.
+
 2017-12-04  Jeff Law  <law@redhat.com>
 
        PR tree-optimization/78496
index f7fcfebb2b460f4e5ce2ed2e79e698ac05f461aa..5f8e2ccb100259394611bc8f10d1435e118d66ea 100644 (file)
@@ -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)
 {