]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-optimization/117355: object size for PHI nodes with negative offsets
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Wed, 20 Nov 2024 03:51:31 +0000 (22:51 -0500)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Fri, 22 Nov 2024 20:25:09 +0000 (15:25 -0500)
commit684595188dea02d246edb66106d82bb7a9a22d79
tree749811b6d6a9f75bda62f6ceac20cc95bb012d64
parent5f95136e5efba13d9caf7e4fa3a57e1aaa136aa4
tree-optimization/117355: object size for PHI nodes with negative offsets

When the object size estimate is returned for a PHI node, it is the
maximum possible value, which is fine in isolation.  When combined with
negative offsets however, it may sometimes end up in zero size because
the resultant size was larger than the wholesize, leading
size_for_offset to conclude that there's a potential underflow.  Fix
this by allowing a non-strict mode to size_for_offset, which
conservatively returns the size (or wholesize) in case of a negative
offset.

gcc/ChangeLog:

PR tree-optimization/117355
* tree-object-size.cc (size_for_offset): New argument STRICT,
return SZ if it is set to false.
(plus_stmt_object_size): Adjust call to SIZE_FOR_OFFSET.

gcc/testsuite/ChangeLog:

PR tree-optimization/117355
* g++.dg/ext/builtin-object-size2.C (test9): New test.
(main): Call it.
* gcc.dg/builtin-object-size-3.c (test10): Adjust expected size.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
gcc/testsuite/g++.dg/ext/builtin-object-size2.C
gcc/testsuite/gcc.dg/builtin-object-size-3.c
gcc/tree-object-size.cc