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/105729] False positive UBsan "reference binding to null pointer of type" when evaluating array indexing which throws exception Date: Mon, 20 Jun 2022 06:38:07 +0000 [thread overview] Message-ID: <bug-105729-4-YF9uQVeRab@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-105729-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105729 --- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-10 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:76562138659d6a3e6f11e467dd1ffd6d19f3df75 commit r10-10855-g76562138659d6a3e6f11e467dd1ffd6d19f3df75 Author: Jakub Jelinek <jakub@redhat.com> Date: Fri May 27 11:40:42 2022 +0200 fold-const: Fix up -fsanitize=null in C++ [PR105729] The following testcase triggers a false positive UBSan binding a reference to null diagnostics. In the FE we instrument conversions from pointer to reference type to diagnose at runtime if the operand of such a conversion is 0. The problem is that a GENERIC folding folds ((const struct Bar *) ((const struct Foo *) this)->data) + (sizetype) range_check (x) conversion to const struct Bar & by converting to that the first operand of the POINTER_PLUS_EXPR. But that changes when the -fsanitize=null binding to reference runtime check occurs. Without the optimization, it is invoked on the result of the POINTER_PLUS_EXPR, and as range_check call throws, that means it never triggers in the testcase. With the optimization, it checks whether this->data is NULL and it is. The following patch avoids that optimization during GENERIC folding when -fsanitize=null is enabled and it is a cast from non-REFERENCE_TYPE to REFERENCE_TYPE. 2022-05-27 Jakub Jelinek <jakub@redhat.com> PR sanitizer/105729 * fold-const.c (fold_unary_loc): Don't optimize (X &) ((Y *) z + w) to (X &) z + w if -fsanitize=null during GENERIC folding. * g++.dg/ubsan/pr105729.C: New test. (cherry picked from commit e2f014fcefcd2ad56b31995329820bbd99072eae)
next prev parent reply other threads:[~2022-06-20 6:38 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-25 16:30 [Bug other/105729] New: " egor_suvorov at mail dot ru 2022-05-26 9:18 ` [Bug other/105729] " marxin at gcc dot gnu.org 2022-05-26 15:18 ` jakub at gcc dot gnu.org 2022-05-26 15:18 ` [Bug sanitizer/105729] " jakub at gcc dot gnu.org 2022-05-26 18:00 ` jakub at gcc dot gnu.org 2022-05-27 9:41 ` cvs-commit at gcc dot gnu.org 2022-05-30 3:36 ` cvs-commit at gcc dot gnu.org 2022-06-20 6:37 ` cvs-commit at gcc dot gnu.org 2022-06-20 6:38 ` cvs-commit at gcc dot gnu.org [this message] 2022-06-20 9:55 ` 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-105729-4-YF9uQVeRab@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: linkBe 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).