On Tue, Jun 14, 2022 at 09:01:54PM +0530, Siddhesh Poyarekar wrote: > The addr_expr computation does not check for error_mark_node before > returning the size expression. This used to work in the constant case > because the conversion to uhwi would end up causing it to return > size_unknown, but that won't work for the dynamic case.
Regarding subject/first line of commit, it should be something like: tree-object-size: Don't let error_mark_node escape for ADDR_EXPR [PR105736] instead of what you have. > Modify the control flow to explicitly return size_unknown if the offset > computation returns an error_mark_node. > > gcc/ChangeLog: > > PR tree-optimization/105736 > * tree-object-size.cc (addr_object_size): Return size_unknown > when object offset computation returns an error. > > gcc/testsuite/ChangeLog: > > PR tree-optimization/105736 > * gcc.dg/builtin-dynamic-object-size-0.c (TV4, val3, > test_pr105736): New struct declaration, variable and function to > test PR. If you want to spell the exact changes in the test, it would be better to do it separately when it is different changes. * gcc.dg/builtin-dynamic-object-size-0.c (struct TV4): New type. (val3): New variable. (test_pr105736): New function. > (main): Use them. Otherwise LGTM, but for GCC 13, it would be nice to add support for BIT_FIELD_REF if both second and third arguments are multiples of BITS_PER_UNIT. Something like: case BIT_FIELD_REF: if (!tree_fits_shwi_p (TREE_OPERAND (expr, 1)) || !tree_fits_shwi_p (TREE_OPERAND (expr, 2)) || (tree_to_shwi (TREE_OPERAND (expr, 1)) % BITS_PER_UNIT) || (tree_to_shwi (TREE_OPERAND (expr, 2)) % BITS_PER_UNIT)) return error_mark_node; base = compute_object_offset (TREE_OPERAND (expr, 0), var); if (base == error_mark_node) return base; off = size_int (tree_to_shwi (TREE_OPERAND (expr, 2) / BITS_PER_UNIT)); break; or so. > > Signed-off-by: Siddhesh Poyarekar <siddh...@gotplt.org> > --- > Changes from v1: > - Used FAIL() instead of __builtin_abort() in the test. > > Tested: > > - x86_64 bootstrap and test > - --with-build-config=bootstrap-ubsan build > > May I also backport this to gcc12? Ok. Jakub