On Wed, Oct 20, 2021 at 03:22:10PM +0200, Richard Biener via Gcc-patches wrote: > This maps -ftrapv to -fsanitize=signed-integer-overflow > -fsanitize-undefined-trap-on-error, effectively removing > flag_trapv (or rather making it always false). > > This has implications on language support - while -ftrapv > was formerly universally available the mapping restricts it > to the C family of frontends. > > It also raises questions on mixing -ftrapv with -fsanitize > flags, specifically with other recovery options for the > undefined sanitizer since -fsanitize-undefined-trap-on-error > cannot be restricted to the signed-integer-overflow part at > the moment. To more closely map behavior we could add > -fsanitize=trapv where with a single option we could also > simply alias -ftrapv to that.
I think we shouldn't do it this way. There is no reason not to support it in all FEs, not just C family, the instrumentation is done during in this case in the ubsan pass anyway. And it also should cope well with different sanitizers, while -ftrapv vs. -fsanitize=signed-integer-overflow probably needs to be either/or, so one of those should take precedence over the other, e.g. -fsanitize=shift -fsanitize-recover=shift -ftrapv should result in recovering from shift UBs, not trap on them. My preference would be new set of ifns for -ftrapv, similar to .UBSAN_CHECK_{ADD,SUB,MUL}, say .TRAPV_CHECK_{ADD,SUB,MUL,DIV}, that uses moreless the same internal-fn.c expansion as .UBSAN_CHECK_*, but doesn't call ubsan_build_overflow_builtin and rely on flag_sanitize_undefined_trap_on_error, instead either emits the trap call directly, or also uses libcalls if optab isn't available and libcall is (or for -Os cases if libcall is smaller). Because some of the -fsanitize=signed-integer-overflow emitted code for multiplication at least on some architectures is very large... Jakub