https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78668

            Bug ID: 78668
           Summary: aligned_alloc, realloc, et al. missing attribute
                    alloc_size
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

All built-in memory allocations functions are missing the aligned_alloc
attribute.  As the output of the test case below shows, the absence of the
attribute on aligned_alloc and realloc causes __builtin_object_size to fail to
determine the size of objects they allocate.

$ cat a.c && gcc -O2 -S -Wall -Wextra -Wpedantic
-fdump-tree-optimized=/dev/stdout a.c | grep -e ^test -eabort
void sink (void*);

unsigned size (unsigned n)
{
  return n;
}

void test_aligned_alloc (unsigned a)
{
  unsigned n = size (7);

  void *p = __builtin_aligned_alloc (n, a);
  if (__builtin_object_size (p, 0) != n)
    __builtin_abort ();
  sink (p);
}

void test_alloca (void)
{
  unsigned n = size (13);

 void *p = __builtin_alloca (n);
  if (__builtin_object_size (p, 0) != n)
    __builtin_abort ();
  sink (p);
}

void test_calloc (void)
{
  unsigned m = size (19);
  unsigned n = size (23);

  void *p = __builtin_calloc (m, n);
  if (__builtin_object_size (p, 0) != m * n)
    __builtin_abort ();
  sink (p);
}

void test_malloc (void)
{
  unsigned n = size (17);

  void *p = __builtin_malloc (n);
  if (__builtin_object_size (p, 0) != n)
    __builtin_abort ();
  sink (p);
}

void test_realloc (void *p)
{
  unsigned n = size (31);

  p = __builtin_realloc (p, n);
  if (__builtin_object_size (p, 0) != n)
    __builtin_abort ();
  sink (p);
}
test_aligned_alloc (unsigned int a)
  __builtin_abort ();
test_alloca ()
test_calloc ()
test_malloc ()
test_realloc (void * p)
  __builtin_abort ();

Reply via email to