[Bug tree-optimization/105677] New: Calling strlen on a string constant is optimized out, but calling wcslen on a string constant is not

alexhenrie24 at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri May 20 18:13:39 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105677

            Bug ID: 105677
           Summary: Calling strlen on a string constant is optimized out,
                    but calling wcslen on a string constant is not
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alexhenrie24 at gmail dot com
  Target Milestone: ---

strlen example, source code:

    #include <string.h>

    int main()
    {
        return strlen("Hello world!");
    }

strlen example, assembly code at -O3:

    movl    $12, %eax
    ret

wcslen example, source code:

    #include <wchar.h>

    int main()
    {
        return wcslen(L"Hello world!");
    }

wcslen example, assembly code at -O3:

    subq    $8, %rsp
    .cfi_def_cfa_offset 16
    leaq    .LC0(%rip), %rdi
    call    wcslen@PLT
    addq    $8, %rsp
    .cfi_def_cfa_offset 8
    ret

Interestingly, Clang produces identical assembly code for both examples, which
is what I expected GCC to do.


More information about the Gcc-bugs mailing list