From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 65368394C833; Tue, 2 May 2023 20:15:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65368394C833 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683058559; bh=CwUj0qrRBAL6WOa2uIDTC7nN95bOp2dTkulc+i9A/vE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lU/Yd7WB2nS0MVkVUxaSU9pj8yPe+ozjlozxTRWgHs8US7y6E7/u0x3S+zH48jWvP DMj/6EFTnS8O95jWg0g1kfgnuGeeMDl1NnNXQwMTSJiB7e1/zg3aqvqSXvFJKWPFgq 1voD7NgyhLDLBzd6B6K8lv9CTaH/YA8UV+um8+eQ= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/109151] UBsan misses a divide-by-zero Date: Tue, 02 May 2023 20:15:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109151 --- Comment #7 from CVS Commits --- The releases/gcc-11 branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:7d9f6140f0fdd59be002a2efb1d61939b29b450f commit r11-10726-g7d9f6140f0fdd59be002a2efb1d61939b29b450f Author: Jakub Jelinek 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 bec= ause 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 opera= nd 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 impossibl= e, 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_divi= sion 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 PR c/109151 * c-ubsan.c (ubsan_instrument_division): Handle all scalar inte= gral types rather than just INTEGER_TYPE. * c-c++-common/ubsan/div-by-zero-8.c: New test. (cherry picked from commit 103d423f6ce72ccb03d55b7b1dfa2dabd5854371)=