<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 - Miscompilation of va_start on Windows MSYS2"
   href="https://bugs.llvm.org/show_bug.cgi?id=48624">48624</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Miscompilation of va_start on Windows MSYS2
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>release blocker
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>husseydevin@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Not sure if this is a Clang bug or a MSYS2 bug, so I am filing it here.


However, since the problem doesn't affect GCC which links to the same libc, I
am assuming it is something fishy with clang.

Compile this rather simple C program on MSYS2:


#include <stdarg.h>
#include <stdio.h>

void my_printf(const char *fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    vprintf(fmt, ap);
    va_end(ap);
}

int main(void)
{
    my_printf("%s\n", "Hello, world!");
}

***@**** MSYS2 ~
$ clang --version
clang version 11.0.0 (<a href="https://github.com/msys2/MSYS2-packages">https://github.com/msys2/MSYS2-packages</a>
a5a028a0811f03c8f9697bf80c2e28111628ffff)
Target: x86_64-pc-windows-msys
Thread model: posix
InstalledDir: /usr/bin

***@**** MSYS2 ~
$ clang test.c; ./a.exe
0@

***@**** MSYS2 ~
$./a.exe | hexdump -C
00000000  04 30 40 0a                                       |.0@.|
00000004

In case you are wondering, GCC correctly compiles this; my libc isn't broken.

***@**** MSYS2 ~
$ gcc --version
gcc (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

***@**** MSYS2 ~
$ gcc test.c; ./a.exe
Hello, world!

It doesn't matter if optimizations are on or off, it still prints 0x04 0x30
0x40.

mingw-w64 clang compiles it fine, though. 

Doing some more investigation now, although I am not familiar with the calling
convention.</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>