public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/44575]  New: __builtin_va_arg overwrites into adjacent stack location
@ 2010-06-18  0:00 eraman at google dot com
  2010-06-18  7:05 ` [Bug target/44575] " jakub at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: eraman at google dot com @ 2010-06-18  0:00 UTC (permalink / raw)
  To: gcc-bugs

$ cat vararg.c
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

int fails = 0;
struct S116 { float a[3]; } ;
struct S116 a116[5];

void check116va (int z, ...)
{ struct S116 arg, *p;
  va_list ap;
  int j=0,k=0;
  int i;
  __builtin_va_start(ap,z);
  for (i = 2; i < 4; ++i) {
    p = NULL;
    j++;
    k+=2;
    switch ((z << 4) | i) {
      case 0x12: case 0x13: p = &a116[2]; arg = __builtin_va_arg(ap,struct
S116); break;
      default: ++fails; break;
    }
    if (p && p->a[2] != arg.a[2]) {
      ++fails;
    }
    if (fails)
      break;
  }
  __builtin_va_end(ap);
}
int main()
{
  memset (a116, '\0', sizeof (a116));
  a116[2].a[2] = -49026.625000;
  check116va (1, a116[2], a116[2]);
  if (fails)
    abort();
}

$ ./trunk-gcc -O0  vararg.c && ./a.out
Aborted

./trunk-gcc is gcc 4.6.0  configured with --target=x86_64-unknown-linux-gnu
--disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit
--enable-c99 --enable-long-long --with-gnu-as --with-gnu-ld
--build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu
--enable-checking=release --enable-multilib --enable-targets=all
--with-arch-32=pentium3 --with-tune-32=pentium4 
--enable-shared=libgcc,libmudflap,libssp,libstdc++,libgfortran
--with-pic=libgfortran --enable-languages=c,c++,fortran 
--with-native-system-header-dir=/include  --enable-linker-build-id 
--with-host-libstdcxx=-lstdc++ FCFLAGS='-g -O2 ' 

The test cases passes with gcc 4.2.4 and 4.4.3.  

The gimple for __builtin_va_arg (from vararg.c.004t.gimple ) contains

  addr.1 = &va_arg_tmp.4;
  addr.5 = (long unsigned int * {ref-all}) addr.1;
  sse_addr.6 = (long unsigned int *) sse_addr.3;
  D.3520 = *sse_addr.6;
  *addr.5 = D.3520;          ---> (1)      
  addr.7 = (long unsigned int * {ref-all}) addr.1;
  D.3522 = addr.7 + 8;
  sse_addr.8 = (long unsigned int *) sse_addr.3;
  D.3524 = sse_addr.8 + 16;
  D.3525 = *D.3524;
  *D.3522 = D.3525;         ---> (2)

The assignments  (1) and (2) above are 8 byte moves, one at offset 0 and
another at offset 8, into va_arg_tmp.4. But the size of va_arg_tmp.4 is 12
bytes (sizeof (struct S116)) resulting in overwriting of adjacent stack
location ( variable i in this case) leading to the failure.


-- 
           Summary: __builtin_va_arg overwrites into adjacent stack location
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: eraman at google dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44575


^ permalink raw reply	[flat|nested] 11+ messages in thread
[parent not found: <bug-44575-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2010-10-01 13:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-18  0:00 [Bug target/44575] New: __builtin_va_arg overwrites into adjacent stack location eraman at google dot com
2010-06-18  7:05 ` [Bug target/44575] " jakub at gcc dot gnu dot org
2010-06-18 10:53 ` [Bug target/44575] [4.5/4.6 Regression] " rguenth at gcc dot gnu dot org
2010-06-18 15:59 ` matz at gcc dot gnu dot org
2010-06-21 12:50 ` jakub at gcc dot gnu dot org
2010-06-21 16:34 ` jakub at gcc dot gnu dot org
2010-06-24 21:43 ` [Bug target/44575] [4.5 " rguenth at gcc dot gnu dot org
2010-07-01 11:02 ` jakub at gcc dot gnu dot org
2010-07-01 11:06 ` jakub at gcc dot gnu dot org
     [not found] <bug-44575-4@http.gcc.gnu.org/bugzilla/>
2010-09-30  9:25 ` eraman at google dot com
2010-10-01 13:13 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).