[PATCH] [x86_64] va_arg bug on when needSSE == 2

WenHan Gu (谷汶翰) wenhan.gu at gmail.com
Thu Sep 25 04:12:17 PDT 2014


Hi, cfe-commits,

When I run gcc testsuite pr44575.c on clang, then I found a stack overflow
issue.
The root cause is since it want to copy {double, double} (16-byte) back to
stack but clang only allocate float[3] (12-byte) in this case.
It happens after release 3.4, and I found this is modified at this commit:


    commit eeb00624413d4a4856e66809b84c558d2cdce17f
Author: Eli Friedman <eli.friedman at gmail.com>
Date:   Fri Jun 7 23:20:55 2013 +0000

    Fix va_arg on x86-64 for a struct containing a single int128_t.  PR16248

    git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183590
91177308-0d34-0410-b5e6-96231b3b80d8

Could somebody please have a look? Thanks!

If you want to reproduce, you can just use this simple code and found var i
will be changed after va_arg extraction.

     1  /* PR target/44575 */
     2  // clang -O0 reduced.c && ./a.out
     3  #include <stdarg.h>
     4
     5  struct S { float a[3]; } a;
     6
     7  void
     8  check (int z, ...)
     9  {
    10    va_list ap;
    11    int i = 0x5566;
    12    va_start (ap, z);
    13    va_arg (ap, struct S);
    14    if (i != 0x5566)
    15      abort();
    16  }
    17
    18  int
    19  main ()
    20  {
    21    a.a[2] = -49026;
    22    check (1, a);
    23    return 0;
    24  }


-- 
Best Regards,
WenHan Gu (Nowar)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140925/38cdaaa2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-3.5-x86_64-Bugfix-for-va_arg-when-neededSSE-2-to-pre.patch
Type: application/octet-stream
Size: 1831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140925/38cdaaa2/attachment.obj>


More information about the cfe-commits mailing list