[ Forwarded from http://bugs.debian.org/458745 ]

Camm Maguire <[EMAIL PROTECTED]>
arm-only miscompilation of alloca code

i386:
cc -g /tmp/foo.c -o /tmp/foo
/tmp/foo
0xbf867bd0
0x1
0x2
0x3

arm:
cc -g foo.c -o foo
./foo
0x18beed5d
Segmentation fault

Testcase:

#include <stdio.h>
#include <alloca.h>
#include <stdarg.h>
#define object void *

int VFUN_NARGS;
void *alloca_val;
struct cons {
  object c_cdr;
  object c_car;
};

#define Cnil 0

static void
foo(object first,...) {
  va_list ap;
  int narg = VFUN_NARGS;
  struct cons *V1128;
  object V1129;

  va_start(ap,first);
  V1129 =
    !narg? Cnil : (alloca_val=alloca((narg)*sizeof(struct
cons)+sizeof(object)),
                   ({object _b=(void *)alloca_val;if (((unsigned
long)_b)&sizeof(_b)) _b++;
                   {struct cons *_p=(void *)_b;
                   {struct cons *_e=_p+(narg-1);
                   for (;_p<_e;_p++) {_p->c_car=({object
_t=first;first=va_arg(ap,object);_t;});_p->c_cdr=(object)(_p+1);}}
_p->c_car=first;_p->c_cdr=Cnil;}_b;}));
  va_end(ap);
  V1128= V1129;
  for (;V1128!=Cnil;V1128=V1128->c_cdr)
    printf("%p\n",V1128->c_car);

}

int
main(int argc,char * argv[]) {

  VFUN_NARGS=4;
  foo(&argc,1,2,3);
  return 0;

}


-- 
           Summary: arm-only miscompilation of alloca code
           Product: gcc
           Version: 4.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tbm at cyrius dot com
GCC target triplet: arm*-linux-gnu


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

Reply via email to