This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/88397] New: attribute malloc ignored on function pointers when alloc_size is accepted


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;
      | ^~~~

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]