]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-optimization/117912 - bogus address equivalences for __builtin_object_size
authorRichard Biener <rguenther@suse.de>
Thu, 5 Dec 2024 09:47:13 +0000 (10:47 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 10 Dec 2024 07:58:08 +0000 (08:58 +0100)
commit233972ab3b5338d7a5d1d7af9108c1f366170e44
tree45f9986109d47b7d1d1589427f06eb35c516bd96
parent0374e6771477553b3cc0c13f000f9e79aabd5020
tree-optimization/117912 - bogus address equivalences for __builtin_object_size

VN again is the culprit for exploiting address equivalences before
__builtin_object_size got the chance to do its job.  This time
it isn't about union members but adjacent structure fields where
an address to one after the last element of an array field can
spill over to the next field.

The following protects all out-of-bound accesses on the upper bound
side (singling out TYPE_MAX_VALUE + 1 is more expensive).  It
ignores other out-of-bound addresses that would invoke UB.

Zero-sized arrays are a bit awkward because the C++ represents them
with a -1U upper bound.

There's a similar issue for zero-sized components whose address can
be the same as the adjacent field in C.

PR tree-optimization/117912
* tree-ssa-sccvn.cc (copy_reference_ops_from_ref): For addresses
of zero-sized components do not set ->off if the object size pass
didn't run.
For OOB ARRAY_REF accesses in address expressions avoid setting
->off if the object size pass didn't run.
(valueize_refs_1): Likewise.

* c-c++-common/torture/pr117912-1.c: New testcase.
* c-c++-common/torture/pr117912-2.c: Likewise.
* c-c++-common/torture/pr117912-3.c: Likewise.
gcc/testsuite/c-c++-common/torture/pr117912-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/torture/pr117912-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/torture/pr117912-3.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.cc