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

            Bug ID: 88505
           Summary: missing -Wbuiltin-declaration-mismatch on a
                    declaration with incompatible attributes
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

-Wbuiltin-declaration-mismatch diagnoses declarations of built-in functions
whose type conflicts with the type of the built-in.  This includes the return
type and argument types, but does not include incompatible attributes.  For
example, the C11 aligned_alloc() function is declared like so:

  void *aligned_alloc (size_t alignment, size_t size);

but GCC silently accepts the declarations that specify attributes in the
opposite order, and in some cases (in g() below) even relies on the conflicting
attributes to make optimization decisions.

The -Wbuiltin-declaration-mismatch warning should be enhanced to also detect
mismatches in function attributes.

$ cat u.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout u.c
typedef __SIZE_TYPE__ size_t;

extern __attribute__ ((alloc_align (2), alloc_size (1))) void*
aligned_alloc (size_t, size_t);

size_t f (void)
{
  size_t align = 16;
  void *p = aligned_alloc (48, align);
  return __builtin_object_size (p, 0);   // bad alloc_size ignored here
}

void g (void)
{
  size_t align = 32;
  void *p = aligned_alloc (4, align); 
  if ((long)p & (align - 1))             // bad alloc_align used here
    __builtin_abort ();
}

;; Function f (f, funcdef_no=0, decl_uid=1910, cgraph_uid=1, symbol_order=0)

f ()
{
  <bb 2> [local count: 1073741824]:
  return 16;

}



;; Function g (g, funcdef_no=1, decl_uid=1915, cgraph_uid=2, symbol_order=1)

g ()
{
  <bb 2> [local count: 1073741824]:
  return;

}

Reply via email to