]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/120358 - bogus PTA with structure access
authorRichard Biener <rguenther@suse.de>
Mon, 7 Jul 2025 13:13:38 +0000 (15:13 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 14 Oct 2025 11:44:48 +0000 (13:44 +0200)
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.

PR tree-optimization/120358
* tree-ssa-structalias.cc (get_constraint_for_1): Adjust
pruning of sub-variables according to the imprecise
known start offset.

(cherry picked from commit aa5ae523e84a97bf3a582ea0fa73d959afa9b9c7)

gcc/tree-ssa-structalias.cc

index b6a5de1a8f6bc7998111f9ab3b234670c8c1e2fd..ab44a28235f45eb65a226e3fd129dbdab0606dc4 100644 (file)
@@ -3615,7 +3615,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);