diff options
author | Jason Merrill <jason@redhat.com> | 2022-06-10 15:26:36 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-06-13 17:54:37 -0400 |
commit | 2c11662391bafd74c9d19bf7626b7bcef41c1323 (patch) | |
tree | 0b5b728822afbb9790590368d1decd1c12edef6f /gcc/c-family | |
parent | 72b185189f914a412ae39776cd284dfaeaf2213b (diff) | |
download | gcc-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/c-family')
-rw-r--r-- | gcc/c-family/c-ubsan.cc | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/gcc/c-family/c-ubsan.cc b/gcc/c-family/c-ubsan.cc index 48f9487..a2cd8fb 100644 --- a/gcc/c-family/c-ubsan.cc +++ b/gcc/c-family/c-ubsan.cc @@ -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); |