[llvm-bugs] [Bug 46489] New: Failure to optimize sprintf of single string to strcpy instead of using strlen+strcpy

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Aug 9 12:42:38 PDT 2020


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

            Bug ID: 46489
           Summary: Failure to optimize sprintf of single string to strcpy
                    instead of using strlen+strcpy
           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

void f(char *p, const char *s)
{
    sprintf(p, "%s", s);
}

This can be optimized to `strcpy(p, s)`. This transformation is done by GCC.
but not by LLVM, which instead transforms it to `memcpy(p, s, strlen(s) + 1)`

--- Comment #1 from Gabriel Ravier <gabravier at gmail.com> ---
*** Bug 46490 has been marked as a duplicate of this bug. ***

-- 
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/20200809/9478cea0/attachment.html>


More information about the llvm-bugs mailing list