<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Regression: Needless memcpy call"
   href="https://bugs.llvm.org/show_bug.cgi?id=38020">38020</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Regression: Needless memcpy call
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nicolasweber@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ 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</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>