ubsan: -Wreturn-type and ubsan trap-on-error
commit2c11662391bafd74c9d19bf7626b7bcef41c1323
authorJason Merrill <jason@redhat.com>
Fri, 10 Jun 2022 19:26:36 +0000 (10 15:26 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 13 Jun 2022 21:54:37 +0000 (13 17:54 -0400)
tree0b5b728822afbb9790590368d1decd1c12edef6f
parent72b185189f914a412ae39776cd284dfaeaf2213b
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.
gcc/c-family/c-ubsan.cc
gcc/testsuite/g++.dg/ubsan/return-8.C [new file with mode: 0644]
gcc/tree-cfg.cc