https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101210
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-10 branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:208ad9a001f192c763e2c9682a4c296b4696a10c commit r10-10628-g208ad9a001f192c763e2c9682a4c296b4696a10c Author: Jakub Jelinek <ja...@redhat.com> Date: Tue Jun 29 11:24:38 2021 +0200 match.pd: Avoid (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST opt in GENERIC when sanitizing [PR101210] When we have (intptr_t) x == cst where x has REFERENCE_TYPE, this optimization creates x == cst out of it where cst has REFERENCE_TYPE. If it is done in GENERIC folding, it can results in ubsan failures where the INTEGER_CST with REFERENCE_TYPE is instrumented. Fixed by deferring it to GIMPLE folding in this case. 2021-06-29 Jakub Jelinek <ja...@redhat.com> PR c++/101210 * match.pd ((intptr_t)x eq/ne CST to x eq/ne (typeof x) CST): Don't perform the optimization in GENERIC when sanitizing and x has a reference type. * g++.dg/ubsan/pr101210.C: New test. (cherry picked from commit 53fd7544aff6d0a18869017cb9bb921a7f5dcd04)