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

            Bug ID: 88363
           Summary: [9 Regression] alloc_align attribute doesn't accept
                    enumerated arguments
           Product: gcc
           Version: 9.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: ---

According to the manual:

  The alloc_align attribute may be applied to a function that returns a pointer
and takes at least one argument of an integer type.

C defines integer types like so:

  The type char, the signed and unsigned integer types, and the enumerated
types are collectively called integer types.

However, when a function argument of an enumerated type is referenced in the
alloc_align attribute GCC 9 prints a warning and ignores the attribute:

$ cat t.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout t.c
__attribute__ ((alloc_align (1))) void* fi (int);

enum A { A1 = 1, A2 = 2, A4 = 4 };
__attribute__ ((alloc_align (1))) void* fA (enum A);

void gi (void)
{
  void *p = fi (A4);
  if ((__UINTPTR_TYPE__)p & 3)
    __builtin_abort ();
}

void gA (void)
{
  void *p = fA (A4);
  if ((__UINTPTR_TYPE__)p & 3)
    __builtin_abort ();
}

t.c:4:50: warning: ‘alloc_align’ attribute argument value ‘1’ refers to
parameter type ‘enum A’ [-Wattributes]
    4 | __attribute__ ((alloc_align (1))) void* fA (enum A);
      |                                                  ^

;; Function gi (gi, funcdef_no=0, decl_uid=1914, cgraph_uid=1, symbol_order=0)

gi ()
{
  <bb 2> [local count: 1073741824]:
  fi (4); [tail call]
  return;

}



;; Function gA (gA, funcdef_no=1, decl_uid=1918, cgraph_uid=2, symbol_order=1)

gA ()
{
  void * p;
  long unsigned int p.1_1;
  long unsigned int _2;

  <bb 2> [local count: 1073741824]:
  p_5 = fA (4);
  p.1_1 = (long unsigned int) p_5;
  _2 = p.1_1 & 3;
  if (_2 != 0)
    goto <bb 3>; [0.00%]
  else
    goto <bb 4>; [100.00%]

  <bb 3> [count: 0]:
  __builtin_abort ();

  <bb 4> [local count: 1073741824]:
  return;

}

Reply via email to