re PR sanitizer/81212 (-Wreturn-type is disabled when used together with -fsanitize...
authorJakub Jelinek <jakub@redhat.com>
Sat, 2 Dec 2017 07:57:04 +0000 (08:57 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 2 Dec 2017 07:57:04 +0000 (08:57 +0100)
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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ubsan/pr81212.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ubsan/return-1.C
gcc/testsuite/g++.dg/ubsan/return-2.C
gcc/testsuite/g++.dg/ubsan/return-7.C
gcc/tree-cfg.c

index 9536a88b8a9e542be5b74eb586ef2afd984ea5dc..f1ce29112e05d63164d6ea61981db224963130e7 100644 (file)
@@ -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
index 49f0409a24aa9364f304f7dc669be337553d5c3b..eedf1a87960490717fc1ec933e07c01e1b24494d 100644 (file)
@@ -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 (file)
index 0000000..ce92a07
--- /dev/null
@@ -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" }
index 43791b9e33f7e6adf86b3c22371d09502af044ce..4e24db0c2a773fe77bd77cdf3cdaaf73bc3b365f 100644 (file)
@@ -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 (); };
index 90c48b5b1d564cb9b8122f36ac3632f48798279d..068210d884c5d5608d26bb88eae931a70f0ef63a 100644 (file)
@@ -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 (); };
 
index 316cb4bc5169b9a5c76d57adfaf6b95f61ec4930..7f23c9f97d706ea753abc360755c8fb107b2a327 100644 (file)
@@ -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 (); };
index 4fb4a834b207f2ca49411d34267b95a735177268..2501a9cb8bb8b67b312b9386b014604ac58a87b5 100644 (file)
@@ -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);