When we compute the constraint for something like MEM[(const struct QStringView &)&tok2 + 32] we go and compute what (const struct QStringView &)&tok2 + 32 points to and then add subvariables to its dereference that possibly fall in the range of the access according to the original refs size. In doing that we disregarded that the subvariable the starting address points to might not be aligned to it and thus the access might start at any point within that variable. The following conservatively adjusts the pruning of adjacent sub-variables to honor this.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. PR tree-optimization/120358 * tree-ssa-structalias.cc (get_constraint_for_1): Adjust pruning of sub-variables according to the imprecise known start offset. --- gcc/tree-ssa-structalias.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc index deca44ae0bf..0215243d5be 100644 --- a/gcc/tree-ssa-structalias.cc +++ b/gcc/tree-ssa-structalias.cc @@ -3690,7 +3690,10 @@ get_constraint_for_1 (tree t, vec<ce_s> *results, bool address_p, size = -1; for (; curr; curr = vi_next (curr)) { - if (curr->offset - vi->offset < size) + /* The start of the access might happen anywhere + within vi, so conservatively assume it was + at its end. */ + if (curr->offset - (vi->offset + vi->size - 1) < size) { cs.var = curr->id; results->safe_push (cs); -- 2.43.0