aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-cfg.cc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-06-10 15:26:36 -0400
committerJason Merrill <jason@redhat.com>2022-06-13 17:54:37 -0400
commit2c11662391bafd74c9d19bf7626b7bcef41c1323 (patch)
tree0b5b728822afbb9790590368d1decd1c12edef6f /gcc/tree-cfg.cc
parent72b185189f914a412ae39776cd284dfaeaf2213b (diff)
downloadgcc-2c11662391bafd74c9d19bf7626b7bcef41c1323.zip
gcc-2c11662391bafd74c9d19bf7626b7bcef41c1323.tar.gz
gcc-2c11662391bafd74c9d19bf7626b7bcef41c1323.tar.bz2
ubsan: -Wreturn-type and ubsan trap-on-error
I noticed that -fsanitize=undefined -fsanitize-undefined-trap-on-error was omitting the usual -Wreturn-type warning for control flowing off the end of a function. This was because the warning code was looking for calls either to __builtin_unreachable or the UBSan function, but these flags produce a call to __builtin_trap instead. gcc/c-family/ChangeLog: * c-ubsan.cc (ubsan_instrument_return): Use BUILTINS_LOCATION. gcc/ChangeLog: * tree-cfg.cc (pass_warn_function_return::execute): Also check BUILT_IN_TRAP. gcc/testsuite/ChangeLog: * g++.dg/ubsan/return-8.C: New test.
Diffstat (limited to 'gcc/tree-cfg.cc')
-rw-r--r--gcc/tree-cfg.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 9e5d84a..c67c278 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -9543,7 +9543,7 @@ pass_warn_function_return::execute (function *fun)
}
/* The C++ FE turns fallthrough from the end of non-void function
into __builtin_unreachable () call with BUILTINS_LOCATION.
- Recognize those too. */
+ Recognize those as well as calls from ubsan_instrument_return. */
basic_block bb;
if (!warning_suppressed_p (fun->decl, OPT_Wreturn_type))
FOR_EACH_BB_FN (bb, fun)
@@ -9555,7 +9555,8 @@ pass_warn_function_return::execute (function *fun)
if (last
&& ((LOCATION_LOCUS (gimple_location (last))
== BUILTINS_LOCATION
- && gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE))
+ && (gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE)
+ || gimple_call_builtin_p (last, BUILT_IN_TRAP)))
|| gimple_call_builtin_p (last, ubsan_missing_ret)))
{
gimple_stmt_iterator gsi = gsi_for_stmt (last);