]> git.ipfire.org Git - people/ms/gcc.git/commit
match.pd: Avoid (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST opt in GENERIC when...
authorJakub Jelinek <jakub@redhat.com>
Tue, 29 Jun 2021 09:24:38 +0000 (11:24 +0200)
committerJakub Jelinek <jakub@redhat.com>
Sun, 18 Jul 2021 10:54:55 +0000 (12:54 +0200)
commit86a9718e162b08cd4263402bcbf0d17a557bfcf1
tree6a5032af90c740d1104457bef22cbfc18264e1c2
parent72ff4a04bb33795fe5b6d5863a66cac5293559b6
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  <jakub@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)
gcc/match.pd
gcc/testsuite/g++.dg/ubsan/pr101210.C [new file with mode: 0644]