[llvm-bugs] [Bug 49596] New: Optimize strlen(foo) > x to strnlen(foo, x+1) > x

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 15 07:18:07 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=49596

            Bug ID: 49596
           Summary: Optimize strlen(foo) > x to strnlen(foo, x+1) > x
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Transformation Utilities
          Assignee: unassignedbugs at nondot.org
          Reporter: gbs at canishe.com
                CC: llvm-bugs at lists.llvm.org

A lot of code has comparisons of the form:

  strlen(foo) > x

This is inefficient, because always we read every byte of the string, even
after we already know it's longer than x. This could be optimized to:

  strnlen(foo, x + 1) > x

But Clang doesn't do this. (Neither does GCC.) I'd like to take a shot at
implementing this, but I wanted to make sure I'm not missing some obvious
reason it wouldn't work.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210315/0e4c481b/attachment.html>


More information about the llvm-bugs mailing list