On 06/22/2018 04:00 PM, Jeff Law wrote:
On 06/18/2018 01:15 PM, Martin Sebor wrote:
While looking into opportunities to detect strnlen/strlen coding
mistakes (pr86199) I noticed a bug in the strnlen implementation
I committed earlier today that lets a strnlen() result be saved
and used in subsequent calls to strlen() with the same argument.
The attached patch changes the handle_builtin_strlen() function
to discard the strnlen() result unless its bound is greater than
the length of the string.

Martin

gcc-86204.diff


PR tree-optimization/86204 -  wrong strlen result after prior strnlen

gcc/ChangeLog:

        PR tree-optimization/86204
        * tree-ssa-strlen.c (handle_builtin_strlen): Avoid storing
        a strnlen result if it's less than the length of the string.

gcc/testsuite/ChangeLog:

        PR tree-optimization/86204
        * gcc.dg/strlenopt-46.c: New test.
OK.  Though I must admit I don't like having variables "bounded" and
"bound" in the same function.  So consider renaming one to avoid future
confusion.

Done in r262114.

Martin

Reply via email to