tree-optimization/104009: Conservative underflow estimate in object size
commit17df585a3a6a852c71883cc2ff40e111a6875149
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Fri, 14 Jan 2022 03:26:15 +0000 (14 08:56 +0530)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Fri, 14 Jan 2022 06:21:44 +0000 (14 11:51 +0530)
tree99894075fe2ee96d9f4bc047c4f994bdfd859a86
parentb77e3b4e4589e56c01511fabdbaadb029cd47f5c
tree-optimization/104009: Conservative underflow estimate in object size

Restrict negative offset computation only to dynamic object sizes, where
size expressions are accurate and not a maximum/minimum estimate and in
cases where negative offsets definitely mean an underflow, e.g. in
MEM_REF of the whole object with negative ofset in addr_object_size.

This ends up missing some cases where __builtin_object_size could have
come up with more precise results, so tests have been adjusted to
reflect that.

gcc/ChangeLog:

PR tree-optimization/104009
* tree-object-size.c (compute_builtin_object_size): Bail out on
negative offset.
(plus_stmt_object_size): Return maximum of wholesize and minimum
of 0 for negative offset.

gcc/testsuite/ChangeLog:

PR tree-optimization/104009
* gcc.dg/builtin-object-size-1.c (test10): New test.
* gcc.dg/builtin-object-size-3.c (test10): Likewise.
(test9): Expect zero size for negative offsets.
* gcc.dg/builtin-object-size-4.c (test8): Likewise.
* gcc.dg/builtin-object-size-5.c (test7): Drop test for
__builtin_object_size.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
gcc/testsuite/gcc.dg/builtin-object-size-1.c
gcc/testsuite/gcc.dg/builtin-object-size-3.c
gcc/testsuite/gcc.dg/builtin-object-size-4.c
gcc/testsuite/gcc.dg/builtin-object-size-5.c
gcc/tree-object-size.c