public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/102515] UBSAN misses signed division instrumentation
Date: Fri, 01 Oct 2021 12:36:30 +0000	[thread overview]
Message-ID: <bug-102515-4-71PRlRzDIA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102515-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102515

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:9c1a633d96926357155d4702b66f8a0ec856a81f

commit r12-4042-g9c1a633d96926357155d4702b66f8a0ec856a81f
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Oct 1 14:27:32 2021 +0200

    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.

  parent reply	other threads:[~2021-10-01 12:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28 12:30 [Bug sanitizer/102515] New: " rguenth at gcc dot gnu.org
2021-09-28 12:48 ` [Bug sanitizer/102515] " jakub at gcc dot gnu.org
2021-09-28 13:01 ` rguenth at gcc dot gnu.org
2021-09-28 13:03 ` rguenth at gcc dot gnu.org
2021-10-01 10:00 ` rguenth at gcc dot gnu.org
2021-10-01 10:10 ` jakub at gcc dot gnu.org
2021-10-01 10:21 ` rguenth at gcc dot gnu.org
2021-10-01 10:21 ` rguenth at gcc dot gnu.org
2021-10-01 12:36 ` cvs-commit at gcc dot gnu.org [this message]
2021-10-04 16:04 ` rguenth at gcc dot gnu.org
2021-10-05 20:31 ` cvs-commit at gcc dot gnu.org
2022-05-10  8:21 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:22 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102515-4-71PRlRzDIA@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).