aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2022-12-07 14:42:24 +0100
committerRichard Biener <rguenther@suse.de>2022-12-11 14:34:44 +0100
commitf8d136e50e6f82cba793483d910a2b2643108508 (patch)
tree3339f7ecb0d9cd8b0b2bb00b2f8990e99dcc0a89 /gcc/tree.cc
parent045592f665bcb67b75dc6b86badbe2fd44aed3e6 (diff)
downloadgcc-f8d136e50e6f82cba793483d910a2b2643108508.zip
gcc-f8d136e50e6f82cba793483d910a2b2643108508.tar.gz
gcc-f8d136e50e6f82cba793483d910a2b2643108508.tar.bz2
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.
Diffstat (limited to 'gcc/tree.cc')
-rw-r--r--gcc/tree.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/tree.cc b/gcc/tree.cc
index b40c95a..0a51f9d 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -12014,6 +12014,18 @@ strip_invariant_refs (const_tree op)
return op;
}
+/* Strip handled components with zero offset from OP. */
+
+tree
+strip_zero_offset_components (tree op)
+{
+ while (TREE_CODE (op) == COMPONENT_REF
+ && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
+ && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
+ op = TREE_OPERAND (op, 0);
+ return op;
+}
+
static GTY(()) tree gcc_eh_personality_decl;
/* Return the GCC personality function decl. */