tree-optimization/108522 Use component_ref_field_offset
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Thu, 26 Jan 2023 12:07:03 +0000 (07:07 -0500)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Thu, 26 Jan 2023 12:20:53 +0000 (07:20 -0500)
commit0573a0778af88e805f7630ac8640ecd67d692665
treeb723e9358ec03b916d7619f3d67a267f41901125
parent59a42fe6a99db39f2fed21c2a69faf6fa78ccfd4
tree-optimization/108522 Use component_ref_field_offset

Instead of using TREE_OPERAND (expr, 2) directly, use
component_ref_field_offset instead, which does scaling for us.  The
function also substitutes PLACEHOLDER_EXPRs but it is not relevant for
tree-object-size.

gcc/ChangeLog:

PR tree-optimization/108522
* tree-object-size.cc (compute_object_offset): Make EXPR
argument non-const.  Call component_ref_field_offset.

gcc/testsuite/ChangeLog:

PR tree-optimization/108522
* gcc.dg/builtin-dynamic-object-size-0.c (DEFSTRUCT): New
macro.
(test_dynarray_struct_member_b, test_dynarray_struct_member_c,
test_dynarray_struct_member_d,
test_dynarray_struct_member_subobj_b,
test_dynarray_struct_member_subobj_c,
test_dynarray_struct_member_subobj_d): New tests.
(main): Call them.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
gcc/tree-object-size.cc