<html>
    <head>
      <base href="http://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 --- - va_copy for AArch64 doesn't work"
   href="http://llvm.org/bugs/show_bug.cgi?id=18789">18789</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>va_copy for AArch64 doesn't work
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>Backend: AArch64
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=12036" name="attach_12036" title="The .ll file to reproduce the run-time failure">attachment 12036</a> <a href="attachment.cgi?id=12036&action=edit" title="The .ll file to reproduce the run-time failure">[details]</a></span>
The .ll file to reproduce the run-time failure

The attached test case t.c is from LNT

$ cat t.c
#include <stdio.h>
#include <stdarg.h>

void testVaCopyArg(char *fmt, ...) {
  va_list ap, aq;
  char *s;
  va_start(ap, fmt);
  va_copy(aq, ap);    /* test va_copy */

  s = va_arg(aq, char *);
  printf("string %s\n", s);
}

int main() {
  testVaCopyArg("s", "abc");
  return 0;
}

It fails at run-time with -O1 and above for aarch64 target, and it can pass
with -O0.

t.ll is generated with the following command line,

clang -O3 --target=aarch64-linux-gnuabi -mfpu=neon t.c -S -emit-llvm

With t.ll, we can confirm the bug is from backend, because the binary built
from "llc -O1" fail, while the binary built from "llc -O0" can pass.

1) -O0 case
// build with the following command line
llc -mtriple=aarch64-none-linux-gnueabi -O0 t.ll
clang --target=aarch64-linux-gnuabi t.s
// running a.out on foundation model shows correct result.

2) -O1 case
// build with the following command line
llc -mtriple=aarch64-none-linux-gnueabi -O1 t.ll
clang --target=aarch64-linux-gnuabi t.s
// running a.out on foundation model shows incorrect result or segmentation
fault.</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>