[PATCH] PR60092 - lower posix_memalign to make align-info accessible

Jakub Jelinek jakub@redhat.com
Wed Feb 12 09:46:00 GMT 2014


On Wed, Feb 12, 2014 at 10:30:01AM +0100, Richard Biener wrote:
> Bah.  I am testing the following.

But then there is no guarantee that ptr is aligned after the call.
char buf[32] __attribute__((aligned (32)));
int
foo (void)
{
  void *ptr = buf + 1;
  posix_memalign (&ptr, 32, -1);
  /* Assume posix_memalign has failed.  */
  return ((__UINTPTR_TYPE__)ptr) & 31;
}

This should return 1, but supposedly doesn't with the optimization.
So, either we need to revert the lowering, or perhaps do it only if
the original posix_memalign has a lhs and do it like:
  void *tmp;
  int res = posix_memalign (&tmp, align, size);
  if (!res)
    ptr = __builtin_assume_aligned (tmp, align);
or so (no need to initialize tmp and copy it back for the failure case,
but perhaps it would result in better code).

	Jakub



More information about the Gcc-patches mailing list