https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101031
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <rgue...@gcc.gnu.org>: https://gcc.gnu.org/g:08ce1f4c5091b80b680d15c53a17237544a3cca8 commit r12-1419-g08ce1f4c5091b80b680d15c53a17237544a3cca8 Author: Richard Biener <rguent...@suse.de> Date: Mon Jun 14 09:37:24 2021 +0200 tree-optimization/101031 - fix strlen opt invalidation logic strlen opt uses ao_ref_init_from_ptr_and_size to prepare alias queries to invalidate its knowledge about strings. It constrains the size using the number of known-nonzero chars and adds one for a terminating nul - without knowing whether such nul exists or even fits the object. The latter is now a problem since the oracle disambiguates an access of size two (as built so) against a store to a plain char variable (where a terminating nul does not fit). The fix is to instead increment max_size but leave size to the number of chars we know are accessed. 2021-06-14 Richard Biener <rguent...@suse.de> PR tree-optimization/101031 * tree-ssa-strlen.c (maybe_invalidate): Increment max_size instead of size when accounting for a possibly string terminating nul. * gcc.dg/torture/pr101031.c: New testcase.