]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-optimization/120780: Support object size for containing objects
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Thu, 26 Jun 2025 21:46:00 +0000 (17:46 -0400)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Thu, 3 Jul 2025 11:19:02 +0000 (07:19 -0400)
commit72e85d46472716e670cbe6e967109473b8d12d38
treec00964a0057fd0135b9a3715589ab8180fb2578d
parent349da53f13de274864d01b6ccc466961c472dbe1
tree-optimization/120780: Support object size for containing objects

MEM_REF cast of a subobject to its containing object has negative
offsets, which objsz sees as an invalid access.  Support this use case
by peeking into the structure to validate that the containing object
indeed contains a type of the subobject at that offset and if present,
adjust the wholesize for the object to allow the negative offset.

gcc/ChangeLog:

PR tree-optimization/120780
* tree-object-size.cc (inner_at_offset,
get_wholesize_for_memref): New functions.
(addr_object_size): Call get_wholesize_for_memref.

gcc/testsuite/ChangeLog:

PR tree-optimization/120780
* gcc.dg/builtin-dynamic-object-size-pr120780.c: New test case.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
gcc/testsuite/gcc.dg/builtin-dynamic-object-size-pr120780.c [new file with mode: 0644]
gcc/tree-object-size.cc