tree-optimization/108522 Use COMPONENT_REF offset when available
commitb851ee9fdf0f3023635f0cb1f7c607b2d6801053
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Wed, 25 Jan 2023 00:47:05 +0000 (24 19:47 -0500)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Wed, 25 Jan 2023 00:47:05 +0000 (24 19:47 -0500)
tree8e81c1f792baf54fb1043f359ef2ed679b41e58e
parent0fa221685a36ef98cb20a6d435a150b5992e99e0
tree-optimization/108522 Use COMPONENT_REF offset when available

Use the offset in TREE_OPERAND(component_ref, 2) when available instead
of DECL_FIELD_OFFSET when trying to compute offset for a COMPONENT_REF.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
gcc/ChangeLog:

PR tree-optimization/108522
* tree-object-size.cc (compute_object_offset): Use
TREE_OPERAND(ref, 2) for COMPONENT_REF when available.

gcc/testsuite/ChangeLog:

PR tree-optimization/108522
* gcc.dg/builtin-dynamic-object-size-0.c
(test_dynarray_struct_member): New test.
(main): Call it.

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