https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109585
--- Comment #21 from Richard Biener <rguenth at gcc dot gnu.org> ---
aliasing_component_refs_p seems to try handle trailing arrays via
component_ref_to_zero_sized_trailing_array_p. It properly detects
f_5->fam[0].n
but fails on
MEM[(struct P *)f_3(D) + 8B].n
but it would also in all cases happily continue with the base ref type
when comparing sizes:
/* Now search for the type1 in the access path of ref2. This
would be a common base for doing offset based disambiguation on.
This however only makes sense if type2 is big enough to hold type1. */
int cmp_outer = compare_type_sizes (type2, type1);
I also wonder if
/* If we didn't find a common base, try the other way around. */
if (cmp_outer <= 0
|| (end_struct_ref1
&& compare_type_sizes (TREE_TYPE (end_struct_ref1), type1) <= 0))
here type1 shouldn't be type2?
In any case we end up failing the access_path_may_continue_p checks and
disambiguate.
diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index 81bc51ed4ad..8a1ec9091fa 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -1330,7 +1330,7 @@ aliasing_component_refs_p (tree ref1,
/* If we didn't find a common base, try the other way around. */
if (cmp_outer <= 0
|| (end_struct_ref1
- && compare_type_sizes (TREE_TYPE (end_struct_ref1), type1) <= 0))
+ && compare_type_sizes (TREE_TYPE (end_struct_ref1), type2) <= 0))
{
int res = aliasing_component_refs_walk (ref2, type2, base2,
offset2, max_size2,
seems to fix the testcase - can anybody confirm?
Honza, is that indeed a typo or do I just hide the issue?