]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-ssa-dce: Punt on allocations with too large constant sizes [PR118224]
authorJakub Jelinek <jakub@redhat.com>
Mon, 6 Jan 2025 09:12:00 +0000 (10:12 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 6 Jan 2025 09:12:00 +0000 (10:12 +0100)
commit804e9d55d9e54cffd32d8dd065bf3c785b1edbf4
tree54ece87362f2b4825ffc6df72c71076211e78e8b
parent90b6d3bc84da803e14627548545626215a127b4d
tree-ssa-dce: Punt on allocations with too large constant sizes [PR118224]

As suggested by Richi in the PR, the following patch will fail to DCE
allocation calls if they have constant size which is too large (over
PTRDIFF_MAX), or for the case of calloc, if either of the arguments
is too large (in that case in theory the call could succeed if the other
argument is variable zero but who cares) or if both are constant and
their product overflows or is above PTRDIFF_MAX.

This will make some pedantic conformance tests happy, though if one
hides the size one will still need to use -fno-malloc-dce or obfuscate even
the malloc etc. uses.  If the size is constant and too large, it isn't worth
trying to optimize it.

2025-01-06  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/118224
* tree-ssa-dce.cc (is_removable_allocation_p): Don't return true
for allocations with constant size argument larger than PTRDIFF_MAX
or for calloc with one of the arguments constant larger than
PTRDIFF_MAX or their product known constant above PTRDIFF_MAX.
Fix comment typos, furhter -> further and then -> than.
* lto-section-in.cc (lto_free_function_in_decl_state_for_node):
Fix comment typo, furhter -> further.

* gcc.dg/pr118224.c: New test.
* c-c++-common/ubsan/vla-1.c (bar): Use noipa attribute instead
of noinline, noclone.
gcc/lto-section-in.cc
gcc/testsuite/c-c++-common/ubsan/vla-1.c
gcc/testsuite/gcc.dg/pr118224.c [new file with mode: 0644]
gcc/tree-ssa-dce.cc