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 c/109151] UBsan misses a divide-by-zero
Date: Fri, 17 Mar 2023 15:11:22 +0000	[thread overview]
Message-ID: <bug-109151-4-T07fI3DW5P@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109151-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 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:103d423f6ce72ccb03d55b7b1dfa2dabd5854371

commit r13-6738-g103d423f6ce72ccb03d55b7b1dfa2dabd5854371
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Mar 17 16:10:14 2023 +0100

    c, ubsan: Instrument even shortened divisions [PR109151]

    On the following testcase, the C FE decides to shorten the division because
    it has a guarantee that INT_MIN / -1 division won't be encountered, the
    first operand is widened from narrower unsigned and/or the second operand
is
    a constant other than all ones (in this case both are true).
    The problem is that the narrower type in this case is _Bool and
    ubsan_instrument_division only instruments it if op0's type is INTEGER_TYPE
    or REAL_TYPE.  Strangely this doesn't happen in C++ FE.
    Anyway, we only shorten divisions if the INT_MIN / -1 case is impossible,
    so I think we should be fine even with -fstrict-enums in C++ in case it
    shortened to ENUMERAL_TYPEs.

    The following patch just instruments those on the ubsan_instrument_division
    side.  Perhaps only the first hunk and testcase might be needed because
    we shouldn't shorten if the other case could be triggered.

    2023-03-17  Jakub Jelinek  <jakub@redhat.com>

            PR c/109151
            * c-ubsan.cc (ubsan_instrument_division): Handle all scalar
integral
            types rather than just INTEGER_TYPE.

            * c-c++-common/ubsan/div-by-zero-8.c: New test.

  parent reply	other threads:[~2023-03-17 15:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 21:51 [Bug sanitizer/109151] New: " shaohua.li at inf dot ethz.ch
2023-03-15 21:54 ` [Bug c/109151] " pinskia at gcc dot gnu.org
2023-03-15 22:02 ` pinskia at gcc dot gnu.org
2023-03-16  9:17 ` jakub at gcc dot gnu.org
2023-03-17 15:11 ` cvs-commit at gcc dot gnu.org [this message]
2023-03-19  5:31 ` cvs-commit at gcc dot gnu.org
2023-03-20 10:29 ` jakub at gcc dot gnu.org
2023-05-02 20:15 ` cvs-commit at gcc dot gnu.org
2023-05-03 10:44 ` jakub at gcc dot gnu.org
2023-05-03 15:22 ` cvs-commit at gcc dot gnu.org
2023-05-04  7:25 ` jakub 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-109151-4-T07fI3DW5P@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).