This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/88397] New: attribute malloc ignored on function pointers when alloc_size is accepted
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 07 Dec 2018 03:16:08 +0000
- Subject: [Bug middle-end/88397] New: attribute malloc ignored on function pointers when alloc_size is accepted
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88397
Bug ID: 88397
Summary: attribute malloc ignored on function pointers when
alloc_size is accepted
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: ---
I noticed this while testing a fix for bug 88372.
GCC accepts attributes alloc_align and alloc_size on declarations of function
pointers but ignores (with a warning) attribute malloc. Besides being
inconsistent, it makes it impossible to get GCC to emit optimally efficient
code for calls via function pointers to malloc-like functions (such as malloc
or aligned_alloc). The same limitation applies to defining function types with
attribute malloc.
$ cat u.c && gcc -O2 -S -Wall -Wextra u.c
typedef __SIZE_TYPE__ size_t;
__attribute__ ((alloc_align (1), alloc_size (2)))
void* (*p)(size_t, size_t) = __builtin_aligned_alloc;
__attribute__ ((alloc_align (1), alloc_size (2), malloc))
void* (*q)(size_t, size_t) = __builtin_aligned_alloc;
u.c:7:1: warning: ‘malloc’ attribute ignored [-Wattributes]
7 | void* (*q)(size_t, size_t) = __builtin_aligned_alloc;
| ^~~~