Adjust objsz Arg in __strcat_chk -> __stpcpy_chk Transformation
The compiler now correctly transforms calls to `__strcat_chk` into calls to `__stpcpy_chk` when optimizing `strlen`, avoiding potential buffer overflows.
This commit addresses an issue in the transformation of __strcat_chk calls during strlen optimization. When the compiler optimizes code that calls strlen after __strcat_chk, it transforms the __strcat_chk call into a call to __stpcpy_chk. The change ensures that the objsz argument (object size) passed to __stpcpy_chk is correctly adjusted, preventing potential buffer overflows.
In Details
tree-ssa-strlen.cc contains the strlen_pass which optimises calls to strlen and related string functions. This commit fixes how get_string_length transforms __strcat_chk(x, y, z) calls into __stpcpy_chk(x + t, y, z - t) - x when computing strlen(x) afterwards. The objsz parameter to the __stpcpy_chk needs to be adjusted to reflect the available buffer size.
For Context
strlen is a standard C library function that calculates the length of a string. Compilers often optimize calls to strlen to improve performance. This commit fixes a specific optimization related to strlen and __strcat_chk, a function that concatenates strings with buffer overflow checking. The fix makes sure that when __strcat_chk is replaced with __stpcpy_chk during optimization, the buffer size is correctly calculated to prevent potential overflows.