<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - LLVM disregards windows’ x64 vararg ABI"
   href="https://llvm.org/bugs/show_bug.cgi?id=26159">26159</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM disregards windows’ x64 vararg ABI
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>other
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>simonas+llvm.org@kazlauskas.me
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>LLVM will reliably mis-translate code calling vararg-using functions which
targets Windows x64.

x64 ABI requires no special handling to varargs as compared to non-vararg
functions and wants some varargs to be placed into registers, not always stack.
LLVM, though, always places all of the varargs onto stack.

Here’s a few C programs that, as compiled with clang 3.7.1 on Windows x64,
produce unexpected results:

#include<stdio.h>
extern int wsprintfA(char *out, const char* in, ...);
int main() {
  char out[100];
  wsprintfA(out, "%d %f %c", 42, 42.25, 'a');
  printf("%s", out); // prints “42 f”
  return 0;
}

---

extern int wsprintfA(char *out, const char* in, ...);
int main() {
  char out[100];
  wsprintfA(out, "%d %f %c %s", 42, 42.25, 'a', "hello world"); //segfaults
  return 0;
}

(you can think of wsprintfA as of alias to sprintf, because it [essentially is
one](<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms647550(v=vs.85).aspx">https://msdn.microsoft.com/en-us/library/windows/desktop/ms647550(v=vs.85).aspx</a>))

I have verified that LLVM generated code correctly places the non-vararg
arguments into the correct registers, however it fails to do so for the
vararg-arguments.

---

I also have a minimal LLVM-IR file which reproduces the issue, but is not as
trivial to build.</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>