@@ -308,7 +308,9 @@ tree
ubsan_instrument_return (location_t loc)
{
if (flag_sanitize_undefined_trap_on_error)
- return build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0);
+ return build_call_expr_loc
+ /* pass_warn_function_return checks for BUILTINS_LOCATION. */
+ (BUILTINS_LOCATION, builtin_decl_explicit (BUILT_IN_TRAP), 0);
tree data = ubsan_create_data ("__ubsan_missing_return_data", 1, &loc,
NULL_TREE, NULL_TREE);
new file mode 100644
@@ -0,0 +1,9 @@
+// { dg-additional-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" }
+
+bool b;
+
+int f() {
+ if (b) return 42;
+} // { dg-warning "-Wreturn-type" }
+
+int main() { f(); }
@@ -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);