Call expander ignores type alignment. But caller honors type alignment.
It usually isn't a problem until the argument is passed via stack. We
have a mismatch between caller and callee:

bash-3.2$ cat x.c
typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));

__m128  __attribute__((noinline))
iszero (__m128 x)
{
  return x;
}

typedef  __m128 __attribute__((aligned(1))) unaligned;

__m128  __attribute__((noinline))
foo (__m128 a1, __m128 a2, __m128 a3, __m128 a4,
     __m128 a5, __m128 a6, __m128 a7, __m128 a8,
     int b1, int b2, int b3, int b4, int b5, int b6, int b7, unaligned y)
{
  return iszero (y);
}

int
main (void)
{
  unaligned x;
  __m128 y, x0 = { 0 };
  x = x0; 
  y = foo (x0, x0, x0, x0, x0, x0, x0, x0, 1, 2, 3, 4, 5, 6, 7, x);
  return __builtin_memcmp (&y, &x0, sizeof (y));
}
bash-3.2$ make
/export/build/gnu/gcc/build-x86_64-linux/stage1-gcc/xgcc
-B/export/build/gnu/gcc/build-x86_64-linux/stage1-gcc/ -O -g    -c -o x.o x.c
/export/build/gnu/gcc/build-x86_64-linux/stage1-gcc/xgcc
-B/export/build/gnu/gcc/build-x86_64-linux/stage1-gcc/   x.o   -o x
./x
make: *** [all] Segmentation fault
bash-3.2$ gdb x
GNU gdb Red Hat Linux (6.6-45.fc8rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu"...
Using host libthread_db library "/lib64/libthread_db.so.1".
(gdb) r
Starting program: /export/home/hjl/bugs/gcc/35767/x 

Program received signal SIGSEGV, Segmentation fault.
foo (a1={0, 0, 0, 0}, a2={0, 0, 0, 0}, a3={0, 0, 0, 0}, a4={0, 0, 0, 0}, a5=
      {0, 0, 0, 0}, a6={0, 0, 0, 0}, a7={0, 0, 0, 0}, a8={0, 0, 0, 0}, b1=1, 
    b2=2, b3=3, b4=4, b5=5, b6=6, b7=7, y={5.87934249e-39, 0, 0, 0}) at x.c:16
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^
                                          Should be {0, 0, 0, 0}
16        return iszero (y);
Missing separate debuginfos, use: debuginfo-install glibc.x86_64
(gdb) f 1
#1  0x00000000004004c3 in main () at x.c:25
25        y = foo (x0, x0, x0, x0, x0, x0, x0, x0, 1, 2, 3, 4, 5, 6, 7, x);
(gdb) p x
No symbol "x" in current context.
(gdb) p x0
$1 = {0, 0, 0, 0}
(gdb) 

The segfault is PR 35767.


-- 
           Summary: Call expander ignores type alignment
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hjl dot tools at gmail dot com
GCC target triplet: x86_64-unknown-linux-gnu
 BugsThisDependsOn: 35767


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

Reply via email to