On 06/07/2018 09:57 AM, Martin Sebor wrote: > The attached patch enhances the strlen pass to more consistently > deal with MEM_REF assignments (PR 86042) and to track string > lengths across calls to memcpy that overwrite parts of a string > with sequences of non-nul characters (PR 86043). > > Fixes for both bugs rely on changes to the same code so I chose > to include them in the same patch. > > To fix PR 86042 the patch extends handle_char_store() to deal with > more forms of multi-character assignments from MEM_REF (originally > introduced in r256180). To handle assignments from strings of > multiple nuls the patch also extends the initializer_zerop() > function to understand MEM_REFs of the form: > > MEM[(char * {ref-all})&a] = MEM[(char * {ref-all})"..."]; > > The solution for PR 86043 consists of two parts: the extension > above which lets handle_char_store() recognize assignments of > sequences of non-null characters that overwrite some portion of > the leading non-zero characters in the destination and avoid > discarding the destination information, and a similar extension > to handle_builtin_memcpy(). > > Martin > > gcc-86042.diff > > > PR tree-optimization/86042 - missing strlen optimization after second strcpy > > gcc/ChangeLog: > > PR tree-optimization/86042 > * tree-ssa-strlen.c (handle_builtin_memcpy): Handle strict overlaps. > (get_string_cst_length): Rename... > (get_min_string_length): ...to this. Add argument. > (handle_char_store): Extend to handle multi-character stores by > MEM_REF. > * tree.c (initializer_zerop): Use new argument. Handle MEM_REF. > * tree.h (initializer_zerop): Add argument. > > gcc/testsuite/ChangeLog: > > PR tree-optimization/86042 > * gcc.dg/strlenopt-44.c: New test. OK.
Thanks, jeff