https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78667
Bug ID: 78667 Summary: nonsensical attribute alloc_size silently accepted 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: --- The documented purpose of the alloc_size attribute is to indicate to the compiler that a function return value points to region of memory whose size is given by one or two of the function's integer arguments. However, GCC accepts even nonsensical specifications of the attribute on function declarations that do not return pointers, or that do not take any arguments of integer types. The program below shows an instance of each of these problems. In the first declaration, the function returns void and so the attribute is meaningless. In the second declaration, the argument associated with the attribute is a pointer and not an integer. GCC should reject such non-sensical declarations the same way it rejects declarations where the argument number referenced by the attribute is out of bounds. $ cat a.c && gcc -O2 -S -Wall -Wextra -Wpedantic -fdump-tree-optimized=/dev/stdout a.c void f (int) __attribute__ ((alloc_size (1))); long g (int*) __attribute__ ((alloc_size (1))); int foo (void) { int i = 17; void *p = (void*)g (&i); return __builtin_object_size (p, 0); } ;; Function foo (foo, funcdef_no=0, decl_uid=1799, cgraph_uid=0, symbol_order=0) foo () { int i; <bb 2> [100.0%]: i = 17; g (&i); i ={v} {CLOBBER}; return -1; }