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

            Bug ID: 84275
           Summary: missing warning on conflicting attributes on different
                    declara
           Product: gcc
           Version: 8.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: ---

GCC silently accepts function declarations with attributes whose parameters
contradict or conflict with one another, both on distinct declarations of the
same function and even on the same declaration.

The test case below shows that if two declarations specify such conflicting
attributes GCC honors the first one (at least the object size pass does). 
Since the other attribute is ignored GCC should point that out (e.g., by
-Wattributes or by -Wignored-attributes).

Similar bugs were reported in pr32960 and pr81544.

$ cat t.C && gcc -D_FORTIFY_SOURCE=2 -O2 -S -Wall -xc t.C
#include <string.h>

#define ATTR(list)   __attribute__ (list)

void* ATTR ((alloc_align (1), alloc_size (2),    // this conflicts...
             alloc_align (2), alloc_size (1)))   // ...with this
foo (int, int);


void* ATTR ((alloc_size (1), alloc_align (2)))   // this conflicts...
bar (int, int);

void* ATTR ((alloc_size (2), alloc_align (1)))   // ...with this
bar (int, int);

void* foobar (void)
{
  void *p = bar (3, 5);
  memset (p, 0, 7);
  return p;
}
In file included from /usr/include/string.h:635,
                 from t.C:1:
In function ‘memset’,
    inlined from ‘foobar’ at t.C:19:3:
/usr/include/bits/string3.h:90:10: warning: ‘__builtin___memset_chk’ writing 7
bytes into a region of size 3 overflows the destination [-Wstringop-overflow=]
   return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to