[llvm-dev] [PATCH] strlen -> strnlen optimization

Joerg Sonnenberger via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 7 12:22:51 PST 2016


On Sat, Feb 06, 2016 at 11:05:14PM -0500, Michael McConville via llvm-dev wrote:
> This addition converts strlen() calls to strnlen() when the result is
> compared to a constant. For example, the following:
> 
> strlen(s) < 5
> 
> Becomes:
> 
> strnlen(s, 5) < 5

BTW, a less problematic lowering of this would be to transform
"strlen(s) < c" into "memchr(s, '\0', c-1) != 0". That's valid on all
ISO C targets.

Joerg


More information about the llvm-commits mailing list