When running gfortran on a 64-bit AMD Athlon64 Linux machine, the
Fortran ALLOCATE statement does not align pointers on 16-byte boundaries.
This means that allocated memory cannot be passed to assembly language
routines that rely on 16-byte alignment (e.g. assembly language using
SSE instructions like "movaps").

The demonstration below involves two files, the first one
a Fortran program name try.f which allocates an array x.
It calls a C function, shown in file sub.c, which returns the
address of x, and prints a message saying whether or not the
array is 16-byte aligned.

% gfortran -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/configure --prefix=/var/tmp/gfortran-20050916/irun
 --enable-languages=c,f95
Thread model: posix
gcc version 4.1.0 20050916 (experimental)

% cat try.f
      real, allocatable :: x(:)
      integer*8 address, p, sixteen
      external address
      sixteen = 16
      allocate (x(300000))
      p = address(x)
      write (*,99) 'Address of x = ', p
  99  format (1x,a,'0x',z16.16)
      if (mod(p,sixteen) .eq. 0) then
         write (*,*) 'x is aligned on a 16-byte boundary'
      else
         write (*,*) 'x is not aligned on a 16-byte boundary'
      end if
      end

% cat sub.c
unsigned long address_(void *x)
{
  return (unsigned long)x;
}

% gfortran try.f sub.c

% ./a.out
 Address of x = 0x00002AAAAB1CB028
 x is not aligned on a 16-byte boundary


-- 
           Summary: gfortran ALLOCATE statement does not align objects on
                    16-byte boundary
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mick at nag dot co dot uk


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

Reply via email to