Go to file
Jakub Jelinek 9c1a633d96 ubsan: Move INT_MIN / -1 instrumentation from -fsanitize=integer-divide-by-zero to -fsanitize=signed-integer-overflow [PR102515]
As noted by Richi, in clang INT_MIN / -1 is instrumented under
-fsanitize=signed-integer-overflow rather than
-fsanitize=integer-divide-by-zero as we did and doing it in the former
makes more sense, as it is overflow during division rather than division
by zero.
I've verified on godbolt that clang behaved that way since 3.2-ish times or
so when sanitizers were added.
Furthermore, we've been using
-f{,no-}sanitize-recover=integer-divide-by-zero to decide on the float
-fsanitize=float-divide-by-zero instrumentation _abort suffix.
The case where INT_MIN / -1 is instrumented by one sanitizer and
x / 0 by another one when both are enabled is slightly harder if
the -f{,no-}sanitize-recover={integer-divide-by-zero,signed-integer-overflow}
flags differ, then we need to emit both __ubsan_handle_divrem_overflow
and __ubsan_handle_divrem_overflow_abort calls guarded by their respective
checks rather than one guarded by check1 || check2.

2021-10-01  Jakub Jelinek  <jakub@redhat.com>
	    Richard Biener  <rguenther@suse.de>

	PR sanitizer/102515
gcc/
	* doc/invoke.texi (-fsanitize=integer-divide-by-zero): Remove
	INT_MIN / -1 division detection from here ...
	(-fsanitize=signed-integer-overflow): ... and add it here.
gcc/c-family/
	* c-ubsan.c (ubsan_instrument_division): Check the right
	flag_sanitize_recover bit, depending on which sanitization
	is done.  Sanitize INT_MIN / -1 under SANITIZE_SI_OVERFLOW
	rather than SANITIZE_DIVIDE.  If both SANITIZE_SI_OVERFLOW
	and SANITIZE_DIVIDE is enabled, neither check is known
	to be false and flag_sanitize_recover bits for those two
	aren't the same, emit both __ubsan_handle_divrem_overflow
	and __ubsan_handle_divrem_overflow_abort calls.
gcc/c/
	* c-typeck.c (build_binary_op): Call ubsan_instrument_division
	for division even for SANITIZE_SI_OVERFLOW.
gcc/cp/
	* typeck.c (cp_build_binary_op): Call ubsan_instrument_division
	for division even for SANITIZE_SI_OVERFLOW.
gcc/testsuite/
	* c-c++-common/ubsan/div-by-zero-3.c: Use
	-fsanitize=signed-integer-overflow instead of
	-fsanitize=integer-divide-by-zero.
	* c-c++-common/ubsan/div-by-zero-5.c: Likewise.
	* c-c++-common/ubsan/div-by-zero-4.c: Likewise.  Add
	-fsanitize-undefined-trap-on-error.
	* c-c++-common/ubsan/float-div-by-zero-2.c: New test.
	* c-c++-common/ubsan/overflow-div-1.c: New test.
	* c-c++-common/ubsan/overflow-div-2.c: New test.
	* c-c++-common/ubsan/overflow-div-3.c: New test.
2021-10-01 14:27:32 +02:00
c++tools Daily bump. 2021-09-15 00:16:29 +00:00
config Daily bump. 2021-09-20 00:16:21 +00:00
contrib Daily bump. 2021-09-21 00:16:31 +00:00
fixincludes
gcc ubsan: Move INT_MIN / -1 instrumentation from -fsanitize=integer-divide-by-zero to -fsanitize=signed-integer-overflow [PR102515] 2021-10-01 14:27:32 +02:00
gnattools
gotools Daily bump. 2021-09-22 00:16:28 +00:00
include Daily bump. 2021-09-28 00:16:21 +00:00
INSTALL
intl
libada
libatomic
libbacktrace
libcc1
libcody
libcpp
libdecnumber
libffi
libgcc Daily bump. 2021-09-29 00:16:26 +00:00
libgfortran Daily bump. 2021-09-28 00:16:21 +00:00
libgo runtime: set runtime.GOROOT value at build time 2021-09-21 14:31:10 -07:00
libgomp openmp: Differentiate between order(concurrent) and order(reproducible:concurrent) 2021-10-01 10:45:48 +02:00
libiberty Daily bump. 2021-09-24 00:16:23 +00:00
libitm
libobjc
liboffloadmic
libphobos Daily bump. 2021-10-01 00:16:27 +00:00
libquadmath
libsanitizer
libssp
libstdc++-v3 Daily bump. 2021-10-01 00:16:27 +00:00
libvtv
lto-plugin
maintainer-scripts
zlib
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2021-09-30 00:16:20 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath Remove freebsd1 from libtool.m4 macros and config.rpath. 2011-02-13 11:45:53 +00:00
config.sub
configure top-level configure: setup target_configdirs based on repository 2021-09-28 09:43:36 +01:00
configure.ac top-level configure: setup target_configdirs based on repository 2021-09-28 09:43:36 +01:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Add myself to DCO section 2021-09-29 21:02:30 +01:00
Makefile.def top-level: merge Makefile.def patches from binutils-gdb repository 2021-09-24 18:16:55 +01:00
Makefile.in top-level: merge Makefile.def patches from binutils-gdb repository 2021-09-24 18:16:55 +01:00
Makefile.tpl
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.