[llvm-bugs] [Bug 47145] New: Failure to optimize strcpy to memcpy when result of strlen is available

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 12 15:05:55 PDT 2020


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

            Bug ID: 47145
           Summary: Failure to optimize strcpy to memcpy when result of
                    strlen is available
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: gabravier at gmail.com
                CC: llvm-bugs at lists.llvm.org

char *f(char *p, char *r)
{
    char buf[10000];
    if (strlen(p) > 10000)
        return NULL;
    strcpy(buf, p);
    return strdup(buf);
}

The strcpy here could be optimized to `memcpy` using the result of `strlen(p)`
that has already been computed. This transformation is done by GCC, but not by
LLVM.

-- 
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/20200812/56a73539/attachment-0001.html>


More information about the llvm-bugs mailing list