From f8d136e50e6f82cba793483d910a2b2643108508 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 7 Dec 2022 14:42:24 +0100 Subject: tree-optimization/106904 - bogus -Wstringopt-overflow with vectors The following avoids CSE of &ps->wp to &ps->wp.hwnd confusing -Wstringopt-overflow by making sure to produce addresses to the biggest container from vectorization. For this I introduce strip_zero_offset_components which turns &ps->wp.hwnd into &(*ps) and use that to base the vector data references on. That will also work for addresses with variable components, alternatively emitting pointer arithmetic via calling get_inner_reference and gimplifying that would be possible but likely more intrusive. This is by no means a complete fix for all of those issues (avoiding ADDR_EXPRs in favor of pointer arithmetic might be). Other passes will have similar issues. In theory that might now cause false negatives. PR tree-optimization/106904 * tree.h (strip_zero_offset_components): Declare. * tree.cc (strip_zero_offset_components): Define. * tree-vect-data-refs.cc (vect_create_addr_base_for_vector_ref): Strip zero offset components before building the address. * gcc.dg/Wstringop-overflow-pr106904.c: New testcase. --- gcc/tree.h | 1 + 1 file changed, 1 insertion(+) (limited to 'gcc/tree.h') diff --git a/gcc/tree.h b/gcc/tree.h index 23223ca..73d3dd7 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -5369,6 +5369,7 @@ extern bool tree_nop_conversion_p (const_tree, const_tree); extern tree tree_strip_nop_conversions (tree); extern tree tree_strip_sign_nop_conversions (tree); extern const_tree strip_invariant_refs (const_tree); +extern tree strip_zero_offset_components (tree); extern tree lhd_gcc_personality (void); extern void assign_assembler_name_if_needed (tree); extern bool warn_deprecated_use (tree, tree); -- cgit v1.1