[llvm-bugs] [Bug 38020] New: Regression: Needless memcpy call

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 2 09:43:39 PDT 2018


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

            Bug ID: 38020
           Summary: Regression: Needless memcpy call
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nicolasweber at gmx.de
                CC: llvm-bugs at lists.llvm.org

$ cat repro.ii
typedef unsigned long DWORD;
typedef void *HANDLE;
__declspec(dllimport) HANDLE GetStdHandle(DWORD);
void mainCRTStartup(void) {
  const char msg[] = "012345678901234567890123456789";
  HANDLE out = GetStdHandle(((DWORD)-11));
  WriteFile(out, msg, sizeof(msg), (DWORD[]){0}, ((void *)0));
}
$ ~/src/chrome/src/third_party/llvm-build/Release+Asserts/bin/clang "-cc1"
"-triple" "i386-pc-windows-msvc19.11.0" "-S" "-O2" -fms-extensions "-o" - "-x"
"c" "repro.ii"
repro.ii:7:3: warning: implicit declaration of function 'WriteFile' is invalid
in C99
  WriteFile(out, msg, sizeof(msg), (DWORD[]){0}, ((void *)0));
  ^
        .text
        .def     @feat.00;
        .scl    3;
        .type   0;
        .endef
        .globl  @feat.00
.set @feat.00, 1
        .def     _mainCRTStartup;
        .scl    2;
        .type   32;
        .endef
        .globl  _mainCRTStartup
        .p2align        4, 0x90
_mainCRTStartup:
        pushl   %esi
        subl    $36, %esp
        leal    5(%esp), %esi
        pushl   $31
        pushl   $L_mainCRTStartup.msg
        pushl   %esi
        calll   _memcpy
        addl    $12, %esp
        pushl   $-11
        calll   *__imp__GetStdHandle
        addl    $4, %esp
        movl    $0, (%esp)
        movl    %esp, %ecx
        pushl   $0
        pushl   %ecx
        pushl   $31
        pushl   %esi
        pushl   %eax
        calll   _WriteFile
        addl    $56, %esp
        popl    %esi
        retl

        .section        .rdata,"dr"
L_mainCRTStartup.msg:
        .asciz  "012345678901234567890123456789"


1 warning generated.



Used to not happen on 6.0, where this was generated instead:

        pushl   %eax
        pushl   $-11
        calll   *__imp__GetStdHandle
Ltmp0:
        addl    $4, %esp
        .loc    1 7 45                  #
/tmp/compiler-explorer-compiler11862-54-b0lq0e.pt5wl/example.c:7:45
        movl    $0, (%esp)
        movl    %esp, %ecx
        .loc    1 7 3 is_stmt 0         #
/tmp/compiler-explorer-compiler11862-54-b0lq0e.pt5wl/example.c:7:3
        pushl   $0
        pushl   %ecx
        pushl   $31
        pushl   $_mainCRTStartup.msg
        pushl   %eax
        calll   _WriteFile
Ltmp1:
        addl    $20, %esp
        .loc    1 8 1 is_stmt 1         #
/tmp/compiler-explorer-compiler11862-54-b0lq0e.pt5wl/example.c:8:1
        popl    %eax
        retl

-- 
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/20180702/8af19328/attachment-0001.html>


More information about the llvm-bugs mailing list